【CodeForces - 834】 A【模拟】 B【模拟】C【思维】

26 篇文章 0 订阅
25 篇文章 1 订阅

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 undefined otherwise.

Example
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined
题意 : 给两个尖角号,和旋转的次数,如果可顺时针转到输出cw,逆时针转到输出cww,都可以转到undefined。
代码

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define first fi
#define second se
#define  LL long long
#define fread() freopen("in.txt","r",stdin)
#define fwrite() freopen("out.txt","w",stdout)
#define CLOSE() ios_base::sync_with_stdio(false)

const int MAXN = 1e5;
const int MAXM = 1e6;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;

char arr[5]={'^','>','v','<'};
char brr[5]={'<','v','>','^'};

int main(){
    CLOSE();
//  fread();
//  fwrite();
    map<char,int>mp;
    mp['^']= 0; mp['>']=1; mp['v']=2; mp['<']=3;
    map<char ,int >mpp;
    mpp['^']= 3; mpp['>']=2; mpp['v']=1; mpp['<']=0;

    char s[5]; scanf("%c %c",&s[0],&s[1]);  int n;scanf("%d",&n);
    int a=0,b=0;
    char ch=arr[(n+mp[s[0]])%4]; if(mp[ch]==mp[s[1]]) a=1;
    ch=brr[(n+mpp[s[0]])%4]; if(mpp[ch]==mpp[s[1]]) b=1;
    //printf("%d\n",(n+mpp[s[0]])%4); 
    if(a&&b) puts("undefined");
    else if(a) puts("cw");
    else puts("ccw");
    return 0;
}

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… 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).

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

懒的写题意了。
代码

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define first fi
#define second se
#define  LL long long
#define fread() freopen("in.txt","r",stdin)
#define fwrite() freopen("out.txt","w",stdout)
#define CLOSE() ios_base::sync_with_stdio(false)

const int MAXN = 1e6+11;
const int MAXM = 1e6;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;

char s[MAXN];
map<char,int>mp;
map<char ,int>vis;
int main(){
    CLOSE();
//  fread();
//  fwrite();
    int n,k;cin>>n>>k; cin>>s;
    for(int i=0;s[i];i++){
        mp[s[i]]++;
    }
    int cnt=0;int ans=0;
    for(int i=0;s[i];i++){
        if(!vis[s[i]]) {
            cnt++;ans=max(ans,cnt);
            vis[s[i]]=1;
            mp[s[i]]--;
            if(mp[s[i]]==0) cnt--;
        }else{
            mp[s[i]]--;
            if(mp[s[i]]==0) cnt--;
        }
    }
    //printf("%d\n",ans); 
    if(ans>k) puts("YES");
    else puts("NO");
    return 0;
}

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

题目大意:

现在有两个人玩游戏,一开始两个人的分数都是1,每一轮游戏两个人会共同挑选一个数K,游戏获得胜利的选手将自己的分数*k^2,输了的选手将自己的分数*k.
现在有n个查询,每个查询表示两个人最终的分数,问是否有一种游戏过程,使得这个最终分数是可能出现的。

好强的思维题,没想到乘起来的规律,真菜。对于每次的round,有一个数乘k,另一个数乘k*k,这样,a*b就增加了k*k*k
所以我们只要判断a*b是否为一个数字的立方,同时还可以被a和b整除.因为那个数字一定是a和b的因子
代码

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define first fi
#define second se
#define  LL long long
#define fread() freopen("in.txt","r",stdin)
#define fwrite() freopen("out.txt","w",stdout)
#define CLOSE() ios_base::sync_with_stdio(false)

const int MAXN = 1e5;
const int MAXM = 1e6;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;

int main(){
    CLOSE();
//  fread();
//  fwrite();
    int n;cin>>n;
    while(n--){
        LL a,b,c;
        cin>>a>>b;
        c=(LL)round(pow((double)a*b,1.0/3));//round 四舍五入
        if(c*c*c==a*b&&a%c==0&&b%c==0) puts("Yes");
        else puts("No");
    } 
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值