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代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
char a,b;
cin>>a>>b;
ll c;
cin>>c;
ll t=((ll)(a-b));
if(abs(t)==||abs(t)==||abs(t)==)
{
printf("undefined\n");
}
else if(t==||t==-||t==-||t==)
{
if((c-)%==)
printf("cw\n");
else if((c-)%==)
printf("ccw\n");
else printf("undefined\n");
}
else if(t==-||t==||t==||t==-)
{
if((c-)%==)
printf("ccw\n");
else if((c-)%==)
printf("cw\n");
else printf("undefined\n");
}
return ;
}

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代码:

 #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x>)
write(x/);
putchar(x%+'');
}
int n,k;
char s[];
int cnt[];
int vis[];
int main()
{
cin>>n>>k;
scanf("%s",s);
for(int i=;i<n;i++)
cnt[s[i]]++;
for(int i=;i<n;i++)
{
if(vis[s[i]]==)
{
if(k==)
{
cout<<"YES"<<endl;
return ;
}
k--;
vis[s[i]]=;
}
cnt[s[i]]--;
if(cnt[s[i]]==)
k++;
}
cout<<"NO"<<endl;
return ;
}

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代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x>)
write(x/);
putchar(x%+'');
}
ll a,b;
ll gcd(ll x)
{
ll l=,r=;
while(l<r)
{
ll mid=(l+r+)/;
if(mid*mid*mid<=x)
l=mid;
else r=mid-;
}
return l;
}
ll solve()
{
ll ab1=a*b;
ll ab2=gcd(ab1);
if(ab2*ab2*ab2!=ab1)
return ;
if(a%ab2==&&b%ab2==)
return ;
return ;
}
int main()
{
ll n;
scanf("%lld",&n);
while(n--)
{
//ll a,b;
a=read();
b=read();
gcd(a);
if(solve()==)
printf("Yes\n");
else printf("No\n");
}
return ;
}

官方题解:

 #include <cmath>
#include <cstdio> bool solve(long long a, long long b)
{
long long r = pow(a * b, . / .) + ;
while (r * r * r > a * b) {
r --;
}
return r * r * r == a * b && a % r == && b % r == ;
} int main()
{
int T;
scanf("%d", &T);
while (T --) {
int a, b;
scanf("%d%d", &a, &b);
puts(solve(a, b) ? "Yes" : "No");
}
}

Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】的更多相关文章

  1. Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)

    D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...

  2. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  3. Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分

    题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...

  4. Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟

    A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

  6. Codeforces Round #426 (Div. 2) C. The Meaningless Game

    C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...

  7. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  8. Codeforces Round #426 (Div. 2) - A

    题目链接:http://codeforces.com/contest/834/problem/A 题意:给定4个图标,某些图标经过顺时针/逆时针旋转90°后能得到另外一些图标.现在给你开始的图标和结束 ...

  9. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. js验证input输入框(字母,数字,符号,中文)

    [javascript]代码库 <h1>js验证输入框内容</h1> <br /> <br /> 只能输入英文 <input type=" ...

  2. iView的使用【CDN向】

    直接粗暴地上html代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  3. ElasticSearch 学习记录之如任何设计可扩容的索引结构

    扩容设计 扩容的单元 一个分片即一个 Lucene 索引 ,一个 Elasticsearch 索引即一系列分片的集合 一个分片即为 扩容的单元 . 一个最小的索引拥有一个分片. 一个只有一个分片的索引 ...

  4. Java解析word,获取文档中图片位置

    前言(背景介绍): Apache POI是Apache基金会下一个开源的项目,用来处理office系列的文档,能够创建和解析word.excel.ppt格式的文档. 其中对word文档的处理有两个技术 ...

  5. Python连接webstocker获取消息

    简介(脚本都是根据网上资料改写) 此脚本主要是客户觉得webstcket不稳定,所以编辑一个脚本,不停的请求web服务器,当发生错误时,脚本自动退出(). 脚本内容 脚本一 # -*- coding: ...

  6. String 转化成java.sql.Date和java.sql.Time

    String类型转换成java.sql.Date类型不能直接进行转换,首先要将String转换成java.util.Date,在转化成java.sql.Date 请点击--->   java架构 ...

  7. Qt数据库集成应用封装

    平时的大大小小的项目中,基本上都需要与数据库打交道,会遇到各种各样的应用场景,本人主要遇到四种场景1:数据库自动重连,例如mysql数据库中经常遇到服务器挂掉的情况,需要自动检测并重新连接数据库.2: ...

  8. struts快速入门第一篇 —— struts相关XML配置映射及讲解

    我们回忆一下在学习JavaWeb过程中(Jsp + servlet编程)所感受到的Servlet的不足: 1 Servllet很多时,web.xml中的代码会很多.这样一来,维护起来就不方便,不利于团 ...

  9. Python 项目实践三(Web应用程序)第五篇

    接着上节继续学习,在这一节,我们将建立一个用户注册和身份验证系统,让用户能够注册账户,进而登录和注销.我们将创建一个新的应用程序,其中包含与处理用户账户相关的所有功能.我们还将对模型Topic稍做修改 ...

  10. 树链剖分( 洛谷P3384 )

    我们有时候遇到这样一类题目,让我们维护树上路径的某些信息,这个时候发现我们无法用线段树或者树状数组来维护这些信息,那么我们就有着一种新的数据结构,树剖:将一棵树划分成若干条链,用数据结构去维护每条链, ...