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 of which is next to the other. Each cell had a prisoner in it, and each cell was 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 was 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 over, inclusive, which is the number of cells N.
Output
For each line, you must print out the number of prisoners, which escape when the prison have n cells.
Sample Input
25100
Sample Output
210
Source
Greater New York 2002
Original title Link: http://poj.org/problem?id=1218
Test instructions: The input n,n is a number of 5-100, representing how many cells are in the room. Just beginning all rooms open, 1th Round 2 multiples of the room door flipped (open close, closed open), 2nd Round 3 multiples, 3rd Round 4 multiples, ..., n-1 round n multiples. Finally, there are several cell doors open.
And the classical open the light problem is similar, the data is not big, can direct simulation, but also has the good method.
AC code 1: Violent Simulations:
#include <iostream> #include <cstdio> #include <cstring>using namespace Std;int main () { bool a[ ]; int t,n; Freopen ("Data/1218.txt", "R", stdin); cin>>t; while (t--) { cin>>n; memset (A,true,sizeof (a)); for (int i=2;i<=n;i++) {for (int j=1;j<=n;j++) { if (j%i==0) a[j]=!a[j]; } } int ans=0; for (int i=1;i<=n;i++) if (A[i]) ans++; cout<<ans<<endl; } return 0;}
AC Code 2:
#include <iostream> #include <cmath> #include <cstdio>using namespace Std;int main () { int t,n; Freopen ("Data/1218.txt", "R", stdin); cin>>t; while (t--) { cin>>n; int ans=0; for (int i=1;i*i<=n;i++) ans++; cout<<ans<<endl; } return 0;}
AC Code 3: Daniel Code
#include <iostream> #include <cmath> #include <cstdio>using namespace Std;int main () { int t,n; Freopen ("Data/1218.txt", "R", stdin); cin>>t; while (t--) { cin>>n; int ans= (int) sqrt (n*1.0); cout<<ans<<endl; } return 0;}
HDU 1218 the DRUNK jailer "class turn on the Lights"