Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added more (unverified) code #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
86 changes: 62 additions & 24 deletions 100.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
#include<cstdio>
int main(){
int i,j;
while(scanf("%d%d",&i,&j)!=EOF){
int x=0,y=0,k=0,max=0;
x=(i>j)?i:j;
y=(i<j)?i:j;
for(k=y;k<=x;k++){
int n=k;
int nc=0;
while(n!=1){
nc++;
if(n%2!=0)
n=3*n+1;
else
n=n/2;
}
if(nc>max)
max=nc;
}
printf("%d %d %d\n",i,j,max+1);
}
return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define SIZE 1000001

static unsigned short tbl[SIZE];

inline unsigned short cycle_len(register unsigned long n)
{
if (n < SIZE && tbl[n])
{
return tbl[n];
}
if (n & 1)
{
// odd n
if (n < SIZE)
{
// calc two steps at once
tbl[n] = 2 + cycle_len((3 * n + 1) >> 1);
return tbl[n];
}
else
{
return 2 + cycle_len((3 * n + 1) >> 1);
}
}
else
{
if (n < SIZE)
{
tbl[n] = 1 + cycle_len(n >> 1);// n/2
return tbl[n];
}
else
{
return 1 + cycle_len(n >> 1);
}
}
}

int main()
{
unsigned long fn = 0, sn = 0, i;
short out = 0, temp;
tbl[1] = 1;
while (scanf("%lu%lu", &fn, &sn) == 2)
{
unsigned long a = min(fn, sn), b = max(fn, sn);
for (int i = a; i <= b; i++)
{
out = max(out, cycle_len(i));
}
printf("%lu %lu %d\n", fn, sn, out);
out = 0;
}
return 0;
}
75 changes: 75 additions & 0 deletions 1000.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <bits/stdc++.h>

using namespace std;

typedef struct
{
int NO, ac[30], dc[30], w;
} Cas;

Cas cas[21];
int len;
int N, K, Ar;
int arr[30][30];

int cmp(const void *a, const void *b)
{
Cas *pa = (Cas *)a, *pb = (Cas *)b;
if (pa->w == pb->w)
{
return pa->NO - pb->NO;
}
else
{
return pa->w - pb->w;
}
}

int main()
{
int i, j, k, D, flow;
while (scanf("%d", &N), N != 0)
{
memset(arr, 0, sizeof(arr));
memset(cas, 0, sizeof(cas));
len = 0;
for (i = 0; i < N; i++)
{
scanf("%d%d", &Ar, &K);
for (j = 0; j < K; j++)
{
scanf("%d%d", &D, &flow);
arr[Ar][D] = flow;
}
}
while (scanf("%d", &K), K != 0)
{
cas[len].NO = K;
cas[len].w = 0;
for (i = 0; i < N; i++)
{
scanf("%d", &cas[len].ac[i]);
}
for (i = 0; i < N; i++)
{
scanf("%d", &cas[len].dc[i]);
}
cas[len].w = 0;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
cas[len].w += arr[cas[len].ac[i]][cas[len].dc[j]] * (1 + abs(i - j));
}
}
len++;
}
qsort(cas, len, sizeof(cas[0]), cmp);
printf("Configuration Load\n");
for (i = 0; i < len; i++)
{
printf("%5d %d\n", cas[i].NO, cas[i].w);
}
}
return 0;
}
79 changes: 79 additions & 0 deletions 10000.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define FOREQ(i, a, b) for (int(i) = int(a); (i) <= int(b); (i)++)
#define SZ(a) ((int)(a).size())

typedef struct _node
{
int n, length;
vector<int> adj;
} node;

static vector<node> G;
static pair<int, int> result;
static int n, start, a, b, counter = 0;

void dfs(int start, int length)
{
if (G[start - 1].length > length)
{
return;
}
else if (G[start - 1].length < length)
{
G[start - 1].length = length;
}
if (G[start - 1].adj.empty())
{
if (length > result.first)
{
result.first = length;
result.second = start;
}
else if (length == result.first)
{
if (start < result.second)
{
result.second = start;
}
}
}
else
{
int end = SZ(G[start - 1].adj);
FOR(i, 0, end)
{
dfs(G[start - 1].adj[i], length + 1);
}
}
}

int main()
{
while (scanf("%d", &n) == 1 && n)
{
G.clear();
counter++;
FOREQ(i, 1, n)
{
node N;
N.n = i;
N.length = 0;
G.push_back(N);
}
scanf("%d", &start);
while (scanf("%d%d", &a, &b) && a && b)
{
G[a - 1].adj.push_back(b);
}
result.first = 0;
result.second = 0;
dfs(start, 0);
printf("Case %d: The longest path from %d has length %d, finishing at %d.\n\n",
counter, start, result.first, result.second);
}
return 0;
}
105 changes: 105 additions & 0 deletions 10001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <bits/stdc++.h>

using namespace std;

int automaton[2][2][2], state[40], map_[160][160], reachable[160], n, maxn;

void init_automaton(int identifier)
{
memset(automaton, 0, sizeof(automaton));
for (int i = 0; i <= 1; ++i)
{
for (int j = 0; j <= 1; ++j)
{
for (int k = 0; k <= 1; ++k)
{
automaton[i][j][k] = identifier & 1;
identifier >>= 1;
}
}
}
}

void init_state(char str_state[])
{
memset(state, 0, sizeof(state));
for (int i = 0; i < strlen(str_state); ++i)
{
state[i] = str_state[i] - '0';
}
}

void add_edge(int id1, int cur1, int next1, int id2, int cur2, int next2)
{
int node1 = id1 * 4 + cur1 * 2 + next1;
int node2 = id2 * 4 + cur2 * 2 + next2;
map_[node1][node2] = 1;
}

void init_map_(void)
{
memset(map_, 0, sizeof(map_));
maxn = n * 4;
for (int id = 0; id < n; ++id)
{
for (int cur = 0; cur <= 1; ++cur)
{
for (int next = 0; next <= 1; ++next)
{
for (int next2 = 0; next2 <= 1; ++next2)
{
int next_id = (id + 1) % n;
if (state[next_id] == automaton[cur][next][next2])
{
add_edge(id, cur, next, next_id, next, next2);
}
}
}
}
}
}

int calc_state()
{
for (int first = 0; first < 4; ++first)
{
memset(reachable, 0, sizeof(reachable));
reachable[first] = 1;
for (int id = 0; id < n - 1; ++id)
{
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
if (reachable[id * 4 + i] && map_[id * 4 + i][(id + 1) * 4 + j])
{
reachable[(id + 1) * 4 + j] = 1;
if (id == n - 2)
{
if (map_[(id + 1) * 4 + j][first])
{
return 1;
}
}
}
}
}
}
}
return 0;
}

int main()
{
int identifier, is_reachable;
char str_state[1000];
while (scanf("%d%d%s", &identifier, &n, str_state) != EOF)
{
init_automaton(identifier);
init_state(str_state);
init_map_();
is_reachable = calc_state();
printf(is_reachable ? "REACHABLE\n" : "GARDEN OF EDEN\n");
}
return 0;
}
Loading