Pku1218
<span style="background-color: rgb(204, 204, 204);">/*
A - THE DRUNK JAILER
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Submit Status Practice POJ 1218
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 <span style="color:#6633ff;">the</span> number of prisoners that escape when the prison has n cells.
Sample Input
2
5
100
Sample Output
2
10
By Grant Yuan
2014.7.11
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool a[101];
int main()
{int m,n,i,j,sum=0;
cin>>n;
while(n--){memset(a,0,101);
cin>>m;
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
if(j%i==0) a[j]=1-a[j];
for(j=1;j<=m;j++)
if(a[j]) sum++;
cout<<sum<<endl;
sum=0;
}
return 0; }
</span>
Pku1218的更多相关文章
随机推荐
- TCMalloc 安装与使用
TCMalloc 安装和使用 Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn.net/chen19870707 Da ...
- 关于苹果公司最新的语言Swift
Swift供IOS和OSX新的编程语言开发的应用程序,吸取C和Objective-C质朴的语言.但没有损失C兼容性语言.Swift使用安全的编程模型.增加各种现代编程语言功能,使语言更容易掌握.更具可 ...
- 左右AjaxFileUpload背景返回Json治
项目中用到图片的无刷新上传,因此想到用ajaxUpLoadFile来解决. 第一步,先在上传图片的页面引入你下载到本地的ajaxfileupload.js文件. 文件下载地址:http://downl ...
- android 该项目的优化toast优化技巧
我们这样做的时候经常登录认证使用toast提示用户输入出现错误等..很多人都直接使用 Toast.makeText(LoginActivity.this, "请联系小区的物业管理" ...
- Unity GUI选择与评价
因为Unity内建的GUI不管是不是从开发效率或效率强制,因此,许多派生GUI插入,什么插件的选择,是一个非常值它被认为是. 既然是评价,就会有非常多的主观意识,这不一定成为选择的根据. 再比方.我已 ...
- OC本学习笔记Foundatio框架集
一.OC数组 OC数组是一个类,它也分不可变数组NSArray和可变数组NSMutableArray. 1➣不可变数组的创建 // 创建一个不可变数组.元素为一个OC字符串对象 ...
- MVC5 Entity Framework学习之实现继承
之前你已经学习了怎样处理并发异常,在本节中你将学习怎样实现继承. 在面向对象的编程中,你能够使用继承来重用代码.接下来你将改动Instructor和Student类,让它们派生自Person基类,该基 ...
- android 防止多次点击提交
版权声明:本文博客原创文章.博客,未经同意,不得转载.
- bzoj 2437 [Noi2011]兔子和鸡蛋 [二分图匹配]
叙述性说明 这些日子.兔子和蛋像一个新的棋盘游戏. 这场比赛是在 n 行 m 在船上进行列. 前,棋盘上有一 个格子是空的,其他的格子中都放置了一枚棋子,棋子或者是黑色,或者是白色. 每一局游戏总是兔 ...
- 【 D3.js 进阶系列 — 2.1 】 力学图的事件 + 顶点的固定
本章讨论在力学图中经常使用到的事件( Event ),然后对[p=555">进阶 - 第 2.0 章]的人物关系图进行改进.使用户可以固定拖拽的对象. 在[入门 - 第 9.2 章]和 ...