一、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.
One night, the jailer gets bored and decides to play a game. For round 1 of the game, he takes a drink of whiskey,and then runs down the hall unlocking each cell. For round 2, he takes a drink of whiskey, and then runs down the
hall locking every other cell (cells 2, 4, 6, ?). For round 3, he takes a drink of whiskey, and then runs down the hall. He visits every third cell (cells 3, 6, 9, ?). If the cell is locked, he unlocks it; if it is unlocked, he locks it. He
repeats this for n rounds, takes a final drink, and passes out.
Some number of prisoners, possibly zero, realizes that their cells are unlocked and the jailer is incapacitated. They immediately escape.
Given the number of cells, determine how many prisoners escape jail.

Input

The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines contains a single integer between 5 and 100, inclusive, which is the number of cells n.

Output

For each line, you must print out the number of prisoners that escape when the prison has n cells.

二、问题分析

此题属于小弟的消暑计划之一,通俗点就是水题。题意通俗易懂,解题没什么难度,要的就是这样的效果啊。哈哈哈!

三、Java代码

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner cin=new Scanner(System.in);int times=cin.nextInt();for(int i=0;i<times;i++){int n=cin.nextInt();boolean[] b=new boolean[n+1];int num=0;for(int l=1;l<=n;l++){b[l]=true;}for(int m=1;m<=n;m++){for(int j=2;j<=n;j++){if(b[m] && m%j==0){b[m]=false;}else if( !b[m] && m%j==0){b[m]=true;}}}for(int j=1;j<=n;j++){if(b[j])num++;}System.out.println(num);}}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/AndyDai/p/4734205.html

Poj1218_THE DRUNK JAILER(水题)相关推荐

  1. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  2. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  3. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  4. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  8. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  9. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

最新文章

  1. 热榜第一!GitHub 标星 5.6w,如何用 Python 实现所有算法?
  2. Linux_CentOS-服务器搭建 六
  3. php-fpm7.0,php-fpm7.0 慢查询设置及说明
  4. 视觉、语音、NLP、ML、AI安全,一家金融科技公司等你来
  5. Heritrix 3.1.0 源码解析(三十四)
  6. Windows 系统部署之创建应答文件
  7. 第九届蓝桥杯 明码2018
  8. python requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('HTTP/1.1 000\r\n'
  9. 自定义rest api的基本思想过程--总结
  10. hdfs中与file数组类似的数组_Java中的数组
  11. Apache自带的ab压力测试工具用法详解
  12. 目标检测论文综述(一)深度卷积神经网络
  13. 教你itunes电脑版怎么下载
  14. 发布infopath模板到sharepoint站点(Infopath 2007)
  15. 输入数值n,计算并输出下列多项式的值:S = 1 + 1/1! + 1/2! + 1/3! + 1/4! + ... + 1/n!
  16. MonoRail MVC应用(1)-VM/HTML页面
  17. Spring框架技术总结(一)
  18. Win8下如何安装Win7 or Win7下如何安装win8?
  19. 刘强东给京东高管降薪:2千多位总监兄弟工资打8折,并拿出100亿保障”兄弟“基础住房
  20. Nacos高级特性Raft算法以及原理和源码分析

热门文章

  1. java命令修改user.home file.encoding等参数值
  2. java post 登陆_java HttpPost 密码登录和提交表单的案例
  3. dederss.php美国与,Dede经验:全站rss/连载和分类首页模板替换
  4. mysql mysqlnd_利用mysqlnd_ms实现mysql读写分离
  5. 两组回归系数差异检验_【stata系列】——组间系数差异检验
  6. linux python wps doc 转 txt_耗时一周尝试踩坑,整理了一些Python实用知识点
  7. 傅里叶变换处理音频c++_积分变换(1)——傅里叶级数
  8. 牛顿法的matlab实现,利用matlab基础语句实现牛顿法matlab潮流计算
  9. Spark SQL之RDD转DataFrame
  10. Apache Flink 零基础入门(十四)Flink 分布式缓存