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,赢的人把自己 ...
随机推荐
- WPF学习 - 自定义Panel
WPF中的Panel(面板),是继承自FrameworkElement的抽象类,表示一个可以用来排列子元素的面板. 在WPF中,一种预设了几种常用的面板,如Grid.StackPanel.WrapPa ...
- HDFS核心概念与架构
HDFS简介 HDFS是Hadoop项目的核心子项目,在大数据开发中通过分布式计算对海量数据进行存储与管理,它基于流数据模式访问和处理超大文件的需求而开发,可以运行在廉价的商用服务器上,为海量数据提供 ...
- HTML视频背景(动态背景)
网页动态背景一般是用视频实现的,能增添网页的感染力,我觉得很好看,也不难,不妨学一下. 先加入下面一串代码: 1 <style> 2 video{ 3 height: 100%; 4 wi ...
- flutter的json转dart model问题
原文链接 原文链接 Preface 最近在做一个app,以后续用来找工作可以拿出来看看. 试试自己到产品设计能力,前后端能力等等. 中间遇到到一些有值得记录的点全部记录在此. Content json ...
- 算法打卡|Day2 数组part02
Day2 数组part02 今日任务:977.有序数组的平方 ,209.长度最小的子数组 ,59.螺旋矩阵II 目录 Day2 数组part02 今日任务:977.有序数组的平方 ,209.长度最小的 ...
- 记录一次gcc的编译
在deepin23上编译gcc13.2 deepin20素以软件版本过老被人诟病,换成最新的deepin23之后情况大有好转,但是gcc版本为11.2,鄙人对此仍有意见,所以特意研究了如何编译一份较新 ...
- 深入理解Python虚拟机:super超级魔法的背后原理
深入理解Python虚拟机:super超级魔法的背后原理 在本篇文章中,我们将深入探讨Python中的super类的使用和内部工作原理.super类作为Python虚拟机中强大的功能之一,super ...
- 我们又组织了一次欧洲最大开源社区活动,Hugging Face 博客欢迎社区成员发帖、Hugging Chat 功能更新!
每一周,我们的同事都会向社区的成员们发布一些关于 Hugging Face 相关的更新,包括我们的产品和平台更新.社区活动.学习资源和内容更新.开源库和模型更新等,我们将其称之为「Hugging Ne ...
- XCODE9.1的一些新问题
自从XCODE7苹果就允许用免费的开发者账号进行真机测试了,但是还是有很多限制的. 在用的过程中发现限制如下: 1.只能生成*.app文件,不能打包成ipa.官方这么说的,但是奇诡的是,我archiv ...
- 从零用VitePress搭建博客教程(5) - 如何自定义页面模板、给页面添加独有的className和使页面标题变成侧边目录?
接上一节:从零用VitePress搭建博客教程(4) – 如何自定义首页布局和主题样式修改? 上一节其实我们也简单说了自定义页面模板,这一节更加详细一点说明,开始之前我们要知道在vitePress中, ...
