Codeforces Round #129 (Div. 2)
第二次做,第一次做了一个,这次做比第一次好,环境好多了。。第一个水题,居然无语的错了两次,INT64好久没用了,忘记加了,唉,如此水题。。。第二个,思考,看出其贪心本质,自己想了组数据手算验证。。。居然1Y。。。剩下一个半小时就是悲剧。。。看看第三个,貌似可以搞,肯定是后边减前边的,但是数据感觉比较大,看看过D的比较多,然后去看D,看懂了D觉得D应该可以做,先快排,然后历遍一遍,悲剧没注意前后可以相等。。。然后,交了3 次 后错了,查错 还有10分钟,发现bug,额,慌乱中交了几次。。。最终还是没过。。。
最后 过了俩题,有进步。。。
PS:今天又去搞D,发现超时。。。算法有问题。。。解题报告在这里。
悲剧的A题
1 #include <stdio.h> 2 #include <string.h> 3 __int64 p[100001]; 4 int main() 5 { 6 __int64 i,j,min,n,z; 7 z = 0; 8 scanf("%I64d",&n); 9 scanf("%I64d",&p[1]); 10 min = p[1];j = 1; 11 for(i = 2;i <= n;i ++) 12 { 13 scanf("%I64d",&p[i]); 14 if(min > p[i]) 15 { 16 min = p[i]; 17 j = i; 18 } 19 } 20 for(i = 1;i <= n;i ++) 21 { 22 if(min == p[i] &&i != j) 23 z = 1; 24 } 25 if(z) 26 printf("Still Rozdil\n"); 27 else 28 printf("%I64d\n",j); 29 return 0; 30 }
B题
1 #include <stdio.h> 2 #include <string.h> 3 __int64 p[100001]; 4 int main() 5 { 6 int n,i; 7 __int64 sum = 0; 8 scanf("%d",&n); 9 for(i = 1;i <= n;i ++) 10 { 11 scanf("%I64d",&p[i]); 12 if(i >= 2) 13 { 14 if(p[i] < p[i-1]) 15 sum += p[i-1] - p[i]; 16 } 17 } 18 printf("%I64d\n",sum); 19 return 0; 20 }
D题 复制上解题报告吧。我的想法是标记然后把所有的数快排,再找一遍。貌似也可以用快排。。。但是在36组数据老是TLE啊。。。
7.13 在DIV 1 发现有我思路差不多的,经过观察发现,人家用的是sort。。。。我用的是qsort。。。。好假。。。C++下个学期好好搞。
It is nice to use the map structure in this problem, but you can solve it without map (using sorting and binary serach). Lets iterate through all possible colors that we have and suppose that this currect color is the one that will make our set funny. The minimal number through all this will be the answer. To find the minimal number of turns to make our set funny using current color we need to know two numbers: the number of cards with current color on the front side and the number of cards with the current color on back side (but not at the same time). Let it be integers a and b. Let m = (n + 1) / 2 — the minimal number of the same cards required to get the funny set. Then if a + b < m it is impossible to make set funny using current color at all. If a ≥ m then the answer is 0, otherwise the answer ism - a.

浙公网安备 33010602011771号