Codeforces Round #426 (Div. 2) A. The Useless Toy
A. The Useless Toytime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThere 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.
OutputOutput cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
Examplesinput^ >
1outputcwinput< ^
3outputccwinput^ v
6outputundefined
题目大意:判断第二个字符是不是第一个字符通过n步逆时针或顺时针得到,如果得不到准确的答案,输出undefined。
思路:模拟。取n%4的值,如果为0或2输出undefined,因为这个时候如果答案对,那么我们分不出顺逆。答案不对更是undefined。
这样只要处理余数为1,3 的情况了。
AC代码如下:
1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 char x[]={'v','<','^','>'};
5 char x2[]={'v','>','^','<'};
6 int main()
7 {
8 char a,c;
9 int n;
10 cin>>a>>c;
11 scanf("%d",&n);
12 if(n%4==2||n%4==0){
13 printf("undefined\n");
14 }else{
15 int now,nxt=n;
16 bool flag=false;
17 for(int i=0;i<4;i++){
18 if(x[i]==a){
19 now=i;
20 break;
21 }
22 }
23 for(int i=now;;i++){
24 i=i%4;
25 if(i==(nxt+now)%4){
26 if(x[i]==c)
27 flag=true;
28 break;
29 }
30 }
31 if(flag){
32 cout<<"cw"<<endl;
33 return 0;
34 }else{
35 for(int i=0;i<4;i++){
36 if(x2[i]==a){
37 now=i;
38 break;
39 }
40 }
41 for(int i=now;;i++){
42 i=i%4;
43 if(i==(nxt+now)%4){
44 if(x2[i]==c)
45 flag=true;
46 break;
47 }
48 }
49 }
50 if(flag){
51 cout<<"ccw"<<endl;
52 return 0;
53 }else{
54 cout<<"undefined"<<endl;
55 return 0;
56 }
57 }
58 return 0;
59 }
Codeforces Round #426 (Div. 2) A. The Useless Toy的更多相关文章
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy 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)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #426 (Div. 2) A,B,C
A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...
- Codeforces Round #426 (Div. 2)A题&&B题&&C题
A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...
- 【Codeforces Round #426 (Div. 2) A】The Useless Toy
[Link]:http://codeforces.com/contest/834/problem/A [Description] [Solution] 开个大小为4的常量字符数组; +n然后余4,-n ...
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...
- 【Codeforces Round #426 (Div. 2) B】The Festive Evening
[Link]:http://codeforces.com/contest/834/problem/B [Description] [Solution] 模拟水题; 注意一个字母单个出现的时候,结束和开 ...
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
[Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...
随机推荐
- Leetcode刷题笔记——单调性
单调性 单调性是数学中使用的一种常见性质,通常用于描述函数,在高等数学中的定义常常为: 设函数f(x)在区间I上有定义,如果对于I上的任意两个数x1和x2,当x1<x2时,有f(x1)<f ...
- stencilJs学习之构建 Drawer 组件
前言 在之前的学习中,我们已经掌握了 stencilJs 中的一些核心概念和基础知识,如装饰器 Prop.State.Event.Listen.Method.Component 以及生命周期方法.这些 ...
- HDFS核心概念与架构
HDFS简介 HDFS是Hadoop项目的核心子项目,在大数据开发中通过分布式计算对海量数据进行存储与管理,它基于流数据模式访问和处理超大文件的需求而开发,可以运行在廉价的商用服务器上,为海量数据提供 ...
- @Async注解详解 以及 可能遇到的各种问题
一.简介1)在方法上使用该@Async注解,申明该方法是一个异步任务:2)在类上面使用该@Async注解,申明该类中的所有方法都是异步任务:3)方法上一旦标记了这个@Async注解,当其它线程调用这个 ...
- ssr服务器极致渲染
域名 RDS 云服务器 ECS 中国站 文档购物车ICP备案控制台 金秋上云季 首页 技术与产品 社区 直播 开发者学堂 开发者云 工具与资源中心 天池大赛 飞 ...
- jmeter的全局变量(将登陆token设置全局)
1.首先调用登陆接口,用json提取器,取出响应内的token值 2.在beanshell取样器中设置全局变量 //设置全局变量方法一:用函数__setProperty设置${__setProper ...
- 10. 用Rust手把手编写一个wmproxy(代理,内网穿透等), HTTP内网穿透支持修改头信息
用Rust手把手编写一个wmproxy(代理,内网穿透等), HTTP内网穿透支持修改头信息 项目 ++wmproxy++ gite: https://gitee.com/tickbh/wmproxy ...
- 【matplotlib 实战】--百分比柱状图
百分比堆叠式柱状图是一种特殊的柱状图,它的每根柱子是等长的,总额为100%.柱子内部被分割为多个部分,高度由该部分占总体的百分比决定. 百分比堆叠式柱状图不显示数据的"绝对数值", ...
- Istio 入门(六):版本控制
目录 VirtualService 和 DestinationRule VirtualService 与 Service 的关系 VirtualService 和 DestinationRule 的关 ...
- "科来杯"第十届山东省大学生网络安全技能大赛决赛复现WP
从朋友那里得来的附件,感觉题目有意思,简单复现一下 MISC 简单编码 1.题目信息 0122 061 1101011 0172 0122 0105 061 1011010 0127 0154 014 ...
