2014ACM/ICPC亚洲区西安站 复旦命题

http://codeforces.com/gym/100548

A 签到

问一个序列是不是yes,yes的序列满足每个数都是3的倍数。

 1 #include<cstdio>
 2 int main(){
 3     int t,n,x;
 4     while(~scanf("%d",&t)){
 5         int cas=1;
 6         while(t--){
 7             scanf("%d",&n);
 8             bool flag=true;
 9             while(n--){
10                 scanf("%d",&x);
11                 if(x%3) flag=false;
12             }
13             printf("Case #%d: ",cas++);
14             puts(flag?"Yes":"No");
15         }
16     }
17     return 0;
18 }
View Code

输入a,b,序列s0=a,s1=b,si=si-1 和 si-2的差的绝对值,求序列中有多少个不同的数字。

找了半天规律,然后就是当a大于b的时候,a会不断的减去b,直至a《b,用个除法o1算出出现多少个数,这个规律只能多测几个数,把序列打出来看。

 1 #include<cstdio>
 2 typedef __int64 LL;
 3 int main(){
 4     int t;
 5     LL a,b;
 6     while(~scanf("%d",&t)){
 7         int cas=1;
 8         while(t--){
 9             scanf("%I64d%I64d",&a,&b);
10             printf("Case #%d: ",cas++);
11             if(a==0&&b==0){
12                 puts("1");
13                 continue;
14             }
15             if(a==0||b==0){
16                 puts("2");
17                 continue;
18             }
19             LL ans=0;
20             while(true){
21                 if(a==b){
22                     ans+=2;
23                     break;
24                 }
25                 if(b==0){
26                     ans++;
27                     break;
28                 }
29                 if(a>b){
30                     ans+=a/b;
31                     LL tmp=a%b;
32                     a=b;
33                     b=tmp;
34                     continue;
35                 }
36                 if(a<b){
37                     LL tmp=b-a;
38                     a=b;
39                     b=tmp;
40                     continue;
41                 }
42             }
43             printf("%I64d
",ans);
44         }
45     }
46     return 0;
47 }
View Code

end

原文地址:https://www.cnblogs.com/gaolzzxin/p/4667471.html