HDU 1443 Joseph
2014-09-04 15:27
375 查看
暴力过,注意k值可能重复出现,要避免重复运算
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
int stor[20]={0};
int main()
{
int k;
while(cin>>k,k)
{
int m=1,cont;
if(stor[k])
{
cout<<stor[k]<<endl;
continue;
}
while(true)
{
int p=-1;
cont=0;
int md=k<<1;
m++;
while(true)
{
p=(p+m)%md;
if(p<k)
break;
p--;
cont++;
md--;
}
if(k==cont)
break;
}
stor[k]=m;
cout<<m<<endl;
}
return 0;
}
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
int stor[20]={0};
int main()
{
int k;
while(cin>>k,k)
{
int m=1,cont;
if(stor[k])
{
cout<<stor[k]<<endl;
continue;
}
while(true)
{
int p=-1;
cont=0;
int md=k<<1;
m++;
while(true)
{
p=(p+m)%md;
if(p<k)
break;
p--;
cont++;
md--;
}
if(k==cont)
break;
}
stor[k]=m;
cout<<m<<endl;
}
return 0;
}
相关文章推荐
- poj 1012 & hdu 1443 Joseph(约瑟夫环变形)
- HDU 1443 Joseph
- POJ 1012 && HDU 1443 Joseph(约瑟夫问题)
- HDU 1443 Joseph
- hdu 1443 Joseph
- HDU 1443 Joseph
- hdu 1443 Joseph
- hdu 1443 Joseph+暴力打表
- HDU1443 Joseph
- HDU 1443 Joseph 约瑟夫环 暴力
- hdu 1443 Joseph+暴力打表
- HDU:1443Joseph(一个超级无耻的…
- hdu 1443 Joseph (约瑟夫环)
- HDU 1443 Joseph
- hdu -- 1443 Joseph
- HDU 1443 Joseph
- HDU 1443 Joseph
- hdu 1443 Joseph
- HDU 1443 Joseph
- HDU 1443 Joseph