您的位置:首页 > 其它

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: