Codeforces Beta Round #51 A. Flea travel 水题
2015-11-23 13:41
190 查看
A. Flea travel
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/55/problem/ADescription
A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping.Input
The only line contains single integer: 1 ≤ n ≤ 1000 — number of hassocks.
Output
Output "YES" if all the hassocks will be visited and "NO" otherwise.
Sample Input
1
Sample Output
YES
HINT
题意有一个环,有n个位置
一开始你在0,然后往前跳,第一次跳n-1,第二次跳n-2,第三次跳n-3.....直到跳到不能跳为止
问你是否能够遍历所有的位置
题解:
数据范围只有1000,直接暴力就好了
代码:
#include<iostream> #include<stdio.h> using namespace std; int p[1005]; int main() { int n;scanf("%d",&n); p[0]=1; int ans = 1; int tmp = 0; for(int i=n-1;i>0;i--) { tmp = (tmp + i)%n; if(p[tmp]==0) { p[tmp]=1; ans++; } } if(ans==n)printf("YES\n"); else printf("NO\n"); }
相关文章推荐
- PADS从原理图到PCB整体简易流程
- textarea内容换行存入数据库解决方案
- android获取屏幕宽高与获取控件宽高 方法总结
- Iterator和ListIterator的不同使用方法
- JS封装类或对象的最佳方案
- photoshop将多个图片合成制作gif
- zTree初始化 节点添加自定义属性
- 数据库导入数据时,数据量很大导致报错问题
- Android性能优化之使用线程池处理异步任务
- vs2015编译boost 64位
- 项目及人员管理
- angularJS学习之路(十一)---ng-show和ng-hide
- 用数组实现队列(C实现)
- 改变导航的返回按钮
- 在ubuntu中映射远端开发机(redhat命令行版)到本地
- plsql中文乱码,显示问号
- iOS 使用模拟器的时候快速切换网络的指令
- poj 1734 Sightseeing trip (floyd求最小环并记录路径)
- IOS导航栏颜色渐变与常用属性
- 布局-同样模块复用