POJ - 2115(没有解决)

2016.8.17下午

今天本想练习数据结构线性表的,结果这题没有解决,占了大半时间。本以为是简单题,居然要用到数论。

写了个错误代码,主观以为第13行的count1不会很大,其实不然。一开始RE,看了测试数据c可以为0.后来WA就是这个问题,

测试数据:http://contest.felk.cvut.cz/04prg/solved/#c。

在线文本比较工具找不一样的数据

错误代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<stdio.h>
#include<math.h>
int main(){
    freopen("test.out","w",stdout);
    int count,a,b,c,k,bite,flag;
    while(scanf("%d%d%d%d",&a,&b,&c,&k)&&(a!=0||b!=0||c!=0||k!=0)){
    count=0;
    flag=0;
    bite=pow(2,k);
     
    int count1=0;
    while(!flag&&count1<100000){
        count1++;
        if(c==0&&(b-a)!=0){
            break;
        }
        else if(c==0&&(b-a)==0){
            flag=1;
            break;
        }
        if((b-a)%c==0&&(b-a)/c>=0){
        count=(b-a)/c;
        flag=1;
        }
        else
        b+=bite;
    }
    if(flag)  
    printf("%d\n",count);
    else
    printf("FOREVER\n");
    }
    return 0;
}

  

posted on   SijingLin  阅读(161)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示