| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求大神测试。自己试了几次 都对。但是就是WA。TAT#if defined(WIN32) || defined(WIN64)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
int mini(int p[],int head){
return p[head];
}
int out(int p[], int head, int m){
if (head == m-1)
head = 0;
else
head ++;
return head;
}
int in(int *pt, int head, int num, int m, int temp){
int note;
if(num == m-1){
note = 1;
}
else{
if(head + num > m -1)
pt[head + num - m + 1] = temp;
else
pt[head + num] = temp;
note = 0;
}
return note;
}
main(){
int a, b, c, count, diff = 0, min, max, temp = 0, *pt, head = 0, m = 2, num = 0;
int *tp, count1, *temp1,n;
while(scanf("%d %d", &a, &b)==2){
pt = (int *)malloc(m * sizeof(int));
pt[0] = 2;
if (a > b){
min = b;
max = a;
}
else if (a < b){
min = a;
max = b;
}
else{
printf("1\n");
continue;
}
for (count = 1; count <= min ; count++){
if(num != 0){
c = mini(pt, head);
if(count == c)
continue;
if(count < c){
diff++;
temp = diff + count;
if(in(pt, head, num, m, temp) == 1){
n = 2*m;
tp =(int *) malloc(n * sizeof(int));
for (count1 = 0; count1 < num; count1++){
if(head + count1 == m)
head = -count1;
tp[count1] = pt[head + count1];
}
temp1 = pt;
pt = tp;
free(temp1);
pt[num] = temp;
head = 0;
m *= 2;
}
num ++;
}
if(count > c){
head = out(pt,head,m);
num--;
diff ++;
temp = diff + count;
if(in(pt,head,num,m,temp) == 1){
n = 2*m;
tp =(int *) malloc(n * sizeof(int));
for (count1 = 0; count1 < num; count1++){
if(head + count1 == m)
head = -count1;
tp[count1] = pt[head + count1];
}
temp1 = pt;
pt = tp;
free(temp1);
pt[num] = temp;
head = 0;
m *= 2;
}
num++;
}
}
else{
diff++;
temp = diff +count;
pt[0] = temp;
num ++;
}
}
if (temp == max)
printf("0\n");
else
printf("1\n");
free(pt);
head = 0;
diff = 0;
m = 2;
num = 0;
temp = 0;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator