Switch Game
来源:互联网 发布:找不到男朋友 知乎 编辑:程序博客网 时间:2024/06/02 07:04
Switch Game
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7593 Accepted Submission(s): 4490
转载自: http://blog.sina.com.cn/s/blog_ac5ed4f301019qj2.htmlProblem Description
There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).
Input
Each test case contains only a number n ( 0< n<= 10^5) in a line.
Output
Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).
Sample Input
1
5
Sample Output
1
0Consider the second test case:
Hint
hintThe initial condition : 0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.
这题思路:
一开始有n盏灯,且全部为关闭状态,都记为 0 就是 The initial condition : 0 0 0 0 0 …
然后之后进行i操作就是对这些灯以是否能被i整除,进行改变状态,如将 0 改为 1 或 将 1 改为 0
正如提醒里的
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
然后题目的输出是 第i次操作的第i个的状态,正如上面红色标记的
代码如下:
#include<stdio.h>
int count(int n)
{
}
int main()
{
}
这题还有规律:
我们把前10个写出来就知道了
1. 1 1 1 1 1 1 1 1 1 1 1 1 1
2. 1 0 1 0 1 0 1 0 1 0 1 0 1
3. 1 0 0 0 1 1 1 0 0 0 1 1 1
4. 1 0 0 1 1 1 1 1 0 0 1 0 1
5. 1 0 0 1 0 1 1 1 0 1 1 0 1
6. 1 0 0 1 0 0 1 1 0 1 1 1 1
7. 1 0 0 1 0 0 0 1 0 1 1 1 1
8. 1 0 0 1 0 0 0 0 0 1 1 1 1
9. 1 0 0 1 0 0 0 0 1 1 1 1 1
10. 1 0 0 1 0 0 0 0 1 0 1 1 1
从这里我们就可以规律了,就是除了 n*n 是 1 ,其余的都是 0
代码如下:
#include<stdio.h>
#include<string.h>
int main()
{
}
0 0
- Switch Game
- Switch Game
- Switch Game
- Switch game
- HDOJ 2053 Switch Game
- 2053 Switch Game
- HDOJ2053 Switch Game
- Hdu 2053 - Switch Game
- Switch Game + 枚举
- HDU 2053 Switch Game
- hdu 2053 Switch Game
- HDU_2053 Switch Game
- Switch Game 2053
- 2053 Switch Game
- HDUJ 2053 Switch Game
- hdu 2053 Switch Game
- HDU 2053 Switch Game
- hdu-2053-Switch Game
- java读取txt文件,获取行数
- 兔子--背景透明度设置
- 可编译易用的模块化nf-HiPAC移植成功
- 一个人的旅行(杭电oj2066)(Dijkstra算法)
- HashMap vs. TreeMap vs. Hashtable vs. LinkedHashMap
- Switch Game
- ZigZag - 2003 TCCC Semifinals 3
- NSPredicate的在查询中的简单使用
- 商派ECmall的支付接口初探(一)
- 正则表达式入门
- ios 内存管理,objective-c内存管理
- 曾做erp开发工程师,谈下自己的经验
- 不定参数函数实现
- POJ2389 BullMath_C语言