成长轨迹53 【ACM算法之路 百炼poj.grids.cn】【枚举】【2747、2810、2692、2977】

一次ac的没啥好说、、、

 

2747:数字方格

 1 //这个。。。貌似米有什么技巧可言。。。
2 #include <stdio.h>
3 int main()
4 {
5 int i,j,k,n,t,s,max;
6 scanf("%d",&t);
7 for(s=0;s<t;s++)
8 {
9 max=0;
10 scanf("%d",&n);
11 for(i=0;i<=n;i++)
12 for(j=0;j<=n;j++)
13 for(k=0;k<=n;k++)
14 {
15 if(((i+j)%2==0)&&((j+k)%3==0)&&((i+j+k)%5==0))
16 {
17 if((i+j+k)>max)
18 max=i+j+k;
19 }
20 }
21 printf("%d\n",max);
22 }
23 return 0;
24 }

 

 


2810:完美立方

 1 #include <stdio.h>
2 #include <string.h>
3
4 int cube[101];
5 int main()
6 {
7
8 int n;
9 scanf("%d",&n);
10 for(int i=2;i<=n;i++)//【这里应该从2开始而不是6】
11 {
12 cube[i]=i*i*i;
13 }
14 for(int a=6;a<=n;a++)
15 {
16
17 for(int b=2;b<a-2;b++)
18 {
19 if(cube[a]<cube[b]+cube[b+1]+cube[b+2])
20 break;
21 for(int c=b+1;c<a-1;c++)
22 {
23 if(cube[a]<cube[b]+cube[c]+cube[c+1])
24 break;
25 for(int d=c+1;d<a;d++)
26 {
27 int result=cube[b]+cube[c]+cube[d];
28
29 if(cube[a]==result)
30 printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
31 else if(cube[a]<result)
32 break;
33 }
34 }
35 }
36 }
37
38 return 0;
39 }

 

 


2692:假币问题

 1 //如果没有找出需求元素的思路
2 //就尝试将元素遍历,看看是否满足需求
3 #include <stdio.h>
4 #include <string.h>
5 char left[3][7],right[3][7],result[3][7];
6
7 bool islight(char c)
8 {
9 for(int i=0;i<3;i++)
10 {
11 if(result[i][0]=='u'&&strchr(right[i],c)==NULL)
12 {
13 return false;
14 }
15 else if(result[i][0]=='e'&&(strchr(left[i],c)!=NULL||strchr(right[i],c)!=NULL))
16 {
17 return false;
18 }
19 else if(result[i][0]=='d'&&strchr(left[i],c)==NULL)
20 {
21 return false;
22 }
23 }
24 return true;
25 }
26
27 bool isheavy(char c)
28 {
29 for(int i=0;i<3;i++)
30 {
31 if(result[i][0]=='u'&&strchr(left[i],c)==NULL)
32 {
33 return false;
34 }
35 else if(result[i][0]=='e'&&(strchr(left[i],c)!=NULL||strchr(right[i],c)!=NULL))
36 {
37 return false;
38 }
39 else if(result[i][0]=='d'&&strchr(right[i],c)==NULL)
40 {
41 return false;
42 }
43 }
44 return true;
45 }
46
47
48 int main()
49 {
50 int t;
51 scanf("%d",&t);
52 while(t--)
53 {
54 for(int i=0;i<3;i++)
55 {
56 scanf("%s %s %s",left[i],right[i],result[i]);
57 }
58 for(char c='A';c<'M';c++)
59 {
60 if(islight(c))
61 {
62 printf("%c is the counterfeit coin and it is light.\n",c);
63 break;
64 }
65 if(isheavy(c))
66 {
67 printf("%c is the counterfeit coin and it is heavy.\n",c);
68 break;
69 }
70 }
71 }
72 return 0;
73 }

 

 


2977:生理周期

 1 #include "stdio.h"
2
3
4 int main()
5 {
6 int p,q,i,d,id=0;
7 while(1)
8 {
9 id++;
10 scanf("%d %d %d %d",&p,&q,&i,&d);
11 if(p==-1&&q==-1&&i==-1&&d==-1)
12 break;
13 int j;
14 for(j=d+1;j<21252;j++)//注意一定比d大
15 if((j-p)%23==0)
16 break;
17 for(;j<21252;j+=23)
18 if((j-q)%28==0)
19 break;
20 for(;j<21252;j+=23*28)
21 if((j-i)%33==0)
22 break;
23 printf("Case %d: the next triple peak occurs in %d days.\n",id,j-d);
24 }
25 return 0;
26 }

 

posted @ 2012-02-22 17:32  MooreZHENG  阅读(439)  评论(0编辑  收藏  举报