THE DRUNK JAILER
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 24918   Accepted: 15632

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.

Sample Input

2
5
100

Sample Output

2
10
poj的一道水题,就是n个牢房,犯人从第一个牢房开始每次改变牢房的状态,如果是锁的,就打开,没有锁,就锁上;
循环n次,看看能逃出去几个犯人
#include <map>
#include <set>
#include <string>
#include <cctype>
#include <climits>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#define INF 0x3f3f3f3f
#define ClearAll(A,T) memset(A,T,sizeof(A)) using namespace std; const int Max=100;
int a[110];
int main()
{ int n,m;
while(~scanf("%d",&n))
{
if(n==0)
{
continue;
}
for(int i=1;i<=n;i++)
{
scanf("%d",&m);
int sum=0;
memset(a,0,sizeof(a));
for(int j=2;j<=m;j++)
{
for(int k=j;k<=m;k+=j)
{
a[k]=a[k]==0?1:0;
}
}
for(int i=1;i<=m;i++)
{
if(!a[i])
sum++;
}
printf("%d\n",sum);
}
}
return 0;
}

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

THE DRUNK JAILER 分类: POJ 2015-06-10 14:50 13人阅读 评论(0) 收藏的更多相关文章

  1. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

  2. Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. printf "%.*s" 分类: 小细节 2015-07-04 14:36 2人阅读 评论(0) 收藏

    ref : http://www.cnblogs.com/yuaqua/archive/2011/10/21/2219856.html 小数点.后"*"表示输出位数,具体的数据来自 ...

  4. iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏

    一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...

  5. iOS中UITextField 使用全面解析 分类: ios技术 2015-04-10 14:37 153人阅读 评论(0) 收藏

    //初始化textfield并设置位置及大小   UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...

  6. Win10尝鲜体验——初识传说中不一样的Windows 分类: 资源分享 2015-07-24 18:27 13人阅读 评论(0) 收藏

    这几天,网上传来一个消息,虽然不知是好是坏,Win10可以下载安装了! 出于好奇,下载尝鲜,几个截图,留作纪念~ 中文,还是要好好支持的,毕竟中国有如此多的用户 可选的安装版本 许可条款也刚刚出炉,估 ...

  7. IIS上虚拟站点的web.config与主站点的web.config冲突解决方法 分类: ASP.NET 2015-06-15 14:07 60人阅读 评论(0) 收藏

    IIS上在主站点下搭建虚拟目录后,子站点中的<system.web>节点与主站点的<system.web>冲突解决方法: 在主站点的<system.web>上一级添 ...

  8. C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏

    using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...

  9. C++实现不能被继承的类——终结类 分类: C/C++ 2015-04-06 14:48 64人阅读 评论(0) 收藏

    1.       问题 C++如何实现不能被继承的类,即终结类.Java中有final关键字修饰,C#中有sealed关键字修饰,而C++目前还没有类似的关键字来修饰类实现终结类,需编程人员手动实现. ...

随机推荐

  1. java List 简单使用

    Student类 class Student{ String name; String pwd; public Student(){} public Student(String name, Stri ...

  2. PHP判断手机号码是否合法

    <html> <head> <script language="JavaScript"> function checkMobile(input) ...

  3. 河南省第八届ACM程序设计大赛总结

    简单的对这次省赛做个总结:总体来说这个比赛过程中做的还算比较顺利,虽然中间多多少少遇到一些坑,正式比赛开始后,我们就开始找水题,当然了我首先把英文题目翻译了一遍,发现了一道水题,这道题目其实就是判断点 ...

  4. Linux内核之旅 List_entry()

    #include "iostream" #define List_entry(type,member)\ (type *)(()->data)) ) using namesp ...

  5. 说说oracle分页的sql语句

    说说oracle分页的sql语句,分排序和不排序两种. 当结果集不需要进行排序时,每页显示条数为:rowPerPage,当前页数为:currentPage. 1. 相对来说,这种查询速度会快一些,因为 ...

  6. ralink网卡驱动的下载地址集合

    linuxMT7612U11/7/2014v3.0.0.1http://cdn-cw.mediatek.com/Downloads/linux/MT7612U_DPO_LinuxSTA_3.0.0.1 ...

  7. 【sublime】在终端下手动安装sublime text 2

    Sublime2下载地址:http://www.sublimetext.com/download step.1 解压下载的压缩包 tar xf Sublime\ Text\ 2.0.2.tar.bz2 ...

  8. 4项技巧使你不再为PHP中文编码苦恼

    PHP程序设计中中文编码问题曾经困扰很多人,导致这个问题的原因其实很简单,每个国家(或区域)都规定了计算机信息交换用的字符编码集,如美国的扩展 ASCII 码,中国的 GB2312-80,日本的 JI ...

  9. 利用VHD虚拟文件加密自己的个人信息

    1.制作VHD磁盘 计算机—管理—磁盘管理—操作—创建VHD 2.挂载卸载VHD磁盘 磁盘管理—操作—附加VHD 选择只读则不允许修改文件内容 3.用途 这样一个虚拟磁盘就被建立出来.它实际上仅仅是一 ...

  10. Ceph的状态错误

    使用命令检查ceph集群的监控状态,得到 [root@node1 ~]# ceph -s cluster c4898b1c-7ac1-406d-bb5d-d3c7980de438 health HEA ...