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

    http://codeforces.com/contest/834

    A. The Useless Toy

    题意:

    <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针旋转得到。

    现在给出起始符号和结束符号,以及旋转的次数,判断是逆时针还是顺时针或者是无法判断。

    思路:

    可以知道4为一个周期,所以就把次数对4取余数,看一个周期之内的操作就可以了,分别模拟顺时针和逆时针的操作,如果都可以到达或者都不可以到达,那么它们就是不可识别的行为,其它就可以判断顺时针或者逆时针了。

    代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main()
     5 {
     6     bool f1 = 0;
     7     bool f2 = 0;
     8 
     9     int n;
    10 
    11     char c1,c2;
    12 
    13     scanf("%c %c",&c1,&c2);
    14 
    15     scanf("%d",&n);
    16 
    17     n %= 4;
    18 
    19     char tmp = c1;
    20 
    21     for (int i = 0;i < n;i++)
    22     {
    23         if (tmp == '<') tmp = '^';
    24         else if (tmp == 'v') tmp = '<';
    25         else if (tmp == '>') tmp = 'v';
    26         else if (tmp == '^') tmp = '>';
    27     }
    28 
    29     if (tmp == c2) f1 = 1;
    30 
    31     tmp = c1;
    32 
    33     for (int i = 0;i < n;i++)
    34     {
    35         //printf("%c
    ",tmp);
    36         if (tmp == '<') tmp = 'v';
    37         else if (tmp == 'v') tmp = '>';
    38         else if (tmp == '>') tmp = '^';
    39         else if (tmp == '^') tmp = '<';
    40     }
    41 
    42     if (tmp == c2) f2 = 1;
    43 
    44     //printf("%d %d",f1,f2);
    45 
    46     if (f1 && !f2)
    47         printf("cw
    ");
    48     else if (!f1 && f2)
    49         printf("ccw
    ");
    50     else
    51         printf("undefined
    ");
    52 
    53     return 0;
    54 }

    B. The Festive Evening

    题意:

    一家人要举办宴会。每个客人从他自己特定的门进去,每一道门直到最后一个客人进去之后才会关闭。现在有若干个守卫,他们在每一道门关闭之后才会去守卫另一道门。一个时间单位之内只能按顺序进去一个客人,现在给出客人进门的序列以及守卫的数量,问这个过程中是否有门是无防守的。

    思路:

    从前往后遍历,记录每一道门第一次出现的位置,然后从后往前遍历,记录每一道门最后一次出现的位置。

    之后统计每一时刻有多少道门是开着的,再与守卫的数量进行对比。

    代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 struct node
     5 {
     6     int x,y;
     7 }a[30];
     8 
     9 int b[1000005];
    10 
    11 int main()
    12 {
    13     int n,k;
    14 
    15     scanf("%d%d",&n,&k);
    16 
    17     char s[1000005];
    18 
    19     scanf("%s",s+1);
    20 
    21     for (int i = 0;i < 26;i++)
    22     {
    23         for (int j = 1;j <= n;j++)
    24         {
    25             if (s[j] == 'A' + i)
    26             {
    27                 a[i].x = j;
    28                 break;
    29             }
    30         }
    31     }
    32 
    33     for (int i = 0;i < 26;i++)
    34     {
    35         for (int j = n;j >= 1;j--)
    36         {
    37             if (s[j] == 'A' + i)
    38             {
    39                 a[i].y = j;
    40                 break;
    41             }
    42         }
    43     }
    44 
    45     for (int i = 0;i < 26;i++)
    46     {
    47         for (int j = a[i].x;j <= a[i].y;j++)
    48         {
    49             b[j]++;
    50         }
    51     }
    52 
    53     bool ans = 0;
    54 
    55     for (int i = 1;i <= n;i++)
    56     {
    57         if (b[i] > k) ans = 1;
    58         //printf("%d ",b[i]);
    59     }
    60 
    61     if (ans) printf("YES
    ");
    62     else printf("NO
    ");
    63 
    64     return 0;
    65 }

    C. The Meaningless Game

    题意:

    两个人玩一个游戏,他们的初始值都为1,每次选一个自然数k(除0),一个人乘以k^2,另一个乘以k,现在给出两个数字a,b,问他们的游戏是否可能达到这个结果。

    思路:

    看题解补的。首先,如果有可能达到这个结果,那么a*b肯定是一个数的3次方,把a*b开3次方之后,得到的结果必定能整除a,也必定能整除b,而且它的3次方也必定等于a*b。

    按照上面3个条件判断就可以了。

    代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 
     5 int main()
     6 {
     7     int n;
     8 
     9     scanf("%d",&n);
    10 
    11     while (n--)
    12     {
    13         long long a,b;
    14 
    15         scanf("%I64d%I64d",&a,&b);
    16 
    17         long long c = a * b;
    18 
    19         long long d = round(pow(c*1.0,1.0 / 3));
    20 
    21         if (a % d > 0 || b % d > 0 || d * d * d != c) printf("No
    ");
    22         else printf("Yes
    ");
    23     }
    24 
    25 
    26 
    27     return 0;
    28 }
  • 相关阅读:
    [MacOS]Sublime text3 安装(一)
    [RHEL8]开启BBR
    PAT Advanced 1136 A Delayed Palindrome (20分)
    PAT Advanced 1144 The Missing Number (20分)
    PAT Advanced 1041 Be Unique (20分)
    PAT Advanced 1025 PAT Ranking (25分)
    PAT Advanced 1022 Digital Library (30分)
    PAT Advanced 1019 General Palindromic Number (20分)
    PAT Advanced 1011 World Cup Betting (20分)
    PAT Advanced 1102 Invert a Binary Tree (25分)
  • 原文地址:https://www.cnblogs.com/kickit/p/7276895.html
Copyright © 2011-2022 走看看