Joseph(hdu1443)
Joseph
Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy.
34 0
530 思路:一开始看到数据很小,打表写的用vector容器模拟,这样模拟肯定超时,但由于只到13,所以,把数据打出来直接上表。 另一种方法是只记录好人的开头和结尾,然后每次出一个人就更新开头和结尾,如果出来的人在头和尾之间就不可行。 关键是更新开头和结尾: head=((((head-(p+1)%i)+1+i))%i); wei=((((wei-(p+1)%i)+i+1))%i);(p+1)%i为去掉前面的数,然后开始的第一个数的原下标,然后算出head,与原下标之间的距离 (head-(p+1)%i+i)%i,因为新的开头为1,所以加1就为当前标号head=((((head-(p+1)%i)+1+i))%i);1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string.h> 5 #include<math.h> 6 #include<vector> 7 void run(); 8 using namespace std; 9 vector<int>my; int yy[14];10 int main(void)11 {12 int n,i,j,k,p,q;run();13 while(scanf("%d",&p),p!=0)14 {15 printf("%d\n",yy[p]);16 }17 return 0;18 }19 void run()20 {21 22 int n,i,j,k,p,q;23 for(k=1;k<14;k++)24 {25 for(j=k+1;; j++)26 {27 int head=1;28 int wei=k;29 int sum=0;30 for(i=2*k; i>=1; i--)31 { p=(j)%i;32 if(p==0)33 p=i;34 if(p>=head&&p<=wei)35 break;36 sum++;37 head=((((head-(p+1)%i)+1+i))%i);38 wei=((((wei-(p+1)%i)+i+1))%i);39 if(head==0)head=i-1;40 if(wei==0)wei=i-1;41 }42 if(sum==k)43 break;44 }45 yy[k]=j;46 }47 }
Joseph(hdu1443)的更多相关文章
- 【模拟】【HDU1443】 Joseph
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- Joseph(JAVA版)
package Joseph;//约瑟夫环,m个人围成一圈.从第K个人开始报数,报道m数时,那个人出列,以此得到出列序列//例如1,2,3,4.从2开始报数,报到3剔除,顺序为4,3,1,2publi ...
- HDU1443 模拟(难)
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Hdu 1443 Joseph
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 一道模拟题:改进的Joseph环
题目:改进的Joseph环.一圈人报数,报数上限依次为3,7,11,19,循环进行,直到所有人出列完毕. 思路:双向循环链表模拟. 代码: #include <cstdio> #inclu ...
- POJ 1012 Joseph
Joseph Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44650 Accepted: 16837 Descript ...
- poj1012.Joseph(数学推论)
Joseph Time Limit: 1 Sec Memory Limit: 64 MB Submit: 493 Solved: 311 Description The Joseph's prob ...
- hdu 1443 Joseph (约瑟夫环)
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- UVa 1363 (数论 数列求和) Joseph's Problem
题意: 给出n, k,求 分析: 假设,则k mod (i+1) = k - (i+1)*p = k - i*p - p = k mod i - p 则对于某个区间,i∈[l, r],k/i的整数部分 ...
随机推荐
- Requests的安装和使用
一.Requests的安装1.pip3 install requests2.验证 import requests 不报错即可
- Scala(五)【集合的高级使用】
目录 一.集合属性 size length contains mkString 二.集合方法 drop.dropRight distinct:去重 head.last:获取第一个.最后一个元素 tai ...
- 【原创】Altium生成Gerber时跳出The Film is too small for this PCB的解决办法
在用altium Designer画板子的时候,要生成gerber文件的时候,会出错,出现这样的提示框:"The Film is too small for this PCB" 原 ...
- C++之数组转换
题目如下: 这道题经过好久的思考也没找到能一次性输入两组数的方法,只能一次性处理一组数,所以就把代码放上来,欢迎交流留言一起讨论可以放两组数的方法~(QQ 841587906) 1 #include ...
- 复制virtualbox虚拟硬盘
D:\VirtualBox\VBoxManage.exe clonevdi F:\virtualbox\rac1\rac1.vdi F:\virtualbox\rac2\rac2.vdi 虚拟机软件安 ...
- Mybatis-运行原理
一.mybatis分层图 二.运行流程 根据全局配置文件创建sqlSessionFactory对象 根据全局配置文件的io流来构建SqlSessionFactoryBuilder对象: 解析(XmlC ...
- vue-cli4脚手架搭建二
vue-cli4脚手架搭建一 vue create vue3 cd vue3 yarn serve http://localhost:8080/#/ main.js文件 import Vue from ...
- Function overloading and return type
In C++ and Java, functions can not be overloaded if they differ only in the return type. For example ...
- 【Java 8】Stream中的Pipeline理解
基于下面一段代码: public static void main(String[] args) { List<String> list = Arrays.asList("123 ...
- DevOps到底是什么意思?
目录 一.方法论 二.DevOps的起源 三.DevOps到底是什么 四.DevOps的发展现状 五.DevOps与虚拟化.容器.微服务 一.方法论 提到DevOps这个词,我相信很多人一定不会陌生. ...