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

    Codeforces Round #426 (Div. 2)

    A. The Useless Toy

    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 undefinedotherwise.

    Examples

    input

    ^ >
    1

    output

    cw

    input

    < ^
    3

    output

    ccw

    input

    ^ v
    6

    output

    undefined

    题意:一个符号,循环出现,给出初始状态,和结束状态,求是顺时针还是逆时针。

    分析:顺时针很好判断:pos1 + t % 4 到结束状态,逆时针就麻烦了,考虑初始和结束的位置关系,循环等等,分情况也行,更好的方式是,调换初始和结束状态,结束状态顺时针到开始状态,则是逆时针。当然常规思维,pos1 - t % 4,可能出现负数,负数没有关系 + 4 %4 。

    #include <bits/stdc++.h>
    using namespace std;
    char str[5] = "v<^>";
    ​
    int main(int argc, char const *argv[]) {
    ​
        char c1,c2;
        int t;
        scanf("%c %c%d",&c1,&c2,&t);
    ​
        int pos1 = -1;
        for(int i=0; i < 4; i++)
            if(c1==str[i]) {
                pos1 = i;
                break;
            }
    ​
        int pos2 = -1;
        for(int i=0; i < 4; i++) {
            if(c2==str[i]) {
                pos2 = i;
                break;
            }
        }
    ​
        if((pos1+t)%4==pos2&&((pos1-t)%4+4)%4==pos2)
            puts("undefined");
        else if((pos1+t)%4==pos2)
            puts("cw");
        else puts("ccw");
    ​
        return 0;
    }

    B. The Festive Evening

    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... s**n are given, where s**i 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.

    题意:有一些客人进门,每个门都是从一个开始到最后必须有一个守卫。守卫少了输出YES。

    分析:原题,求出每个门的开始位置,和结束位置,就是一个区间,类似于资源调度。

    #include <bits/stdc++.h>
    ​
    using namespace std;
    ​
    const int maxn = 1e6+5;
    ​
    char str[maxn];
    ​
    vector<pair<int,int> > v;
    set<char> s;
    ​
    struct Node{
        int l,r;
        bool flag;
    }nodes[30];
    ​
    int main(int argc, char const *argv[]) {
    ​
        int n,k;
        scanf("%d%d",&n,&k);
        scanf("%s",str);
    ​
    ​
        for(int i=0; i < n; i++) {
            if(s.count(str[i])==0) {
               nodes[str[i]-'A'].l = i;
               nodes[str[i]-'A'].r = i;
               nodes[str[i]-'A'].flag = true;
               s.insert(str[i]);
            }
            else {
                nodes[str[i]-'A'].r = max(nodes[str[i]-'A'].r,i);
            }
        }
    ​
    ​
        for(int i=0; i < 26; i++) {
            if(nodes[i].flag) {
                //printf("%c %d %d
    ",i+'A',nodes[i].l,nodes[i].r);
                v.push_back(make_pair(nodes[i].l,1));
                v.push_back(make_pair(nodes[i].r+1,-1));
            }
        }
    ​
        sort(v.begin(),v.end());
    ​
        bool flag = true;
        int ans = 0;
        for(int i=0; i < (int)v.size(); i++) {
            ans+=v[i].second;
            if(ans>k)
            {
                printf("YES
    ");
                flag = false;
                break;
            }
        }
        if(flag)
            puts("NO");
    ​
        return 0;
    }

    C. The Meaningless Game

    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.

    题意:每个案例中有很多回合,每个回合初始两个人积分为1,然后任意选一个数k,赢者积分累成k^2,输者积分累成k,求最后积分是否有可能。

    分析:两个人的积分相乘就一定是一个k^3,二分判断这个数。

    #include <bits/stdc++.h>
    using namespace std;
    long long a,b;
    typedef long long ll;
    const int maxn = 1e6+10;
    ​
    int main(int argc, char const *argv[]) {
    ​
        int n;
        scanf("%d",&n);
        while(n--) {
            scanf("%I64d%I64d",&a,&b);
            ll ans = a*b;
            int l = 0,r=maxn;
            ll sum;
            while(l<=r) {
                ll mid = (l+r)/2;
                if(mid*mid*mid>=ans) {
                    sum = mid;
                    r = mid - 1;
                }
                else l = mid+1;
            }
    ​
            if(sum*sum*sum==ans&&a%sum==0&&b%sum==0)
                puts("Yes");
            else puts("No");
        }
    ​
        return 0;
    }

    总体来说,状态不好,第一题无限WA卡了很久,第二题秒过了,第三题,没思路。弱的不行!!!

  • 相关阅读:
    js定位光标到输入框指定位置
    JS获取本机时间和实时动态时间代码
    一个小游戏
    select optionschange oeder
    js控制下拉列表框
    glow滤镜的使用
    body.innerHTML
    怎样用C语言编写病毒(三)
    2011东北地区赛G题(二分网络流判可行性)
    Codeforces Round #122 (Div. 1)>TLE代码 跪求(n^2)的最小割顶集算法(StoerWagner)
  • 原文地址:https://www.cnblogs.com/TreeDream/p/7434869.html
Copyright © 2011-2022 走看看