poj 3665

记九月的第一个小水题

题目:http://poj.org/problem?id=3665

好像是以前做过的一个比赛题目,当时没有过,后来再写也没有过。刚才看到,就又重新读了一遍题目,竟然发现,自己以前读错题目了,而且那时候总是检查程序,根本就没重新去读过题,悲剧!题目给的算法规则里第二条说要把最高分的牛的分数平均分给 除他以外的其他牛(当然,如果不能平分,那么就把多余的分数从第一头牛开始每个 + 1的分完,当然还是不能给自己加),然就是把分数按给每头牛(包括自己)错了好几次,

View Code
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <iostream>
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int n, t, maxx, pos;
11     int r[1006]={0};
12     int s, x, y;
13     int i, j;
14     //freopen("data.txt","r",stdin);
15     while (scanf("%d%d",&n,&t) != EOF)
16     {
17 
18         for (i=0; i<n; i++)
19         scanf("%d",&r[i]);
20         if(n == 1)
21         {
22             for(i = 0; i < t; i++)
23             cout<<n<<endl;
24             continue;
25         }
26         s = 0;
27         pos = -1;
28         int tpos = -1;
29         while (t--)
30         {
31             x = s % (n-1);
32             y = s / (n-1);
33             i = 0;
34             while (x)
35             {
36                 if (i != pos)
37                 {
38                     r[i] += 1;
39                     x--;
40                 }
41                 i++;
42             }
43             maxx = -1;
44             for (i=0; i<n;i++)
45             {
46                 if(i != tpos)  //  自己不能再平分分数了
47                 r[i] += y;
48                 if(r[i] > maxx)
49                 {
50                     maxx = r[i];
51                     pos = i;
52                 }
53             }
54             tpos = pos;
55             printf("%d\n",pos+1);
56             s = r[pos];
57             r[pos] = 0;
58         }
59     }
60     return 0;
61 }

 

posted @ 2012-09-03 21:41  AC_Girl  阅读(264)  评论(0编辑  收藏  举报