ACM水题堆(一)T-switch game
2018-02-14 21:36
246 查看
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 ).InputEach test case contains only a number n ( 0< n<= 10^5) in a line.OutputOutput the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).Sample Input
1 5Sample Output
1 0 Consider the second test case: The 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.
这个题目主要是在题目意思的理解,输入一个数i,执行到第I个步骤,每i个步骤的将十五个1中的第I和I的倍数位的数变为上一步操作相反的状态,再输出第I个状态的数字,找规律就可以了#include<iostream>#include<cmath>using namespace std;int main(){ int n; while (scanf("%d", &n) != EOF) { //int con[16] = { 1 }; int i=sqrt(n); if (pow(i, 2) == n) { cout << 1 << endl; } else { cout << 0 << endl; } } return 0;}
相关文章推荐
- acm-UVA494(水题)
- acm-uva490(水题)
- ACM-水题 Lunch Time
- ACMSTEP 1.2.4 ecimal System //水题 模拟 活用Sprintf和sscanf
- 华东交通大学2014年ACM“双基”程序设计竞赛(部分水题)
- ACM水题系列 HDOJ2093
- ACM水题-数据选取(AC解题报告)
- acm水题
- acm-UVa414(水题)
- ACM-水题 May Day Holiday
- ACM水题堆(三)M-分拆素数和(超时与解决办法)
- ACM——Tutor(水题一枚)
- [ACM] hdu 2025查找最大元素(水题)
- acm Alyona and copybooks 新人水题
- hdu 5053 the Sum of Cube 水题 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5443 The Water Problem 水题 2015 ACM/ICPC Asia Regional Changchun Online
- 1175: ACM"水题"
- 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest A】【水题 讨论】Alex Origami Squares 矩形内置三个最大正方形
- ACM水题-Rescue LK(AC,迷宫问题,DFS求解)
- ACM水题-Beautiful Sequence(AC,杂题,贪心思想?)