zoukankan      html  css  js  c++  java
  • 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
     
    题意:一种玩具有四种形态: "v", "<", "^", ">",可依次通过旋转90°得到, 给一个初始形态、最终形态和时间,询问是否能在给定时间从初始形态转到最终形态,并且是顺时针(输出"cw")还是逆时针(输出"ccw")。PS:若顺时针和逆时针所需时间一样,则也为undefined。
    题解:很简单的题目,只要先确定好给定初始形态转动一周时的中间形态,再判断n % 4或者4 - n % 4相对应的结果是否为最终形态即可:设转动中的四种形态为a[0](初始形态), a[1](顺时针旋转90°), a[2](顺时针旋转180°), a[3](顺时针旋转270°),若a[n % 4]为最终形态且a[4 - n % 4]不是最终形态,则为顺时针,若a[4 - n % 4]为最终形态且a[n % 4]不是最终形态,则为逆时针,否则undefined。
    PS:该题有一个叉点,若初始形态和最终形态一样,那也是“undefined”,需要特判。(由于这个没有特判,我被hack点卡了5次QAQ)
    附上代码:
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int main()
    {
        char ch1,ch2;
        int n;
        char a[4];
        int i;
        cin >> ch1 >> ch2;
        cin >> n;
        if (ch1 == '^')
        {
            a[0] = '^';
            a[1] = '>';
            a[2] = 'v';
            a[3] = '<';
        }
        else
        if (ch1 == '>')
        {
            a[3] = '^';
            a[0] = '>';
            a[1] = 'v';
            a[2] = '<';
        }
        else
        if (ch1 == 'v')
        {
            a[2] = '^';
            a[3] = '>';
            a[0] = 'v';
            a[1] = '<';
        }
        else
        if (ch1 == '<')
        {
            a[1] = '^';
            a[2] = '>';
            a[3] = 'v';
            a[0] = '<';
        }
        int temp = n % 4;
        if (ch1 == ch2) printf("undefined
    ");
        else 
        if ((a[temp] == ch2) && (a[4 - temp] != ch2))
        {
            printf("cw
    ");
        }
        else
        if ((a[temp] != ch2) && (a[4 - temp] == ch2))
        {
            printf("ccw
    ");
        }
        else
        printf("undefined
    ");
    }
    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.
    题意:一个城堡有26个入口以A到Z表示,每个入口的门在第一个通过这个入口的人来之前打开,在最后一个通过这个入口的人通过之后关闭。求是否有一个时刻超过k个门被打开
    题解:记录下每个入口出现的次数,再按照入口分配守卫即可:出现新的入口没有被访问,则分配一个守卫,若守卫被分配完毕,则说明有这样一个时刻,有超过k个入口被打开。若这个入口之后没有人经过了,则还原一个守卫的位置。暴力即可。
     
    #include<iostream>
    #include
    <cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int n,k,i,j; char str[1000050]; int a[150]; bool vis[150]; bool f = false; scanf("%d%d",&n,&k); scanf("%s",str); memset(a,0,sizeof(a)); memset(vis,0,sizeof(vis)); for (i = 0;i < n;i++) a[str[i]]++; for (i = 0;i < n;i++) { if (!vis[str[i]]) { if (!k) { f = true; break; } k--; vis[str[i]] = true; } a[str[i]]--; if (!a[str[i]]) k++; } if (f) printf("YES "); else printf("NO "); }
    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 ab (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.
    题意:两人开始游戏,每人的初始分数均为1,在每轮游戏中,赢家的分数乘以k2,输家的分数乘以k(k为任意正整数),给出每次游戏的最终得分,询问这样的得分是否符合游戏结果。
    题解:我们可以拆分分数,可以发现符合要求的分数a和b的乘积的立方根是可以被a和b整除的,因此我们只要求出a * b的立方根并取整得到结果为x,判断x是否被a和b整除即可
    #include<iostream>
    #include
    <cmath> #include<cstdio> #include<cstring> using namespace std; int main() { int n,i; long long a,b; scanf("%d",&n); for (i = 0;i < n;i++) { scanf("%lld%lld",&a,&b); long long x = pow(a * b,1.0 / 3); long long p = a * b; while (x * x * x < p) x++; if ((a % x == 0) && (b % x == 0)) printf("Yes "); else printf("No "); } }

    注意:在求立方根时注意精度,即x = pow(a * b,1.0 / 3)

     

  • 相关阅读:
    node.js开发 打包管理工具webpack
    node.js开发 npm包管理工具 npm 和 cnpm区别
    node.js开发 npm包管理工具
    node.js开发 1-概述
    脚手架-1概念
    前端开发 vue,angular,react框架对比2
    AttachDispatch
    画图软件orign的使用
    建立xml文件时遇到的编码问题和解决方法
    securecrt简介
  • 原文地址:https://www.cnblogs.com/Suwako1997/p/7261687.html
Copyright © 2011-2022 走看看