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. iOS wkwebview懒加载中遇到的问题

    这是我遇到的问题,也许是个例,就算狗血了点吧 需求: 当前界面(mainVC)响应点击事件,传值给webviewController(webVC)其中包含网址,此时如果在webVC中对wkwebvie ...

  2. 小白的Python之路 day4 生成器并行运算

    一.概述 我们已经明白生成器内部的结构,其实就是通过像函数这样的东西实现的! 多线程和单线程:简单来说多线程就是并行运算,单线程就是串行运算 二.生成器执行原理 第一步:生成一个生成器  第二步:执行 ...

  3. softmax分类算法原理(用python实现)

    逻辑回归神经网络实现手写数字识别 如果更习惯看Jupyter的形式,请戳Gitthub_逻辑回归softmax神经网络实现手写数字识别.ipynb 1 - 导入模块 import numpy as n ...

  4. Servlet与Jsp的结合使用实现信息管理系统一

    PS:1:先介绍一下什么是Servlet? Servlet(Server Applet)是Java Servlet的简称,称为小服务程序或服务连接器,用Java编写的服务器端程序,主要功能在于交互式地 ...

  5. UWP 应用通知Notifications

    之前说UWP 使用OneDrive云存储2.x api(二)[全网首发],微识别实现了上传下载的功能,那么为了给用户更上一层楼的体验,那就是在上传下载完成之后,弹出一通知Notifications. ...

  6. JavaUtil_06_DES加解密工具

    一.示例 CommonUtil.java package com.ray.test.des; import java.io.ByteArrayOutputStream; import java.io. ...

  7. lastIndex对正则结果的影响

    前言 今天遇到一个问题,用正则表达式去检查同一个字符串时,交替返回true和false.无奈之下,重新翻了翻权威指南,发现罪魁祸首原来是lastIndex.可在控制台尝试下 let reg = /[\ ...

  8. webpack3.x基本配置与总结

    基本配置 1.开始之前,请确定你已经安装了当前 Node 的较新版本. 2.然后在文件夹根目录下执行以下命令初始化项目并全局安装webpack: 1.$ cnpm init // 初始化项目 2.$ ...

  9. MSSQLSERVER并行度

    Microsoft SQL Server最大并行度(MAXDOP) 配置选项控制并行计划用于执行查询的处理器的数目.此选项确定用于执行工作并行查询计划运算符的计算和线程资源.根据是否 SQL Serv ...

  10. Struts2内部执行过程

    首先是Struts2的流程图. 一.当有一个请求的时候.执行以下流程. 1 客户端初始化一个指向Servlet容器的请求: 2 这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做Act ...