记一次周赛

A

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2089

去掉最高最低 算平均

View Code
 1 #include<iostream>

 2 #include<cstring>

 3 #include<cstdio>

 4 #include<stdlib.h>

 5 #include<algorithm>

 6 using namespace std;

 7 double a[10];

 8 int main()

 9 {

10     int i,j,k,n,m,x,y;

11     while(cin>>a[0])

12     {

13         int f = 0;

14         double s= a[0];

15         for(i = 1; i < 6 ; i++)

16         {

17             cin>>a[i];

18             s+=a[i];

19         }

20         for(i = 0; i < 6 ; i++)

21             if(a[i]!=0)

22                 f =1;

23         if(!f)

24             break;

25         double mi = a[0],ma = a[1];

26         x = 0;y = 1;

27         for(i = 0 ; i < 6 ; i++)

28         {

29             if(a[i]>ma)

30             {

31                 x = i;

32                 ma = a[i];

33             }

34             if(a[i]<mi)

35             {

36                 y = i;

37                 mi = a[i];

38             }

39         }

40         s= s-(mi+ma);;

41         cout<<s/4<<endl;

42     }

43     return 0;

44 }

B

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2090
不能用gets输入 错了好几次

View Code
 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<stdlib.h>

 5 using namespace std;

 6 char str[1000010],ss[1000010];

 7 int main()

 8 {

 9     int i,j,k,m,kk=0,g;

10     char c;

11     while(cin>>str)

12     {

13         if(strcmp(str,"0")==0)

14         break;

15         kk++;

16         k = strlen(str);

17         g=0;

18         int gg=0;

19         while(str[gg]=='0')

20         {

21             gg++;

22         }

23         ss[g++] = str[k-1];

24         c = str[k-1];

25         int tk = 0;

26         for(i = k-2 ; i >=gg ; i--)

27         {

28             if(str[i]-(c+tk)>=0)

29             {

30                 ss[g++] = str[i]-(c+tk)+'0';

31                 tk = 0;

32                 c = ss[g-1];

33             }

34             else

35             {

36                 ss[g++] = (str[i]+10)-(c+tk)+'0';

37                 tk = 1;

38                 c = ss[g-1];

39             }

40         }

41         printf("%d. ",kk);

42         if(ss[g-1]=='0')

43         {

44             cout<<"IMPOSSIBLE\n";

45             continue;

46         }

47         int f = 0;

48         for(i = g-1; i >= 0 ; i--)

49         {

50             if(str[i]<'0'||str[i]>'9')

51             {

52                 f = 1;

53                 break;

54             }

55         }

56         if(f)

57         {

58             cout<<"IMPOSSIBLE\n";

59             continue;

60         }

61         for(i = g-1 ; i >=0 ; i--)

62         cout<<ss[i];

63         puts("");

64     }

65     return 0;

66 }

C
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2091

当时没看这题 后来听学长说了怎么做 才A了的 从外到内 每次都找一圈中的最小的放在左上角 判断是否成立

View Code
  1 #include <iostream>

  2 #include<cstring>

  3 #include<cstdio>

  4 #include<stdlib.h>

  5 using namespace std;

  6 int ro[1010][1010],go[1010][1010],yy[5000];

  7 int main()

  8 {

  9     int i,j,k,n,m,x,y,oo=0,g;

 10     while(cin>>n)

 11     {

 12         if(n==0)

 13         break;

 14         oo++;

 15         int flag = 1;

 16         for(i = 1; i <= n ;i++)

 17         for(j = 1 ; j <= n ; j++)

 18         {

 19             scanf("%d",&ro[i][j]);

 20         }

 21         k = 0;

 22         j = 1;

 23         g =1;

 24         int kk;

 25         while(1)

 26         {

 27              kk = n*k+j;

 28              g=1;

 29              for(i = j ; i <= n-j+1 ; i++)

 30                 yy[g++] = ro[k+1][i];

 31              for(i = k+2 ; i <= n-k ; i++)

 32                  yy[g++]=ro[i][n-j+1];

 33              for(i = n-j ; i >= j ; i--)

 34                  yy[g++]=ro[n-k][i];

 35              for(i = n-k-1 ; i > k+1 ; i--)

 36                  yy[g++] = ro[i][j];

 37              for(i = 1 ; i < g ; i++)

 38              if(yy[i]==kk)

 39              {

 40                  x = i;

 41                  break;

 42              }

 43              if(i==g)

 44              flag=0;

 45              if(!flag)

 46              break;

 47              int o = x-1;

 48 

 49              for(i = j ; i <= n-j+1 ; i++)

 50              {

 51                  o++;if(o==g) o=1;

 52                  ro[k+1][i] = yy[o];

 53              }

 54              for(i = k+2 ; i <= n-k ; i++)

 55              {

 56                  o++;if(o==g) o=1;

 57                  ro[i][n-j+1] = yy[o];

 58              }

 59              for(i = n-j ; i >= j ; i--)

 60              {

 61                  o++;if(o==g) o=1;

 62                  ro[n-k][i] = yy[o];

 63              }

 64              for(i = n-k-1 ; i > k+1 ; i--)

 65              {

 66                   o++;

 67                   if(o==g) o=1;

 68                   ro[i][j] = yy[o];

 69              }

 70             if((k+1)==n/2)

 71              {

 72                 break;

 73              }

 74              j++;

 75              k++;

 76         }

 77         printf("%d. ",oo);

 78         if(!flag)

 79         {

 80             cout<<"NO\n";

 81             continue;

 82         }

 83 

 84         for(i = 1 ; i <= n ; i++)

 85         {

 86             for(j = 1; j <= n ; j++)

 87             if(ro[i][j]!=((i-1)*n+j))

 88             {

 89                 flag = 0;

 90                 break;

 91             }

 92             if(!flag)

 93             break;

 94         }

 95          if(!flag)

 96         {

 97             cout<<"NO\n";

 98         }

 99         else

100         cout<<"YES\n";

101     }

102     return 0;

103 }

104 

105  

D

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2092

第一时间做的这题,打完发现样例不对 就一直没敢交 后来说样例错了 而且EOF出现一次就break

View Code
 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<stdlib.h>

 5 using namespace std;

 6 char str[100010];

 7 int main()

 8 {

 9     int i,j,k;

10     while(gets(str)!=NULL)

11     {

12         if(strcmp(str,"EOF")==0)

13             break;

14         k = strlen(str);

15         int g=0,xx=0;

16         for(i = 0 ; i < k ; i++)

17         {

18             if(i+2<k&&str[i]=='E'&&str[i+1]=='O'&&str[i+2]=='F')

19             {

20                 return 0;

21             }

22             if(str[i]!=' '&&(str[i]<'a'||str[i]>'z'))

23                 continue;

24             if(str[i]==' ')

25             {

26                 cout<<str[i];

27             }

28             else

29             {

30                 if(i+1<k)

31                 {

32                     if(str[i]=='d'&&str[i+1]=='d')

33                     {

34                         cout<<'p';

35                         i++;

36                     }

37                     else

38                     if(str[i]=='e'&&str[i+1]=='i')

39                     {

40                         if(i!=0&&str[i-1]=='c')

41                         cout<<"ei";

42                         else

43                         cout<<"ie";

44                         i++;

45                     }

46                     else

47                     if(i+3<k)

48                     {

49                         if(str[i]=='p'&&str[i+1]=='i'&&str[i+2]=='n'&&str[i+3]=='k')

50                         {

51                             cout<<"floyd";

52                             i+=3;

53                         }

54                         else

55                         cout<<str[i];

56                     }

57                     else

58                     cout<<str[i];

59                 }

60                 else

61                 cout<<str[i];

62             }

63         }

64         puts("");

65     }

66     return 0;

67 }

68  

E
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2093

比赛时没看这道题 看好多人都挂在这了 就没敢看 注意一下会有负数 打个表

View Code
 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<stdlib.h>

 5 using namespace std;

 6 #define N 1000010

 7 int pg[N],pr[N],pd[N],g,p[N];

 8 void init()

 9 {

10     int i,j;

11     for(i = 2 ; i <= 1000; i++)

12     {

13         if(!pr[i])

14         {

15             for(j = i+i ; j <= 1000000 ; j+=i)

16             if(!pr[j])

17             pr[j] = 1;

18         }

19     }

20     for(i = 1; i <= 1000 ; i++)

21         for(j = 1; j <= 1000 ; j++)

22         {

23             int k = i*i+j*j;

24             if(k<=1000000)

25             pg[k] = 1;

26         }

27     p[2] = 1;

28     pd[2] = 1;

29     for(i = 2 ; i <= 1000000 ; i++)

30     {

31         if(!pr[i])

32           pd[i]= pd[i-1]+1;

33         else

34           pd[i] = pd[i-1];

35         if(!pr[i]&&pg[i])

36           p[i] = p[i-1]+1;

37         else

38           p[i] = p[i-1];

39     }

40 }

41 int main()

42 {

43     int i,j,k,n,m;

44     init();

45     while(cin>>n>>m)

46     {

47         if(n==-1&&m==-1)

48             break;

49         int sum = 0;

50         if(m<2)

51         {

52             cout<<n<<" "<<m<<" 0 0\n";

53             continue;

54         }

55         cout<<n<<" "<<m<<" ";

56         if(n<2)

57         n = 2;

58         cout<<pd[m]-pd[n-1]<<" "<<p[m]-p[n-1]<<endl;

59     }

60     return 0;

61 }

62  

 

 

 

 

 

你可能感兴趣的:(记一次周赛)