第一次组队训练

题目链接:http://www.bnuoj.com/bnuoj/contest_show.php?cid=2009#problem/0

A.........水题,在学校学C的时候就做过的..............

代码如下:

 1 #include <stdio.h>
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,a,i,j=0;
 7     while(scanf ("%d",&n)!=EOF)
 8     {
 9         j=0;
10         if(n==0) break;
11     for (i=1;;i++)
12     {
13         a=n/3;
14         n=n-2*a;
15         j=j+a;
16         if(n<=2)
17         {
18             if (n==2)
19                 j++;
20             break;
21         }
22     }
23     printf ("%d
",j);
24     }
25     return 0;
26 }
View Code

B.

//注意跳出是用EOF(Ctrl+6+z);

代码如下:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #include<string>
 5 #include<string.h>
 6 using namespace std;
 7 int main()
 8 {
 9     int a,b,s=0,n,i=0,x;
10     char d,c[5];
11         while(scanf("%d%c%d%*c%s",&a,&d,&b,c)!=EOF)
12         {
13             i++;
14             if(d=='+')
15         {
16             n=a+b;
17         }
18         else
19         {
20             n=a-b;
21         }
22         if(n<0&&c[0]=='?')
23             s++;
24         else
25         {
26             x=strlen(c);
27             if(x==1&&n==(c[0]-'0')&&n>=0&&n<10)
28             {
29             s++;
30             }
31             else if(x==2&&n>9&&n<100&&(n%10==c[1]-'0')&&(n/10==c[0]-'0'))
32                 s++;
33             else if(n>99&&x==3&&(n%10==c[2]-'0')&&((n/10)%10==c[1]-'0')&&(n/100==c[0]-'0'))
34                 s++;
35         }
36             if(i==100)
37                 break;
38         }
39         printf("%d
",s);
40         return 0;
41 }
View Code

C.

代码如下:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cstring>
 4 using namespace std;
 5 int main()
 6 {
 7     char a[1000];
 8     int b[1000],i,j,n,x;
 9     while(scanf("%s",a) && a[0]!='0')
10     {
11         n=0;
12         x=strlen(a);
13         for(i=0;i<x;i++)
14             b[i]=a[i]-'0';
15         for(i=0;i<x-1;i++)
16         {
17             n=n*10+b[i];
18             n%=17;
19         }
20         n=(n-b[x-1]*5)%17;
21         if(n) printf("0
");
22         else printf("1
");
23     }
24     return 0;
25 }
View Code

D.

//搜索+强剪枝

//代码来自http://blog.csdn.net/andring/article/details/7376129

代码如下:

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 using namespace std;
  5 #define FRE freopen("a.txt","r",stdin);
  6 struct node
  7 {
  8     int x,y;
  9 }queue[1000];
 10 int n,m;
 11 int Max,flag,tatal;
 12 char map[20][20];
 13 char ans[35],stack[35];
 14 int dir[4][2]={-1,0,0,-1,0,1,1,0};
 15 bool yes(int x,int y)
 16 {
 17     return x>=0&&x<n&&y>=0&&y<m;
 18 }
 19 int bfs(int x,int y)
 20 {
 21     node t;
 22     char g[20][20];
 23     for(int i=0;i<n;i++)strcpy(g[i],map[i]);
 24     int head,tail;
 25     head=tail=0;
 26     t.x=x,t.y=y;
 27     queue[tail++]=t;
 28     while(head<tail)
 29     {
 30         x=queue[head].x;
 31         y=queue[head++].y;
 32         for(int i=0;i<4;i++)
 33         {
 34             int xx=x+dir[i][0];
 35             int yy=y+dir[i][1];
 36             if(!yes(xx,yy)||g[xx][yy]=='#')continue;
 37             g[xx][yy]='#';
 38             t.x=xx,t.y=yy;
 39             queue[tail++]=t;
 40         }
 41     }
 42     return head;
 43 }
 44 void dfs(int x,int y,int cnt)
 45 {
 46     if(Max<cnt||(Max==cnt&&flag==1))
 47     {
 48         stack[cnt]=0;
 49         strcpy(ans,stack);
 50         Max=cnt;
 51         flag=0;
 52     }
 53     int res=bfs(x,y);
 54     if(res+cnt-1<Max||(res+cnt-1==Max&&flag==-1))return;
 55     for(int i=0;i<4;i++)
 56     {
 57         int xx=x+dir[i][0];
 58         int yy=y+dir[i][1];
 59         if(!yes(xx,yy)||map[xx][yy]=='#')continue;
 60         if(flag!=1&&ans[cnt]>map[xx][yy]&&tatal==Max)continue;
 61         stack[cnt]=map[xx][yy];
 62         map[xx][yy]='#';
 63         if(flag==0)
 64         {
 65             if(cnt>=Max)flag=1;
 66             else if(ans[cnt]==stack[cnt])flag=0;
 67             else if(ans[cnt]<stack[cnt])flag=1;
 68             else flag=-1;
 69             dfs(xx,yy,cnt+1);
 70             flag=0;
 71         }
 72         else dfs(xx,yy,cnt+1);
 73         map[xx][yy]=stack[cnt];
 74     }
 75 }
 76 int main()
 77 {
 78     //FRE;
 79     while(scanf("%d%d",&n,&m)&&n+m)
 80     {
 81         tatal=0;
 82         for(int i=0;i<n;i++)
 83         {
 84             scanf("%s",map+i);
 85             for(int j=0;j<m;j++)
 86             {
 87                 if(map[i][j]!='#')tatal++;
 88             }
 89         }
 90         Max=1;
 91         memset(ans,0,sizeof(ans));
 92         for(int i=0;i<n;i++)
 93         {
 94             for(int j=0;j<m;j++)
 95             {
 96                 if(map[i][j]=='#')continue;
 97                 if(Max==tatal&&ans[0]>map[i][j])continue;
 98                 stack[0]=map[i][j];
 99                 map[i][j]='#';
100                 if(ans[0]==stack[0])flag=0;
101                 else if(ans[0]<stack[0])flag=1;
102                 else flag=-1;
103                 dfs(i,j,1);
104                 map[i][j]=stack[0];
105             }
106         }
107         printf("%s
",ans);
108     }
109     return 0;
110 }
View Code

E.

水题...........= =.......不解释........

代码如下:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     char a[4],t;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         scanf("%s",a);
13         int x,i,n=0;
14         x=strlen(a);
15         if(x==5) printf("3
");
16         else
17         {
18             for(i=0;i<x;i++)
19             {
20                 if(a[i]=='o') n++;
21                 if(a[i]=='n') n++;
22                 if(a[i]=='e') n++;
23             }
24             if(n>=2) printf("1
");
25             else printf("2
");
26         }
27     }
28     return 0;
29 }
View Code

F.

代码如下:

 1 #include<stdio.h>
 2 #include<string.h>
 3 bool aa[1000000];
 4 bool solve(int n)
 5 {
 6     if(n%7==0)  return true;
 7     int t=n;
 8     while(t)
 9     {
10         if(t%10==7)  return true;
11         t/=10;
12     }
13     return false;
14 }
15 
16 void calc()
17 {
18     for(int i=1;i<1000000;i++)
19     {
20         if(solve(i))  aa[i]=true;
21         else  aa[i]=false;
22     }
23 
24 }
25 int main()
26 {
27     int n,m,k;
28     int t;
29     int cnt;
30     calc();
31     while(scanf("%d%d%d",&n,&m,&k)!=EOF)
32     {
33         if(n==0 && m==0 && k==0) break;
34         t=m;
35         cnt=0;
36      for(;;)
37         {
38             if(aa[t])cnt++;
39             if(cnt==k)
40             {
41                 printf("%d
",t);
42                 break;
43             }
44             if(n==m)
45             {
46                 t+=2*(m-1);
47                 continue;
48             }
49             if(m==1)
50             {
51                 t+=2*(n-m);
52                 continue;
53             }
54             t+=2*(n-m);
55             if(aa[t])cnt++;
56             if(cnt==k)
57             {
58                 printf("%d
",t);
59                 break;
60             }
61 
62             t+=2*(m-1);
63         }
64     }
65     return 0;
66 }
View Code

G.

在学校做过类似的题目,但那个题目是一个盒子的。此题对于Bob的胜利可以找出规律........

Bob胜利时,最初的球的个数(多的那一边)为:3,7,15,31,63,........等于前一个球的个数乘以2加1;

代码如下:

 1 #include <stdio.h>
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,sum;
 7     while(~scanf("%d",&n)&&n)
 8     {
 9         sum=1;
10         for(;;)
11         {
12             sum=sum*2+1;
13             if(n<=sum)
14                 break;
15         }
16         if(n==sum)
17             printf("Bob
");
18         else
19             printf("Alice
");
20     }
21     return 0;
22 }
View Code

H.

//待解决

I.

暴力解题

代码如下:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 
 6 using namespace std;
 7 
 8 int map[122][122];
 9 
10 int N, K, M;
11 
12 int main()
13 {
14     int T;
15     int a, b;
16     while (scanf("%d", &T) != EOF)
17     {
18         while (T--)
19         {
20             memset(map, 0, sizeof(map));
21             scanf("%d%d%d", &N, &M, &K);
22             for (int i = 0; i < M; i++)
23             {
24                 scanf("%d%d", &a, &b);
25                 map[a][b] = 1;
26                 map[b][a] = 1;
27             }
28             int ans = 0;
29             while (1)
30             {
31                 int count = 0;
32                 for (int i = 0; i < N - 1; i++)
33                 {
34                     for (int j = i + 1; j < N; j++)
35                     {
36                         int cnt = 0;
37                         if (!map[i][j])
38                         {
39                             for (int k = 0; k < N; k++)
40                             {
41                                 if (map[i][k] && map[j][k])
42                                 {
43                                     cnt++;
44                                 }
45                             }
46                             if (cnt >= K && !map[i][j])
47                             {
48                                 map[i][j] = 1;
49                                 map[j][i] = 1;
50 //                                cout << "i == " << i << "j == " << j << endl;
51                                 count++;
52                             }
53                         }
54                     }
55                 }
56                 ans += count;
57                 if (count == 0)
58                 {
59                     break;
60                 }
61             }
62             printf("%d
", ans);
63         }
64     }
65 //    system("pause");
66     return 0;
67 }
View Code

//代码来自于:http://blog.csdn.net/qinaide_lixiaoshuo/article/details/8945349

J.

暴力......

代码如下:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int t;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         int N,M,a[410],maxx,sum,i,j;
13         scanf("%d%d",&N,&M);
14         memset(a,0,sizeof(a));
15         for(i=0;i<N;i++)
16             scanf("%d",&a[i]);
17         for(i=N;i<2*N-1;i++)
18             a[i]=a[i-N];
19         for(i=0,maxx=0;i<N;i++)
20         {
21             for(j=i,sum=0;j<i+M;j++)
22             sum+=a[j];
23             if(sum>maxx) maxx=sum;
24         }
25         printf("%d
",maxx);
26     }
27     return 0;
28 }
View Code

K.

 ..............还木有看

原文地址:https://www.cnblogs.com/teilawll/p/3218308.html