码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #310 (Div. 2)

时间:2015-06-28 01:10:16      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

A. Case of the Zeros and Ones

题目大意:

  给出一个只含0和1的字符串,当是0和1相邻的话,这两个字符就可以删除,问最后不能删除的字符有多少个?

解题思路:

  只需要分别统计出来0和1的个数,然后相减之后的绝对值就是答案。

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <cmath>
 7 using namespace std;
 8 
 9 const int maxn = 200010;
10 const int INF = 0x3f3f3f3f;
11 int Fabs (int a, int b)
12 {
13     if (a > b)
14         return a - b;
15     return b - a;
16 }
17 int main ()
18 {
19     char str[maxn];
20     int n, a, b;
21     while (scanf ("%d", &n) != EOF)
22     {
23         a = b = 0;
24         scanf ("%s", str);
25         for (int i=0; i<n; i++)
26         {
27             if (str[i] == 0)
28                 a ++;
29             else
30                 b++;
31         }
32         printf ("%d\n", Fabs(a , b));
33     }
34     return 0;
35 }

B. Case of Fake Numbers

题目大意:

  一个序列有n个数,从1开始编号,每次对序列的操作是奇树为加一,偶数为减一,问经过有限次操作后能不能构成0,1,2,3,4·······n-1的序列。

解题思路:

  因为这个序列中的数都是在[0,n-1]区间内的数字,这个序列肯定经过n次数的操作之后会循环,

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <cmath>
 7 using namespace std;
 8 
 9 const int maxn = 2000;
10 const int INF = 0x3f3f3f3f;
11 
12 int main ()
13 {
14     int n, a[maxn], i;
15     while (scanf ("%d", &n) != EOF)
16     {
17         for (i=0; i<n; i++)
18             scanf ("%d", &a[i]);
19         for (i=0; i<n; i++)
20         {
21             int flag = 0;
22             for (int j=0; j<n; j++)
23             {
24                 if (j%2)
25             a[j] = (a[j] + 1) % n;
26                 else
27                     a[j] = (a[j] - 1 + n) % n;
28                 if (a[j] != j)
29                     flag ++;
30             }
31             if (flag==0)
32                 break;
33         }
34         if (i < n)
35             printf ("Yes\n");
36         else
37             printf ("No\n");
38     }
39     return 0;
40 }

C. Case of Matryoshkas

题目大意:

  有n个可爱美丽滴俄罗斯娃娃,编号从1开始,编号大的可以套在编号小的上面,因为她们爱可爱了,所以现在要把它们全部套在一起娶回家。

套娃娃的时候只能有两种操作:

  1:把单独的一个大娃娃套在一串或者一个娃娃外面。

  2:把单独的一个娃娃在一串娃娃的最外层取下来。

问最小多少次操作才能把娃娃娶回家?

解题思路:

  就是模拟,就是迷你。

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <cmath>
 7 using namespace std;
 8 
 9 const int maxn = 100010;
10 const int INF = 0x3f3f3f3f;
11 
12 int main ()
13 {
14     int n, m;
15     while (scanf ("%d %d", &n, &m) != EOF)
16     {
17         int sum = m - 1, ans = 0, a1, b;
18         while (m --)
19         {
20             int num, f = 0;
21             scanf ("%d", &num);
22             scanf ("%d", &a1);
23             num --;
24             int c = num;
25             int a = a1;
26             while (num --)
27             {
28                 scanf ("%d", &b);
29                 if (b > a + 1 && f == 0)
30                     f = num + 1;
31                 a = b;
32             }
33             if (a1 != 1)//只有大的可以向小的上面一个一个套,记住哦,是一个一个,在这里wa的心真是塞塞的
34                 f = c;
35             ans += f;
36             sum += f;
37         }
38         ans += sum;
39         printf ("%d\n", ans);
40     }
41     return 0;
42 }

后面的题目本宝宝真的做不到啊,毕竟手残党,明天一定第一时间给大家补上,~~~~~~~~

Codeforces Round #310 (Div. 2)

标签:

原文地址:http://www.cnblogs.com/alihenaixiao/p/4604979.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!