1218THE DRUNK JAILER

THE DRUNK JAILER

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 25010   Accepted: 15692

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

Source

#include<iostream>
#include<cstring>

using namespace std;

int a[102];
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
	int n;
	   cin>>n;
	   memset(a,0,sizeof(a));
	   for(int i=1;i<=n;i++)
	   {for(int j=1;j<=n;j++)
			if(j%i==0)
			{
				a[j]=!a[j];
			}
	   }
	   int count=0;
	   for(int i=1;i<=n;i++)
	   if(a[i]==1)
	   count++;

	   cout<<count<<endl;
	}
}

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

时间: 2025-01-11 23:49:46

1218THE DRUNK JAILER的相关文章

POJ1218 THE DRUNK JAILER

问题链接:POJ1218 THE DRUNK JAILER. 题意简述:输入n,n为5-100间的一个数,代表有多少间牢房.刚开始所有房间打开,第1轮2的倍数的房间门翻转(打开的关上,关上的打开),第2轮3的倍数,第3轮4的倍数,......,第n-1轮n的倍数.求最后有几间牢房门是打开的. 问题分析:使用模拟法,模拟这个过程即可.好在计算规模不算大. AC的C语言程序如下: /* POJ1218 THE DRUNK JAILER */ #include <stdio.h> #include

开灯问题 —— POJ 1218 THE DRUNK JAILER

对应POJ 题目:点击打开链接 THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24831   Accepted: 15569 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 eac

[ACM] POJ 1218 THE DRUNK JAILER (关灯问题)

THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23246   Accepted: 14641 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

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

poj 1218 THE DRUNK JAILER【水题】

THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25124   Accepted: 15767 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

hdu 1337 The Drunk Jailer

http://acm.hdu.edu.cn/showproblem.php?pid=1337 1 #include <cstdio> 2 #include <cstring> 3 #define maxn 200 4 using namespace std; 5 int main() 6 { 7 int t; 8 int a[maxn]; 9 scanf("%d",&t); 10 int n; 11 while(t--) 12 { 13 scanf(&q

poj-1218 THE DRUNK JAILER 喝醉的狱卒

自己去看看原题; 题目大意: 就是一个狱卒喝醉了,他第一趟吧所有的监狱都带开,第二趟把能把二整除的监狱关闭,第三趟操作能把三整除的监狱; 求最后能逃跑的罪犯数 输入第一个数是代表 测试数据组数 每个数据代表狱卒来回的次数 当作开关问题即可 #include<iostream> using namespace std; int main() { int n; cin>>n; while(n--) { int a; int aa[120]={1}; cin>>a; int

POJ 1218 THE DRUNK JAILER

开关问题,有n个灯,分别由n个开关控制,拨一下开关则可以改变灯的状态(开->关 关->开).初始状态灯都是关着的,先把每个开关都拨一下,然后拨一下2的倍数的开关,接着3的倍数,直到n的倍数,问最后有多少灯是开着的. #include <iostream> #include <cstring> using namespace std; int main() { int n; cin>>n; while(n--) { int t, a[110], k; mems

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY