HDU 2053 Switch Game(开灯问题,完全平方数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2053

题目大意:灯开始是关着的,有n盏灯,i从1数到n每当灯的序号是i的倍数的时候就对灯进行一次操作(开->关,关->开),求最后第n盏灯是关着还是开着。

解题思路:直接对第n盏灯模拟也可以,但是有规律更好不是吗~。其实就是判断n的约束奇偶性,奇数就开着,偶数就关着。

     当一个数不是完全平方数:如18约数为:(3,6),(2,19),(1,15)约数个数总会是偶数,因为每个约数都有一个对应的不同的约数。

     当他是完全平方数:如36约数为:(1,36),(2,18),(3,12),(4,9),6 约数个数总是奇数,因为约数sqrt(n)对应的约数是相同的。

代码:

 1 #include<cstdio>
 2 #include<cmath>
 3 using namespace std;
 4
 5 int main(){
 6     int n;
 7     while(~scanf("%d",&n)){
 8         int b=sqrt(n*1.0);
 9         if(b*b==n)
10             puts("1");
11         else
12             puts("0");
13     }
14     return 0;
15 }
时间: 2024-08-26 22:10:18

HDU 2053 Switch Game(开灯问题,完全平方数)的相关文章

HDU 2053 Switch Game(开灯问题,唯一分解定理)

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15011    Accepted Submission(s): 9160 Problem Description There are many lamps in a line. All of them are off at first. A series of o

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op

HDU 2053 Switch Game

Switch Game 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2053Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Problem Description There are many lamps in a line. All of them are off at first. A series of operations

HDU 2053 Switch Game(数学题)

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15008    Accepted Submission(s): 9158 Problem Description There are many lamps in a line. All of them are off at first. A series of o

HDU 1218 THE DRUNK JAILER【类开灯问题】

THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27268   Accepted: 16933 Description A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked

杭电 acm 2053 ( Switch Game )

这题思路: 一开始有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

HDU 3404 Switch lights(Nim积)题解

题意:在一个二维平面中,有n个灯亮着并告诉你坐标,每回合需要找到一个矩形,这个矩形xy坐标最大的那个角落的点必须是亮着的灯,然后我们把四个角落的灯状态反转,不能操作为败 思路:二维Nim积,看不懂啊,只能套模板了 参考:HDU 3404 Switch lights (NIM 积) 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #inc

9509 开灯(dfs)

9509 开灯 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description 有16的开关分别控制16盏灯,开关排列成4*4的矩形,这些开关有这样的关系: 你改变其中一个开关的状态,与其同行和同列的开关的状态也跟着改变.先给出一个这些开关的初始状态,要求将所有的开关都打开,让所有的灯都亮起来,要求按下开关的次数最少. 输入格式 第一行输入一个整数t,表示有多少个case,每个case之间有一空行,每个case输入一

9509 开灯

9509 开灯 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description 有16的开关分别控制16盏灯,开关排列成4*4的矩形,这些开关有这样的关系: 你改变其中一个开关的状态,与其同行和同列的开关的状态也跟着改变.先给出一个这些开关的初始状态,要求将所有的开关都打开,让所有的灯都亮起来,要求按下开关的次数最少. 输入格式 第一行输入一个整数t,表示有多少个case,每个case之间有一空行,每个case输入一