Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
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.
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 cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
^ >
1
cw
< ^
3
ccw
^ v
6
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

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.
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 «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).
5 1
AABBB
NO
5 1
ABABB
YES
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

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.
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.
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).
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
Yes
Yes
Yes
No
No
Yes
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,二分+数学】的更多相关文章
- Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)
D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- 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 ...
- 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 ...
- Codeforces Round #426 (Div. 2)
http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #426 (Div. 2) - A
题目链接:http://codeforces.com/contest/834/problem/A 题意:给定4个图标,某些图标经过顺时针/逆时针旋转90°后能得到另外一些图标.现在给你开始的图标和结束 ...
- 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 ...
随机推荐
- springboot 入门七-静态资源处理
Spring Boot 默认配置的/**映射到/static(或/public ,/META-INF/resources),/webjars/**会映射到classpath:/META-INF/res ...
- iOS 讯飞语音测试没问题,一上线就用不了了
看一下打包的版本是不是release, Debug : 调试版本,主要是让程序员使用,在调试的过程中调用 Debug 会启动更多的服务来监控错误,运行速度相对较慢,而且比较耗能. Release : ...
- MQ NameServer模块划分
上图是之前讨论确定的系统架构(后续内容会按照这个架构来叙述),其中: NameServer做Broker的服务发现,即客户端可以通过NameServer拿到Broker的信息 Broker汇报数据到N ...
- js获取字符串最后一位方法
方法一:运用String对象下的charAt方法 charAt() 方法可返回指定位置的字符. str.charAt(str.length – 1) 请注意,JavaScript 并没有一种有别于字符 ...
- Struts2-整理笔记(四)Action生命周期、如何获取参数(3种)、集合类型参数封装
一.Action生命周期 每次请求到来时,都会创建一个新的Action实例 Action是线程安全的,可以使用成员变量接收参数 二.获取参数的方式(3种) 1.属性驱动获得参数 每次请求Action时 ...
- Error in library(DESeq2) : 不存在叫‘DESeq2’这个名字的程辑包
Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type&quo ...
- spring的基本使用
Spring的基本使用ioc,今天主要给大家说明了解决强耦合的联系,并且,注入的基本使用 Java里面的强耦合并且讲了spring是如何解决强耦合的第一种方式使用工厂模式,用的是反射,第二种方式是sp ...
- SpringMvc开发步骤
1.导入基本jar包 2.在Web.xml中配置DispatcherServlet <!-- 配置 DispatcherServlet --> <servlet> <se ...
- 对比Tornado和Twisted两种异步Python框架
做Python的人,一定知道两个性能优秀的异步网络框架:tornado,和twisted. 那么,这两个著名的框架,又有什么异同呢?tornado和twisted,我都用在几个游戏项目中,做过后端,觉 ...
- 纯CSS二级纵向菜单
纯CSS二级纵向菜单 <body> <div class="divda"> <div class="nav"> <ul ...