[1218]THE DRUNK JAILER (水题)POJ
2014-09-25 22:44
176 查看
THE DRUNK JAILER
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
Sample Output
题意:
THE DRUNK JAILER
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23597 | Accepted: 14853 |
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
题意:
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int n,m,num; int i,j,k; int room[110]; scanf("%d",&n); while(n--) { num=0; scanf("%d",&m); memset(room,0,sizeof(room)); for(i=2;i<=m;i++) { k=i; j=2; while(k<=m) { if(room[k]==0) room[k]=1; else if(room[k]==1) room[k]=0; k=i*j; j++; } } for(i=1;i<=m;i++) { if(room[i]==0) num++; } printf("%d\n",num); } return 0; }
相关文章推荐
- POJ 1218 THE DRUNK JAILER(水题)
- 【水题】POJ-1218 THE DRUNK JAILER
- POJ 1218 水题
- THE DRUNK JAILER - POJ 1218 水题
- poj_1218 水题
- poj 1218 THE DRUNK JAILER【水题】
- poj 1511 spfa水题
- POJ-1218
- POJ水题1008Maya Calendar
- [poj] 水题2159
- poj 3615(floyd变形 水题)
- POJ 1258 Agri-Net (最小生成树 + 水题)
- poj 1003&&HDU 1056 && nyoj 156 Hangover【水题】
- POJ 3641 Oulipo KMP 水题
- hdu 1241 || poj 1562 Oil Deposits(搜索:BFS水题)
- POJ 1298 The Hardest Problem Ever(我的水题之路——解密,水题)
- POJ水题集1
- poj 最小生成树入门水题 1251 && 1258 && 1287 && 2395 && 2485 && 2377
- poj 1218 THE DRUNK JAILER
- POJ 2028 When Can We Meet?(我的水题之路——边输入,边搜索)