HDOJ 2053 Switch Game
Problem 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
0
Hinthint
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.
思路:
说下题目大意吧,
先把这些灯标上号,1 2 3 4 5 6 7 8 ……无穷
首先全是关的,也就是全是0
第一次操作 ,标号是1的倍数,全都变成相反的状态,也就是全变成1.。
第二次操作 ,标号是2的倍数,全都变成相反的状态,你可以看下,2 4 6……变成了0.。。
第三次操作 ,标号是3的倍数,全都变成相反的状态,你可以看下,3 6 9……
他问你 N 号台灯最后 变成了 什么状态,
例如 1号灯,最后变成了1,不管多少次操作都是1.。
例如 5号灯 最后变成了0,不管多少次操作都是0.。
当操作次数大于N的时候 N的状态就不会改变了,因为N不会是M(M>N)的倍数。。
本题思路很简单就是求n有几个约数(包括1和自身)如果有奇数个约数,变奇数次,结果也就是1;否则为0
import java.util.Scanner;
public class Main {
// static boolean[] islight = new boolean[100002];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
// for(int i=1;i<=n;i++){
// islight[i] = false;
// }
//
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// if(j%i==0){
// islight[j] = !islight[j];
// }
// }
// }
//
// if(islight[n]){
// System.out.println("1");
// }else{
// System.out.println("0");
// }
// 超时
int k =0;
for(int i=1;i<=n;i++){
if(n%i==0){
k++;
}
}
if(k%2==0){
System.out.println("0");
}else{
System.out.println("1");
}
}
}
}
HDOJ 2053 Switch Game的更多相关文章
- hdu 2053 Switch Game 水题一枚,鉴定完毕
Switch Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2053 Switch Game
http://acm.hdu.edu.cn/showproblem.php?pid=2053 Problem Description There are many lamps in a line. A ...
- HDU 2053 Switch Game(开灯问题,完全平方数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2053 题目大意:灯开始是关着的,有n盏灯,i从1数到n每当灯的序号是i的倍数的时候就对灯进行一次操作( ...
- 杭电(hdu)2053 Switch Game 水题
Switch Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 杭电oj2047-2049、2051-2053、2056、2058
2047 阿牛的EOF牛肉串 #include<stdio.h> int main(){ int n,i; _int64 s[]; while(~scanf("%d" ...
- hdu 1039 (string process, fgets, scanf, neat utilization of switch clause) 分类: hdoj 2015-06-16 22:15 38人阅读 评论(0) 收藏
(string process, fgets, scanf, neat utilization of switch clause) simple problem, simple code. #incl ...
- hdu 1035 (usage of sentinel, proper utilization of switch and goto to make code neat) 分类: hdoj 2015-06-16 12:33 28人阅读 评论(0) 收藏
as Scott Meyers said in his book Effective STL, "My advice on choosing among the sorting algori ...
- hdu 1033 (bit masking, utilization of switch, '\0' as end of c string) 分类: hdoj 2015-06-15 21:47 37人阅读 评论(0) 收藏
bit masking is very common on the lower level code. #include <cstdio> #include <algorithm&g ...
- hdoj:2053
#include <iostream> #include <string> #include <vector> using namespace std; /* 无穷 ...
随机推荐
- 设置linux服务器定时与时间服务器同步
在一些大公司经常出现这样一个情况:公司或一些机关单位的内部业务系统的应用服务器以及数据都是做的多机集群部署而且基本都是linux系统,而且都是内部网,不与外网通讯的.这样经常就会出现一个情况,我发送任 ...
- animationWithKeyPath键值对
animationWithKeyPath键值对的方式来改变动画 <Jacky Shin:可以从这个网址查到哪些可以做为动画效果, 打开xcode帮助,搜索animatable propertie ...
- 【转】 iOS开发之手势gesture详解
原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...
- 1、大部分社交平台接口不支持https协议。
参考文献来自:http://wiki.mob.com/ios9-%E5%AF%B9sharesdk%E7%9A%84%E5%BD%B1%E5%93%8D%EF%BC%88%E9%80%82%E9%85 ...
- 使用Physics_Body_Editor获得json文件的类
[转自]:http://www.cocoachina.com/bbs/read.php?tid=209290 工具介绍,json文件获得方法,请参考原帖 MyBodyParser.h // // My ...
- SGU 152.Making round
不断向下取直到,忽略的数累计到一个百分比,给当前百分比加1. 这道题要避免处理浮点数,用余数来处理,不然会wa 9 #include <iostream> #include <cma ...
- 关于Function()函数对象的那些小九九
概念:首先,函数是一种特殊类型的数据,函数也是数据类型的一种,实际上函数也是一种对象,函数对象的内建构造器是Function(); 函数的几种创建方式: 函数声明法: function sum(a,b ...
- IOS 企业版证书($299)In-House方式发布指南
一.明确几个概念 1.企业版IDP:即iOS Development Enterprise Program.注意是$299/Year那种,并不是$99/Year的那种. 2.In House:是只企业 ...
- windows系统安装ubuntu后,grub中没有windows启动项
我的问题: 安装系统时候,选择grub安装在sdb磁盘 http://forum.ubuntu.org.cn/viewtopic.php?f=139&t=474289&start=15 ...
- Node.js规范化应用
Node.js运行在一个单线程模式,但它使用一个事件驱动范例来处理并发.它还有助于创建子进程,以充分利用并行处理的多核CPU系统. 子进程总是有三个流child.stdin,child.stdout和 ...