Joseph

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2453    Accepted Submission(s): 1476

Problem Description
The
Joseph's problem is notoriously known. For those who are not familiar
with the original problem: from among n people, numbered 1, 2, . . ., n,
standing in circle every mth is going to be executed and only the life
of the last remaining person will be saved. Joseph was smart enough to
choose the position of the last remaining person, thus saving his life
to give us the message about the incident. For example when n = 6 and m =
5 then the people will be executed in the order 5, 4, 6, 2, 3 and 1
will be saved.

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.

 
Input
The
input file consists of separate lines containing k. The last line in
the input file contains 0. You can suppose that 0 < k < 14.
 
Output
The output file will consist of separate lines containing m corresponding to k in the input file.
 
Sample Input
3
4
0
 
Sample Output
5
30
 
Source
题意:
给出2*n个数串成环,找出一个k使得每隔k个数就去掉一个数,要去掉后n个数的情况下的最小的k。
代码:
 /*
用数组和链表写的两个,费了一晚上时间一直超时。数据只有13个最后只能先跑出来数据再打表提交15S水过去。然而怎么就忘了把这两步合在一起呢?
真是糊涂了。
*/
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int linklt_point[];
int ans[];
int t;
for(int n=;n<;n++)
{
if(n==) break;
for(int i=n+;;i++)
{
if(i%(*n)!=&&i%(*n)<=n)
continue;
for(int j=;j<*n;j++)
{
linklt_point[j]=j+;
}
linklt_point[*n]=;
int sta=,pre=*n;
int sum=;
int m=*n;
while()
{
int k=i%m;
if(k==) k=m;
for(int j=;j<k;j++)
{
pre=sta;
sta=linklt_point[sta];
}
if(sta<=n)
break;
linklt_point[pre]=linklt_point[sta];
sta=linklt_point[sta];
sum++;
m--;
if(sum==n)
break;
}
if(sum==n)
{
ans[n]=i;
break;
}
}
}
while(scanf("%d",&t)&&t!=)
{
printf("%d\n",ans[t]);
}
return ;
} #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a[];
int n;
int ans[];
for(int t=;t<;t++)
{
for(int i=t+;;i++)
{
for(int j=;j<=*t;j++)
a[j]=;
int sta=;
int sum=;
int m=*t;
while()
{
int k=i%m;
if(k==) k=m;
int l=;
while(l!=k)
{
sta++;
if(sta==*t+)
sta=;
if(a[sta]==)
l++;
}
if(sta<=t)
break;
m--;
a[sta]=;
sum++;
if(sum==t)
break;
}
if(sum==t)
{
ans[t]=i;
break;
}
}
}
while(scanf("%d",&n)&&n!=)
{
printf("%d\n",ans[n]);
}
return ;
}

HDU1443 模拟(难)的更多相关文章

  1. Codeforces Round #523 (Div. 2) D. TV Shows 模拟(多重集 先把所有区间加入多重集合)+贪心+二分

    题意:给出n个电视节目的起始和结束时间  并且租一台电视需要x +y*(b-a)  [a,b]为时段 问完整看完电视节目的最小花费是多少 思路:贪心的思想 情况1 如果新租一台电视的花费<=在空 ...

  2. [考试反思]1026csp-s模拟测试88:发展

    不用你们说,我自己来:我颓闪存我没脸. 昨天的想法, 今天的回答. 生存, 发展. 总分榜应该稍有回升,但是和上面的差距肯定还是很大. 继续. 为昨天的谬误,承担代价. T2和T3都值得张记性. T2 ...

  3. 【模拟】【HDU1443】 Joseph

    Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  4. PAT 1139 First Contact[难][模拟]

    1139 First Contact(30 分) Unlike in nowadays, the way that boys and girls expressing their feelings o ...

  5. What?废柴, 模拟登陆,代码控制滑动验证真的很难吗?Are you kidding???

    1.简介 在前边的python接口自动化的时候,我们由于博客园的登录机制的改变,没有用博客园的登录测试接口.那么博客园现在变成了滑动验证登录,而且现在绝大多数的登录都变成这种滑动验证和验证码的登录验证 ...

  6. PAT 1105 Spiral Matrix[模拟][螺旋矩阵][难]

    1105 Spiral Matrix(25 分) This time your job is to fill a sequence of N positive integers into a spir ...

  7. PAT 1088 Rational Arithmetic[模拟分数的加减乘除][难]

    1088 Rational Arithmetic(20 分) For two rational numbers, your task is to implement the basic arithme ...

  8. CF 1005B Delete from the Left 【模拟数组操作/正难则反】

    You are given two strings s and t. In a single move, you can choose any of two strings and delete th ...

  9. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

随机推荐

  1. python-logging-日志系统

    有时候需要记录日志,典型的出现在web程序或者服务器中,需要与正在运行的程序交互或者得知里面正在运行的信息 最近在倒腾webservice,使用spyne模块进行打包服务,很多实例代码也都用到了这个l ...

  2. WebAPI接口调用身份验证

    Common public interface ICacheWriter { void AddCache(string key, object value, DateTime expDate); vo ...

  3. 【微信Java开发 --2】接入微信公众平台开发,配置自己的服务器,验证过程

    接入微信公众平台开发,开发者需要按照如下步骤完成: 1.填写服务器配置 2.验证服务器地址的有效性 3.依据接口文档实现业务逻辑好我们就开始:1.填写好我们的URL和Token[此处是已经通过验证的] ...

  4. background为圆角的表框,dp转Px,Px转dp

    圆角边框<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="ht ...

  5. CSS3详解:background

    CSS3对于background做了一些修改,最明显的一个就是采用设置多背景,不但添加了4个新属性,并且还对目前的属性进行了调整增强. 1.多个背景图片 在css3里面,你可以再一个标签元素里应用多个 ...

  6. SpringMVC解析3-DispatcherServlet组件初始化

    在spring中,ContextLoaderListener只是辅助功能,用于创建WebApplicationContext类型实例,而真正的逻辑实现其实是在DispatcherServlet中进行的 ...

  7. css之overflow:细探之下有意想不到的结果

    overflow 是一个非常常用的 CSS 属性,一般来说会认为很简单,其实细究之后就会发现他还有很多小特性或者说意想不到的结果: 下面就介绍下(在浏览器环境下)关于 overflow 的小总结. 哪 ...

  8. [工作中的设计模式]观察者模式observer

    一.模式解析 观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 观察者模式又叫订阅发布模式, ...

  9. delphi 对Tmemo指定的行写入

    mmoMonitor:Tmemo; mmoMonitor.Lines.ValueFromIndex[0]:=aInfo ; procedure TMainForm.LogInfo(aInfo: str ...

  10. ZJOI2016 Round 1 之前

    day 0 中午要出发了,很虚.. 主要原因: 1.在转语言 2.模板还没有系统整理过 3.最近代码能力感觉要狗带 4.急于想为联赛翻盘... MARK几个未完成的任务 1.字符串处理再去看看..实在 ...