poj 1012
来源:互联网 发布:mac照片导出到移动硬盘 编辑:程序博客网 时间:2024/06/03 19:43
利用打表来节省时间,约瑟夫问题的变体;
#include<stdio.h>
int result[1000]={0};
bool text(int k,int m)
{
int i,t=0,curr=2*k;//sum people
for(i=1;i<=k;i++)
{
t=(t+m-1)%curr;
curr--;
if(t<k)return false;
}
return true;
}
void db()
{
int k,m;
for(k=1;k<14;k++)
for(m=k+1;;m++)
if(text(k,m)==true)
{
result[k-1]=m;
break;
}
}
int main()
{
int k;
db();
while(scanf("%d",&k)!=EOF){
printf("%d\n",result[k-1]);
}
}
0 0
- POJ 1012
- POJ 1012
- POJ 1012
- POJ 1012
- poj 1012
- POJ 1012
- POJ-1012
- poj 1012
- POJ 1012
- poj 1012
- poj 1012
- poj 1012
- POJ 1012
- POJ 1012
- 约瑟夫环问题 poj 1012 && poj 2244
- POJ 1012 Joseph
- POJ 1012 约瑟夫问题
- POJ 1012 Joseph
- Atitit.故障排除系列---NoClassDefFoundError NoClassDefFoundError
- Java中的垃圾收集器
- nike air max Ldpo aGDX dnmNX
- (hiho一下 第十九周)线段树之查询空间最小值
- hadoop例子
- poj 1012
- 触摸机制
- elasticsearch的javaAPI之index
- POJ 2560 Freckles(最小生成树)
- java集合框架
- ActiveX控件的注册
- Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员
- linux常见错误解答汇总
- Atitit.故障排除系列---php 程序网站数据库错误排除流程