UVA, 151 Power Crisis
来源:互联网 发布:mac没有flash会怎么样 编辑:程序博客网 时间:2024/06/05 06:52
题目:约瑟夫模型。要求最后输出的是13
注意:判断跳出条件时,用m.size()>2而不是>1,否则会发生指针错误。这种错误在xcode中会直接指出来。在codeblocks中,程序仍然可以运行,但是,会突然中止。
提示“Process terminated with status -1073741676 (0 minute(s), 6 second”。检查时注意可能涉及到的溢出情况
#include <cstdio>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <ctgmath>
#include <iostream>
#include <vector>
#include <algorithm>
using namespacestd;
void pack(vector<int> &m,int a){
for(int i=1; i <= a; i++){
m.push_back(i);
}
}
int main()
{
vector<int> m;
int a;
while(scanf("%d",&a) && a){
int gap =1;
for(;;gap++){
pack(m, a);
int num =0;//关键代码
while( m.size()>=2 ){
m.erase(m.begin()+num);
num = (num+gap-1)%(m.size()) ;
}
if(m[0] ==13) {
m.clear();
break;
}
m.clear();
}
cout<<gap<<endl;
}
return0;
}
- 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
- OLDboy-python第八期运维教程
- 对于丢失网络之后ssh抛出的 Caused by: java.net.UnknownHostException: struts.apache.org异常处理
- Packet for query is too large(mysql写入数据过大)
- Ubuntu系统在任意终端下运行已安装的可执行程序
- uilabel 多行显示时顶端对齐
- UVA, 151 Power Crisis
- 构建技术知识体系,让自己含金量更高
- 【代码】指针
- 学习opencv——手写数字识别(2)
- 老男孩python第六期高级运维开发课程
- 树的统计【bzoj1036】
- leetcode 4:median-of-two-sorted-arrays
- ACM-递推递归练习A-母牛的故事
- No repeats please