剩余定理,读题废了好长时间,看完题,又看了一遍算法段轮的31.5
1#include<stdio.h>
2#define N 21252
3typedef struct node{
4 int d;
5 int x;
6 int y;
7void operator=(node b)
8{
9 d=b.d;
10 x=b.x;
11 y=b.y;
12}}NODE;
13NODE EXTENDED_EUCLID(int a,int b)
14{
15 NODE first,sec;
16 if(b==0){
17 sec.d=a;
18 sec.x=1;
19 sec.y=0;
20 return sec;
21 }
22 first=EXTENDED_EUCLID(b,a%b);
23 sec.d=first.d;
24 sec.x=first.y;
25 sec.y=first.x-(a/b)*first.y;
26 return sec;
27}
28int main()
29{
30 int a,c1,c2,c3,j=1;
31 int p,e,i,d;
32 NODE m1,m2,m3;
33 m1= EXTENDED_EUCLID(28*33,23);
34 m2= EXTENDED_EUCLID(23*33,28);
35 m3= EXTENDED_EUCLID(23*28,33);
36 c1=28*33*m1.x;
37 c2=23*33*(m2.x+28);
38 c3=23*28*m3.x;
39 while(scanf("%d%d%d%d",&p,&e,&i,&d)){
40 if(p==-1&&e==-1&&i==-1&&d==-1)break;
41 a=(p*c1+e*c2+i*c3-d+N)%N;
42 if(!a)a=N;
43 printf("Case %d: the next triple peak occurs in %d days.\n",j++,a);
44 }
45 return 0;
46}
前27行都是用来求c1,c2,c3的,真正这道题的数据处理只是在main函数的while循环
posted on 2008-02-23 11:20
zoyi 阅读(539)
评论(0) 编辑 收藏 引用 所属分类:
acm