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. 
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 题意:第一个人把所有的牢房全部打开,第二个人把是2的倍数的牢房全部锁上,第三个人对是3的倍数的牢房进行操作,如果是锁上的就把它打开,如果是打开的就把它锁上,依次第4个人...直到第n个人完成操作,问最后有多少间牢房是打开的
#include<stdio.h>
#include<string.h>
int a[110];
int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--)
{
int sum=0;
scanf("%d",&n);
memset(a,0,sizeof(a));
for(j=1;j<=n;j++)
{
for(i=1;i<=n;i++)
{
if(i%j==0)
{
if(a[i]==0)
a[i]=1;
else if(a[i]==1)
a[i]=0;
}
}
}
for(i=1;i<=n;i++)
if(a[i]==1)
sum++;
printf("%d\n",sum);
}
return 0;
}

  

poj 1218 THE DRUNK JAILER【水题】的更多相关文章

  1. Poj1218_THE DRUNK JAILER(水题)

    一.Description A certain prison contains a long hall of n cells, each right next to each other. Each ...

  2. poj 1218 THE DRUNK JAILER

    THE DRUNK JAILER Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23358   Accepted: 1472 ...

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

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/37727417 THE DRUNK JAILE ...

  4. POJ 1218 THE DRUNK JAILER(类开灯问题,完全平方数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2188 题目大意:n为5-100之间的一个数,代表有多少间牢房,刚开始所有房间打开,第一轮2的倍数的房间 ...

  5. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  6. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  7. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  8. poj 1004:Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

  9. POJ 3176 Cow Bowling (水题DP)

    题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...

随机推荐

  1. C#输出40以内的所有奇数程序代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  2. 完全背包的变形POJ1252

    话说今天做背包做到有点累了,题目是英文的--而且还很长,我看了好久(弱爆了). 题目大概的意思就是,有六种硬币,之后,求用这六种硬币最小数目支付1到100美分的平均值,以及最小数目中的最大值. 很容易 ...

  3. mysql备份sql,脚本

    MySQL 安装位置:/usr/local/mysq 论坛数据库名称为:bbs MySQL root 密码:123456 数据库备份目的地:/var/db_backup/ #! /bin/bash / ...

  4. JS+CSS实现选项卡功能

    [小小一记] 首先我们写一个选项卡的结构出来,包括tab和content: 首先是tab: <ul class="ttitle-box-tabs" id="tabs ...

  5. C# C/S系统软件开发平台架构图(原创)

    企业版V4.0 - 架构图 企业版V4.0 - 桥接功能.后台连接策略 桥接功能是指应用策略模式,由用户配置本地INI文件选择ADO直连(ADO-Direct)或者调用WCF服务接口访问远程服务器后台 ...

  6. BuzzSumo:什么样的文章能获得疯转?(基于1亿篇文章大数据分析)

    BuzzSumo:什么样的文章能获得疯转?(基于1亿篇文章大数据分析) 社交媒体追踪服务分析工具BuzzSumo,2014年5月前后对社交媒体上超过1亿篇文章进行了分析,试图找出一个答案: 什么样的内 ...

  7. touchend与click顺序

    http://www.w3cmm.com/javascript/touch.html click 在 touchend之前 去除超链接的虚线框 http://www.cnblogs.com/kingw ...

  8. Android 使用HttpClient方式提交POST请求

    final String username = usernameEditText.getText().toString().trim(); final String password = passwr ...

  9. 【UVA1416】(LA4080) Warfare And Logistics (单源最短路)

    题目: Sample Input4 6 10001 3 21 4 42 1 32 3 33 4 14 2 2Sample Output28 38 题意: 给出n个节点m条无向边的图,每条边权都为正.令 ...

  10. Android开源项目发现--- 安全篇(持续更新)

    SQLCipher Sqlite加密工具 项目地址:https://github.com/sqlcipher/sqlcipher 帮助文档:http://sqlcipher.net/sqlcipher ...