poj 3372(找规律)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6033 | Accepted: 3351 |
Description
N children standing in circle who are numbered 1 through N clockwise are waiting their candies. Their teacher distributes the candies by in the following way:
First the teacher gives child No.1 and No.2 a candy each. Then he walks clockwise along the circle, skipping one child (child No.3) and giving the next one (child No.4) a candy. And then he goes on his walk, skipping two children (child No.5 and No.6) and giving the next one (child No.7) a candy. And so on.
Now you have to tell the teacher whether all the children will get at least one candy?
Input
The input consists of several data sets, each containing a positive integer N (2 ≤ N ≤ 1,000,000,000).
Output
For each data set the output should be either "YES" or "NO".
Sample Input
2
3
4
Sample Output
YES
NO
YES 老师给糖给 1 2号学生,然后接下来隔着一个学生给糖,隔着两个学生给糖,问一直这样下去,是否所有学生都会拿到糖? 找规律,判断 n是否为 2^k...快速判断 n是否为 2的指数幂的方法 n&n-1...
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL;
const int N = ; int main()
{
int n;
while(scanf("%d",&n)!=EOF){
if((n&(n-))==) printf("YES\n");
else printf("NO\n");
}
return ;
}
poj 3372(找规律)的更多相关文章
- POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律
http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律…… 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系, ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- 【poj 2478】Farey Sequence(数论--欧拉函数 找规律求前缀和)
题意:定义 Fn 序列表示一串 <1 的分数,分数为最简分数,且分母 ≤n .问该序列的个数.(2≤N≤10^6) 解法:先暴力找规律(代码见屏蔽处),发现 Fn 序列的个数就是 Φ(1)~Φ( ...
- poj 2440 (找递推公式)
http://poj.org/problem?id=2440 DNA Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3254 ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- POJ2992:Divisors(求N!因子的个数,乘性函数,分解n!的质因子(算是找规律))
题目链接:http://poj.org/problem?id=2992 题目要求:Your task in this problem is to determine the number of div ...
- POJ2505 A multiplication game 博弈论 找规律
http://poj.org/problem?id=2505 感觉博弈论只有找规律的印象已经在我心中埋下了种子... 题目大意:两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9 ...
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
随机推荐
- Linux系统时间函数
先来说说自己在做工程过程中的一些理解: 1, 输入time_t,输出tm格式的函数 loctaltime(time_t) / gmtime(time_t) 其中localtime会受时区和夏令时影响, ...
- linux tmux命令小结
http://note.youdao.com/noteshare?id=f1be507b4be27e53684b46a1424746b5
- SQL Server 2008定期的备份数据库--差异+完整
https://www.cnblogs.com/l1pe1/p/7885207.html https://www.cnblogs.com/tylerflyn/p/8051398.html https: ...
- SDOI2017 Round1 起点
第二次打酱油了 高一两次考试以打两瓶酱油告终 来的时候明知自己没戏,却总存有一丝希望 NOIP连200都没考到,是不是有点儿不自量力 如果我真的去争取那一丝希望的话,该有多好 先简单分析下考试 Day ...
- seaborn基础整理
seaborn是基于matplotlib的更高级的做图工具,下面主要针对以下几个部分进行整理: 第一部分:https://douzujun.github.io/page/%E6%95%B0%E6%8D ...
- 《C语言程序设计基础I》秋季学习总结
希望下学期比这学期轻松,学习能力上升,只是越发丰富. 一步一步的走踏实了
- sqlalchemy操作数据库(二)
sqlalchemy的基本操作 表结构如下: from sqlalchemy import create_enginefrom sqlalchemy.ext.declarative importdec ...
- node.js 基础篇
日志输出方式 node test.js 2>error.log 1>info.log 如果需要日志文件追加 node test.js 2>>error.log 1>> ...
- [转]编译防火墙——C++的Pimpl惯用法解析
impl(pointer to implementation, 指向实现的指针)是一种常用的,用来对“类的接口与实现”进行解耦的方法.这个技巧可以避免在头文件中暴露私有细节(见下图1),因此是促进AP ...
- JSON数据填充表格——(三)
1.定义页面请求JSON的按钮与定义一个带表头的表格 请求数据的按钮 <button class="btn btn-primary search_bar_button floatR& ...