POJ 1012 Joseph(打表题)
来源:互联网 发布:淘宝多个自定义间隙 编辑:程序博客网 时间:2024/05/28 15:48
题意:约瑟夫环的变形,要求寻找到一个杀人循环节m使后半节的坏人先被全部杀光。
直接链表模拟出结果,再打表就行;
代码:(注释的是打表码)
#include<iostream>#include<cstdio>#include<cmath>#include<map>#include<queue>#include<string>#include<cstring>#include<algorithm>using namespace std;/*int l[30],r[30];int main(){ int k=1; //while(~scanf("%d",&k)&&k) for(k=1;k<14;k++) { k*=2;int ans=0; for(int i=1;1;i++) { memset(r,0,sizeof r); memset(l,0,sizeof l); for(int j=1;j<=k;j++) r[j]=j+1,l[j]=j-1; r[k]=1;l[0]=k; int dead=0,flag=1; for(int num=1,x=1;dead!=k/2;x=r[x],num++) { if(num!=i) if((i-num)/(k-dead)&&(i-num)%(k-dead)>0)num+=(i-num)/(k-dead)*(k-dead); else ; else if(x>k/2)num=0,l[r[x]]=l[x],r[l[x]]=r[x],dead++; else {flag=0;break;} } if(flag){ans=i;break;} } printf("%d,",ans); k/=2; } return 0;}*/int da[]={2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};int main(){ int n; while(~scanf("%d",&n)&&n) { printf("%d\n",da[n-1]); } return 0;}
0 0
- POJ 1012 Joseph(打表题)
- POJ 1012 Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph
- 【POJ】1012 Joseph
- poj 1012 Joseph
- poj-1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph
- Poj 1012 Joseph
- POJ - 1012 Joseph
- [POJ][1012]Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph
- 【Linux】查看dhcp服务
- Guava手册
- Centos下ftp服务安装与配置
- Container with most water
- HTTPS原理
- POJ 1012 Joseph(打表题)
- 【Hrbust】 The Smallest Oil Tank (Kruskal算法)
- easyui-layout 布局自适应
- POJ3311 Hie with the Pie
- Impala:新一代开源大数据分析引擎
- MVC-webervice-webserviceDao
- 强大的vim配置文件,让编程更随意
- html上标与下标应用
- 【浅墨Unity3D Shader编程】之二 雪山飞狐篇:Unity的基本Shader框架写法&颜色、光照与材质