poj 1218 THE DRUNK JAILER【水题】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 25124 | Accepted: 15767 |
Description
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
Output
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【水题】的更多相关文章
- Poj1218_THE DRUNK JAILER(水题)
一.Description A certain prison contains a long hall of n cells, each right next to each other. Each ...
- poj 1218 THE DRUNK JAILER
THE DRUNK JAILER Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23358 Accepted: 1472 ...
- [ACM] POJ 1218 THE DRUNK JAILER (关灯问题)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/37727417 THE DRUNK JAILE ...
- POJ 1218 THE DRUNK JAILER(类开灯问题,完全平方数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2188 题目大意:n为5-100之间的一个数,代表有多少间牢房,刚开始所有房间打开,第一轮2的倍数的房间 ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- poj 1004:Financial Management(水题,求平均数)
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126087 Accepted: ...
- POJ 3176 Cow Bowling (水题DP)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
随机推荐
- EditPlus 快捷键
FileFtpUpload Ctrl+Shift+S 上传文件到 FTP 服务器 FileNew Ctrl+N 新建普通的文本文档 Fi ...
- 使用微信api接口开发的框架
<?php/** * 微信公众平台API */class WeixinChat{ private $token; private $appid; private $appsecret; priv ...
- 如何让你的eclipse运行更快和eclipse常用快捷键
方案来之网络,已自测... 原地址:戳进来 1.在eclipse启动的时候,它总是会搜索让其运行的jre,往往就是这个搜索过程让eclipse启动变慢了.(没设置时,等2-3s出现进度条,设置后直接出 ...
- [转] 小tip: 使用CSS将图片转换成黑白(灰色、置灰) ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=2547 //zxx: ...
- Python3.4使用MySql
如何在Django1.6结合Python3.4版本中使用MySql django默认的mysql连接是Mysqldb,悲催的是此版本只支持到python2.7,oracle官方的mysql-conne ...
- linux c++ 遍历一个目录下的文件名 (包括子目录的文件名)
最近写代码有一个要遍历目录下的每一个文件并取得这个文件的绝对路径的需求, 我们知道linux c++中有system命令所以我在代码中 先生成了一个log,然后去读log文件的每一行文件名,然后给存储 ...
- ruby特性
1. ruby类结构 每个类都是Class类的对象 所有类都继承自BasicObject类(Module类不能实例化) 2. 单例方法 单例方法可以不定义在类中,只为某个对象定义方法,所以称为单例方法 ...
- mmap内存映射复习
c语言初学时,比较常见的一个习题就是实现cp. 使用c库实现的cp就不赘述了. 最近工作用到内存映射,就拿来练下手,复习一下mmap的用法. 很简单,将目标文件和源文件映射到内存,然后使用memcpy ...
- PyCharm 5.0.3 快捷键
下面记录PyCharm 5.0.3常用快捷键 注释 注释行:Ctrl+/
- PANGU---Planet and Asteroid Natural scene Generation Utility
PANGU是由英国dundee邓迪大学开发的一款行星.小行星自然环境仿真软件 https://www.star-dundee.com/products/pangu-planet-and-asteroi ...