UVa 151 - Power Crisis
来源:互联网 发布:sql 除后求和 编辑:程序博客网 时间:2024/06/05 02:43
题目:有n个电厂,按照约瑟夫环的规则断电,要求最后停13号,求最小的m(删数的步长)。
分析:数学题。从1到n-1枚举所有m,找到最后输出的为13的即可。(m >= n时与m%n等价)
因为,最开始要停1号,所以问题转化为从2到n中去m的约瑟夫环,最后取13,转化为:
从1到n-1中去m的约瑟夫环,最后取12。
约瑟夫环公式:f[i+1] = (f[i]+m)%i { f[0] = 0 }
(数字从0到n-1,f[i]为长度为i的环最后的输出,原理为映射转化)
说明:注意scanf(),printf()在库<cstdio>中。
#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int main(){int n;while ( cin >> n && n ) {for ( int i = 1 ; i < n ; ++ i ) {int k = 0;for ( int j = 1 ; j < n ; ++ j )k = (k+i)%j;if ( k == 11 ) {printf("%d\n",i);break;}}}return 0;}
0 0
- Uva 151 - Power Crisis
- uva 151 - Power Crisis
- UVA 151 - Power Crisis
- UVa 151 - Power Crisis
- UVa 151 - Power Crisis
- UVa 151 - Power Crisis
- UVA, 151 Power Crisis
- Power Crisis
- Power Crisis
- Power Crisis
- Uva-12186-Another Crisis
- UVA 12186 Another Crisis
- UVA - 12186 Another Crisis
- UVA-12186 Another Crisis
- uva 12186 Another Crisis
- UVA 12186 Another Crisis
- UVA 12186 Another Crisis
- Another Crisis UVA
- hbase中强制删除表
- 微信公众平台接口程序语音天气
- Swift编程语言教程-中文版两大官方文档汇总
- 今天天气好凉快
- 使用CCLabelAtlas来显示得分
- UVa 151 - Power Crisis
- 一步一步实现C++操作SQLite数据库
- 逻辑运算符 或 ||
- 面试题(十)连续子数组的最大和、最大差
- 常用的python package下载(windows)
- Android多媒体开发【10】-- android中OpenMax的实现【1】整体框架
- NYOJ--1009 So Easy[Ⅰ]
- WKT 格式
- 存储过程里出错:在将 nvarchar 值 'MAX' 转换成数据类型 smallint 时失败, 的终极解决方法