博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[解题报告]151 - Power Crisis
阅读量:7055 次
发布时间:2019-06-28

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

 Power Crisis 

During the power crisis in New Zealand this winter (caused by a shortage of rain and hence low levels in the hydro dams), a contingency scheme was developed to turn off the power to areas of the country in a systematic, totally fair, manner. The country was divided up into N regions (Auckland was region number 1, and Wellington number 13). A number, m, would be picked `at random', and the power would first be turned off in region 1 (clearly the fairest starting point) and then in every m'th region after that, wrapping around to 1 after N, and ignoring regions already turned off. For example, if N = 17 and m = 5, power would be turned off to the regions in the order:1,6,11,16,5,12,2,9,17,10,4,15,14,3,8,13,7.

 

The problem is that it is clearly fairest to turn off Wellington last (after all, that is where the Electricity headquarters are), so for a given N, the `random' number m needs to be carefully chosen so that region 13 is the last region selected.

 

Write a program that will read in the number of regions and then determine the smallest number m that will ensure that Wellington (region 13) can function while the rest of the country is blacked out.

 

Input and Output

Input will consist of a series of lines, each line containing the number of regions (N) with tex2html_wrap_inline42 . The file will be terminated by a line consisting of a single 0.

 

Output will consist of a series of lines, one for each line of the input. Each line will consist of the number m according to the above scheme.

 

Sample input

 

170

 

Sample output

 

7 首先处理一下方便解题 先把头一个先去掉,再从0开始编号, 这样就不是13号留最后,而是11留最后。 不折返顺着m个m个的关,把同一趟最后关的下一个当做第一个,开头的接在这一趟的最后,已经关闭的当做删除 这样只要保证某一次的第一个是11然后输出m就可以了
#include
int main(){ int N,m,t; int i; while(scanf("%d",&N)!=EOF&&N!=0) { for(m=1;m

 

转载于:https://www.cnblogs.com/TheLaughingMan/archive/2013/02/23/2923037.html

你可能感兴趣的文章
三元运算符判断分数类型
查看>>
通过QC远程运行QTP脚本,QTP自动崩溃关闭的解决方法
查看>>
HTML资源定位器-URL
查看>>
定时器setTimeout()和setInterval()使用心得整理
查看>>
C#学习笔记③——手动调试与错误处理
查看>>
Oracle all_parameters 视图
查看>>
StringBuilder拼接字符串,“,”在前还是在后问题
查看>>
Linux 内核中断内幕【转】
查看>>
Linux内核驱动--mmap设备方法【原创】
查看>>
ELK(elasticsearch+kibana+logstash)搜索引擎(二): elasticsearch基础教程
查看>>
网页中内容的显示问题
查看>>
JAVA编程思想三
查看>>
加密工具类
查看>>
ThinkPHP配置简单的mysql读写分离
查看>>
AngularJS Select(选择框)
查看>>
EXT.NET入门必读
查看>>
数据结构定义
查看>>
实验报告二201521460014
查看>>
sql中的Replace
查看>>
POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏...
查看>>