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. Docker(二):Docker镜像使用

    1.Docker Image介绍 简单来说,Docker Image是用来启动容器的只读模板. Docker Image被划分了三个部分:Remote-dockerhub.com/namespace/ ...

  2. rabbitmq 启动报错

    =============================================== 2017/10/24_第1次修改                       ccb_warlock = ...

  3. Python中range()和len()

  4. 关于oracle数据库 跨表查询建立 视图的方法

    工作中很多时候都会遇到需要将两个不同的表空间甚至数据库的表进行联合查询或者建立视图的情况. 不同的表空间查询我们可以通过在将要查询的表前面加上 表空间的对应的用户名来实现,如有两个表空间分别对应两个用 ...

  5. Nginx编译配置介绍

    源码包 nginx-1.6.2.tar.gz --help 使用帮助 --prefix=PATH Nginx安装路径,如果没有指定,默认为/usr/local/nginx. --sbin-path=P ...

  6. (class file version 53.0), Java Runtime versions up to 52.0错误的解决方法

    遇到这个错误是在Apache Tomcat上部署应用程序的时候遇到的,具体的错误描述是: java.lang.UnsupportedClassVersionError: HelloWorld has ...

  7. Netty入门之客户端与服务端通信(二)

    Netty入门之客户端与服务端通信(二) 一.简介 在上一篇博文中笔者写了关于Netty入门级的Hello World程序.书接上回,本博文是关于客户端与服务端的通信,感觉也没什么好说的了,直接上代码 ...

  8. golang 栈操作

    Monk's Love for Food   Our monk loves food. Hence,he took up position of a manager at Sagar,a restau ...

  9. JavaMail开发教程01开山篇

    序 其实想写JavaMail这一系列的博客已经有一个月之久了,缘起是某次乱逛传智播客官网浏览到相关的视频教程,想起大学时代学过的计算机网络提到邮件相关的协议,但遗憾的是到目前为止还没有接触计算机网络编 ...

  10. NUnit实战,第一个测试类,测试事件触发是否是并行的

    以前测试都是新建一个控制台测试的方式来进行,感觉版本管理啥的非常麻烦.也是非常原始的办法.后来想以前有写过测试单元,不过好久没弄了.Nuget了NUnit后写了正式的第一个测试类. 测试用例: 测试事 ...