博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【C语言】1218 THE DRUNK JAILER
阅读量:5166 次
发布时间:2019-06-13

本文共 1249 字,大约阅读时间需要 4 分钟。

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.

#include 
int main(){ int t, i, n, k, cc; int a[101]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) a[i]=0; for(k=1;k<=n; k++) for(i=k; i<=n; i+=k) a[i]=!a[i]; cc=0; for(k=1;k<=n; k++) if(a[k]) cc++; printf("%d\n", cc); } return 0;}

 

转载于:https://www.cnblogs.com/ieybl/p/6553532.html

你可能感兴趣的文章
SQLServer中的CTE通用表表达式
查看>>
ural 1133. Fibonacci Sequence
查看>>
压缩图片
查看>>
SDK登录cognos
查看>>
内存知识整理。
查看>>
redis—Spring中redis缓存的简单使用
查看>>
[VC]关于ocx打包为cab的使用
查看>>
面向对象高级编程(1)-使用__slots__
查看>>
软件测试-HW03
查看>>
linux第1天 fork exec 守护进程
查看>>
Ajax原理学习
查看>>
最新最潮的24段魔尺立体几何玩法(2016版)
查看>>
C# 3.0 LINQ的准备工作
查看>>
CodeForces - 449D Jzzhu and Numbers
查看>>
mysql批量插入更新操作
查看>>
静态代码审查工具FxCop插件开发(c#)
查看>>
创建代码仓库
查看>>
理解裸机部署过程ironic
查看>>
Django 组件-ModelForm
查看>>
zabbix 二 zabbix agent 客户端
查看>>