zoukankan      html  css  js  c++  java
  • Codeforces Round #310 (Div. 2)

    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
    ", 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 <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1010;
     4 int a[maxn], b[maxn];
     5 int main ()
     6 {
     7     int n;
     8     while (scanf ("%d", &n) != EOF)
     9     {
    10         int flag = 1;
    11         for (int i=0; i<n; i++)
    12         {
    13             scanf ("%d", &a[i]);
    14             if (i != a[i])
    15                 flag = 0;
    16         }
    17         for (int j=0; j<n&&!flag; j++)
    18         {
    19             flag = 1;
    20             for (int i=0; i<n; i++)
    21             {
    22 
    23                 if (i % 2 == 0)
    24                     a[i] = (a[i] + 1) % n;
    25                 else
    26                     a[i] = (a[i] + n - 1) % n;
    27                 if (a[i] != i)
    28                     flag = 0;
    29             }
    30         }
    31         if (flag)
    32             printf ("Yes
    ");
    33         else
    34             printf ("No
    ");
    35     }
    36     return 0;
    37 }

    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, num, ans, a, b, c;
    18         while (m --)
    19         {
    20             scanf ("%d", &num);
    21             scanf ("%d", &c);
    22             a = c;
    23             ans = 0;
    24             for (int i=1; i<num; i++)
    25             {
    26                 scanf ("%d", &b);
    27                 if (b > a + 1 && ans == 0)
    28                     ans = num - i;
    29                 a = b;
    30             }
    31             if (c != 1)//只有大的可以向小的上面一个一个套,记住哦,是一个一个,在这里wa的心真是塞塞的
    32                 ans = num - 1;
    33             sum += ans * 2;
    34         }
    35         printf ("%d
    ", sum);
    36     }
    37     return 0;
    38 }
    39 /*
    40 9 3
    41 3 7 8 9
    42 3 1 2 3
    43 3 4 5 6
    44 
    45 */

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

    本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    第一个JAVA程序
    python小项目(python实现鉴黄)源码
    整蛊小病毒,自己拿来快乐
    JavaScript(这里主要侧重于 JavaScript HTML DOM)杂项
    图片与文本基础(html和css)
    CSS的基础学习
    Javascript中this作用域以及bind方法的重写
    斐波那契数列算法求解及速度
    javascript中的描述对象(Descriptor)获取和定义随笔
    vue-cli3生产环境和开发环境路径的替换
  • 原文地址:https://www.cnblogs.com/alihenaixiao/p/4604979.html
Copyright © 2011-2022 走看看