POJ 1012 Joseph 笔记 G++
2017-04-21 18:27
411 查看
/*
#include <iostream>
#include <vector>
using namespace std;
//Time Limit Exceeded
int main()
{
while(1)
{
int NUM;
cin>>NUM;
if(NUM==0)
{
break;
}
int shu=1;
while(1)
{
int t=shu;
int wz=0;
vector<int> a;
for(int i=0;i<NUM;i++)
{
a.push_back(1);
}
for(int i=0;i<NUM;i++)//把2挑出来
{
a.push_back(2);
}
int N=NUM*2;
for(int i=0;i<NUM;i++)
{
//cout<<"shu "<<shu<<" wz "<<wz<<" N "<<N<<" (wz+shu-1)%N "<<(wz+shu-1)%N-1<<endl;
if(a[(wz+shu-1)%N]==2)
{
a.erase(a.begin()+(wz+shu-1)%N);
wz=(wz+shu-1)%N;
N--;
}else
{
shu++;
break;
}
}
if(shu==t)
{
cout<<shu<<endl;
break;
}
}
}
return 0;
}
*/
//由上面程序的结果打表
#include <iostream>
using namespace std;
int a[14];
int main()
{
a[1]=2;
a[2]=7;
a[3]=5;
a[4]=30;
a[5]=169;
a[6]=441;
a[7]=1872;
a[8]=7632;
a[9]=1740;
a[10]=93313;
a[11]=459901;
a[12]=1358657;
a[13]=2504881;
while(1)
{
int NUM;
cin>>NUM;
if(NUM==0)
{
break;
}
cout<<a[NUM]<<endl;
}
return 0;
}
k个好人k个坏人,好人在前,围成一圈。按一个数查圈,先挑出坏人。求这个数。
#include <iostream>
#include <vector>
using namespace std;
//Time Limit Exceeded
int main()
{
while(1)
{
int NUM;
cin>>NUM;
if(NUM==0)
{
break;
}
int shu=1;
while(1)
{
int t=shu;
int wz=0;
vector<int> a;
for(int i=0;i<NUM;i++)
{
a.push_back(1);
}
for(int i=0;i<NUM;i++)//把2挑出来
{
a.push_back(2);
}
int N=NUM*2;
for(int i=0;i<NUM;i++)
{
//cout<<"shu "<<shu<<" wz "<<wz<<" N "<<N<<" (wz+shu-1)%N "<<(wz+shu-1)%N-1<<endl;
if(a[(wz+shu-1)%N]==2)
{
a.erase(a.begin()+(wz+shu-1)%N);
wz=(wz+shu-1)%N;
N--;
}else
{
shu++;
break;
}
}
if(shu==t)
{
cout<<shu<<endl;
break;
}
}
}
return 0;
}
*/
//由上面程序的结果打表
#include <iostream>
using namespace std;
int a[14];
int main()
{
a[1]=2;
a[2]=7;
a[3]=5;
a[4]=30;
a[5]=169;
a[6]=441;
a[7]=1872;
a[8]=7632;
a[9]=1740;
a[10]=93313;
a[11]=459901;
a[12]=1358657;
a[13]=2504881;
while(1)
{
int NUM;
cin>>NUM;
if(NUM==0)
{
break;
}
cout<<a[NUM]<<endl;
}
return 0;
}
k个好人k个坏人,好人在前,围成一圈。按一个数查圈,先挑出坏人。求这个数。
相关文章推荐
- poj1012-Joseph
- POJ 1012 Joseph
- poj 1012 Joseph解题报告
- POJ 1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph 约瑟夫问题 (★★☆☆☆)
- 【POJ】1012 Joseph
- poj1012 Joseph题解2
- poj 1012 -- Joseph (约瑟夫环)
- POJ1012 Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph 解题报告
- poj 1012 Joseph
- Poj 1012 Joseph (约瑟夫环)
- POJ 1012 Joseph
- poj1012-Joseph
- poj 1012 joseph
- POJ 1012 Joseph 约瑟夫-保证坏人先被清除
- POJ 1012 Joseph解题报告
- poj1012——Joseph