• Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】


    A. The Useless Toy

    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.

    Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):

    After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.

    Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.

    Input

    There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.

    In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation.

    It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.

    Output

    Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.

    Examples
    Input
    ^ >
    1
    Output
    cw
    Input
    < ^
    3
    Output
    ccw
    Input
    ^ v
    6
    Output
    undefined


    题目链接:http://codeforces.com/contest/834/problem/A

    题意:给出两个方向和转动次数,问在给定的转动次数中能否由第一个方向转到第二个方向,并且是顺时针转动还是逆时针转动,如果顺时针转动次数和逆时针是一样的,输出undefined,顺时针转动输出cw,逆时针转动输出ccw。

    注:转动次数也存在周期性

    分析:先看看我的战记:

    很明显被hacked了,为啥会被hacked呢?

     我的做法是算出每两个方向的ASCII的差值,显然可以得到一组数,+24,-24,+34,-34,+32,-32,+58,-58,+56,-56,+2,-2

    ^-->v--------(24)

    v-->^--------(-24)

    ^--><--------(34)

    <-->^--------(-34)

    ^-->>--------(32)

    >-->^--------(-32)

    v--><--------(58)

    <-->v--------(-58)

    v-->>--------(56)

    >-->v--------(-56)

    <-->>--------(2)

    >--><--------(-2)

    这样做为啥会pp呢,(不用想了,肯定是数据太水了)为啥后面会被hacked了呢?

    有一种条件是不是没想到呢?假如两个转动方向相同,转动次数的是不是应该等于0呢,无论转动次数是多少,一定应该输出undefined

    所以这种情况导致GG了!

    下面给出AC代码:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 int main()
     5 {
     6     char a,b;
     7     cin>>a>>b;
     8     ll c;
     9     cin>>c;
    10     ll t=((ll)(a-b));
    11     if(abs(t)==2||abs(t)==24||abs(t)==0)
    12     {
    13         printf("undefined
    ");
    14     }
    15     else if(t==34||t==-32||t==-58||t==56)
    16     {
    17         if((c-3)%4==0)
    18             printf("cw
    ");
    19         else if((c-1)%4==0)
    20             printf("ccw
    ");
    21         else printf("undefined
    ");
    22     }
    23     else if(t==-34||t==32||t==58||t==-56)
    24     {
    25         if((c-3)%4==0)
    26             printf("ccw
    ");
    27         else if((c-1)%4==0)
    28             printf("cw
    ");
    29         else printf("undefined
    ");
    30     }
    31     return 0;
    32 }

    B. The Festive Evening

    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.

    There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.

    For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.

    Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

    Input

    Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26).

    In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

    Output

    Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.

    You can output each letter in arbitrary case (upper or lower).

    Examples
    Input
    5 1
    AABBB
    Output
    NO
    Input
    5 1
    ABABB
    Output
    YES
    Note

    In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.

    In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.

    题目链接:http://codeforces.com/contest/834/problem/B

    题目大意,输入一堆大写字母,每个字符从第一次出现到最后一次出现的这段时间内需要一个守卫, 问你在给定k给守卫的条件下,总需求会不会超过k个守卫。

    这是一道思维题, 只需要记录每个字母出现的第一次的位置,和最后一次的位置,求一次区间最大覆盖就行了,由于数据量很小, 可以直接暴力。

    下面给出AC代码:

     1 #include <bits/stdc++.h>
     2 typedef long long ll;
     3 using namespace std;
     4 inline int read()
     5 {
     6     int x=0,f=1;
     7     char ch=getchar();
     8     while(ch<'0'||ch>'9')
     9     {
    10         if(ch=='-')
    11             f=-1;
    12         ch=getchar();
    13     }
    14     while(ch>='0'&&ch<='9')
    15     {
    16         x=x*10+ch-'0';
    17         ch=getchar();
    18     }
    19     return x*f;
    20 }
    21 inline void write(int x)
    22 {
    23     if(x<0)
    24     {
    25         putchar('-');
    26         x=-x;
    27     }
    28     if(x>9)
    29         write(x/10);
    30     putchar(x%10+'0');
    31 }
    32 int n,k;
    33 char s[1000010];
    34 int cnt[155];
    35 int vis[155];
    36 int main()
    37 {
    38     cin>>n>>k;
    39     scanf("%s",s);
    40     for(int i=0;i<n;i++)
    41         cnt[s[i]]++;
    42     for(int i=0;i<n;i++)
    43     {
    44         if(vis[s[i]]==0)
    45         {
    46             if(k==0)
    47             {
    48                 cout<<"YES"<<endl;
    49                 return 0;
    50             }
    51             k--;
    52             vis[s[i]]=1;
    53         }
    54         cnt[s[i]]--;
    55         if(cnt[s[i]]==0)
    56            k++;
    57     }
    58     cout<<"NO"<<endl;
    59     return 0;
    60 }

    C. The Meaningless Game

    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.

    The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.

    Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.

    Input

    In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

    Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

    Output

    For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.

    You can output each letter in arbitrary case (upper or lower).

    Example
    Input
    6
    2 4
    75 45
    8 8
    16 16
    247 994
    1000000000 1000000
    Output
    Yes
    Yes
    Yes
    No
    No
    Yes
    Note

    First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.

    The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.

    题目链接:http://codeforces.com/contest/834/problem/C

    题目大意

    两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样一组得分。(谁扩大k倍, 谁扩大k的平方倍,是可以自由选择的, k的值只要是自然数就行了)。
    题目做法: 对输入的两个数a, b。求(a*b) 的1/3次方, 如果不能得到,就是不能得的输出“No”。否则在看开方得到的数,能不能同时被a和b整除, 如果可以就输出“Yes”,否则就是“No”。

    分析:

    大神是这样做的

    不过我是二分求解的,方法思路也差不多,就不再赘述了,注意读入优化即可!

    跑的还是挺快的:

    下面给出AC代码:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 inline ll read()
     5 {
     6     ll x=0,f=1;
     7     char ch=getchar();
     8     while(ch<'0'||ch>'9')
     9     {
    10         if(ch=='-')
    11             f=-1;
    12         ch=getchar();
    13     }
    14     while(ch>='0'&&ch<='9')
    15     {
    16         x=x*10+ch-'0';
    17         ch=getchar();
    18     }
    19     return x*f;
    20 }
    21 inline void write(int x)
    22 {
    23     if(x<0)
    24     {
    25         putchar('-');
    26         x=-x;
    27     }
    28     if(x>9)
    29         write(x/10);
    30     putchar(x%10+'0');
    31 }
    32 ll a,b;
    33 ll gcd(ll x)
    34 {
    35     ll l=1,r=1000000;
    36     while(l<r)
    37     {
    38         ll mid=(l+r+1)/2;
    39         if(mid*mid*mid<=x)
    40             l=mid;
    41         else r=mid-1;
    42     }
    43     return l;
    44 }
    45 ll solve()
    46 {
    47     ll ab1=a*b;
    48     ll ab2=gcd(ab1);
    49     if(ab2*ab2*ab2!=ab1)
    50         return 0;
    51     if(a%ab2==0&&b%ab2==0)
    52         return 1;
    53     return 0;
    54 }
    55 int main()
    56 {
    57     ll n;
    58     scanf("%lld",&n);
    59     while(n--)
    60     {
    61         //ll a,b;
    62         a=read();
    63         b=read();
    64         gcd(a);
    65         if(solve()==1)
    66             printf("Yes
    ");
    67         else printf("No
    ");
    68     }
    69     return 0;
    70 }

     官方题解:

     1 #include <cmath>
     2 #include <cstdio>
     3 
     4 bool solve(long long a, long long b)
     5 {
     6     long long r = pow(a * b, 1. / 3.) + 1;
     7     while (r * r * r > a * b) {
     8         r --;
     9     }
    10     return r * r * r == a * b && a % r == 0 && b % r == 0;
    11 }
    12 
    13 int main()
    14 {
    15     int T;
    16     scanf("%d", &T);
    17     while (T --) {
    18         int a, b;
    19         scanf("%d%d", &a, &b);
    20         puts(solve(a, b) ? "Yes" : "No");
    21     }
    22 }
  • 相关阅读:
    Daily Scrum 11.20
    Daily Scrum 11.19
    Daily Scrum 11.18
    Daily Scrum 11.17
    Daily Scrum 11.16
    Daily Scrum 11.15
    Loj10222佳佳的 Fibonacci
    CH3801Rainbow的信号
    js仓库。。。
    【UVa1635】Irrelevant Elements
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/7261249.html
Copyright © 2020-2023  润新知