POJ 1591 M*A*S*H 水模拟
来源:互联网 发布:软件开发立项 编辑:程序博客网 时间:2024/05/16 07:35
Language:
M*A*S*H
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 977 Accepted: 518
Description
Corporal Klinger is a member of the 4077th Mobile Army Surgical Hospital in the Korean War; and he will do just about anything to get out. The U.S. Army has made an offer for a lottery that will choose some number of lucky people (X) to return to the states for a recruiting tour. Klinger needs your help getting out.
The lottery is run by lining up all the members of the unit at attention and eliminating members by counting off the members from 1 to N where N is a number chosen by pulling cards off of the top of a deck. Every time N is reached, that person falls out of the line, and counting begins again at 1 with the next person in line. When the end of the line has been reached (with whatever number that may be), the next card on the top of the deck will be taken, and counting starts again at 1 with the first person in the remaining line. The last X people in line get to go home.
Klinger has found a way to trade a stacked deck with the real deck just before the selection process begins. However, he will not know how many people will show up for the selection until the last minute. Your job is to write a program that will use the deck Klinger supplies and the number of people in line that he counts just before the selection process begins and tell him what position(s) in the line to get in to assure himself of a trip home. You are assured that Klinger's deck will get the job done by the time the 20th card is used.
A simple example with 10 people, 2 lucky spots, and the numbers from cards 3, 5, 4, 3, 2 would show that Klinger should get in positions 1 or 8 to go home.
The lottery is run by lining up all the members of the unit at attention and eliminating members by counting off the members from 1 to N where N is a number chosen by pulling cards off of the top of a deck. Every time N is reached, that person falls out of the line, and counting begins again at 1 with the next person in line. When the end of the line has been reached (with whatever number that may be), the next card on the top of the deck will be taken, and counting starts again at 1 with the first person in the remaining line. The last X people in line get to go home.
Klinger has found a way to trade a stacked deck with the real deck just before the selection process begins. However, he will not know how many people will show up for the selection until the last minute. Your job is to write a program that will use the deck Klinger supplies and the number of people in line that he counts just before the selection process begins and tell him what position(s) in the line to get in to assure himself of a trip home. You are assured that Klinger's deck will get the job done by the time the 20th card is used.
A simple example with 10 people, 2 lucky spots, and the numbers from cards 3, 5, 4, 3, 2 would show that Klinger should get in positions 1 or 8 to go home.
Input
For each selection, you will be given a line of 22 integers. The first integer (1 <= N <= 50) tells how many people will participate in the lottery. The second integer (1 <= X <= N) is how many lucky "home" positions will be selected. The next 20 integers are the values of the first 20 cards in the deck. Card values are interpretted to integer values between 1 and 11 inclusive.
Output
For each input line, you are to print the message ``Selection #A" on a line by itself where A is the number of the selection starting with 1 at the top of the input file. The next line will contain a list of ``lucky" positions that Klinger should attempt to get into. The list of ``lucky" positions is then followed by a blank line.
Sample Input
10 2 3 5 4 3 2 9 6 10 10 6 2 6 7 3 4 7 4 5 3 247 6 11 2 7 3 4 8 5 10 7 8 3 7 4 2 3 9 10 2 5 3
Sample Output
Selection #1 1 8 Selection #2 1 3 16 23 31 47
Source
South Central USA 1995
ACcode:
ACcode:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ int del[55]; int n,x; int card[21]; int loop=0; while(scanf("%d %d",&n,&x)!=EOF){ memset(del,0,sizeof(del)); for(int i=0;i<20;++i)scanf("%d",&card[i]); printf("Selection #%d\n",++loop); int pos=0,p=n,i,count; while(p>x){ for(i=1,count=0;i<=n;++i){ if(del[i]==0)count++; if(count==card[pos]){ del[i]=1; count=0; p--; } if(p<=x)break; } pos++; } for(i=1,count=1;count<x;++i) if(del[i]==0){ printf("%d ",i); count++; } while(i<=n){ if(del[i]==0){ printf("%d\n",i); break; } i++; } putchar('\n'); } return 0;}
0 0
- POJ 1591 M*A*S*H 水模拟
- POJ 1591 M*A*S*H
- poj-1591-M*A*S*H
- 1591 M*A*S*H
- 杭电 1591 M*A*S*H
- POJ1591 M*A*S*H
- (顺序表的应用5.4.2)POJ 1591 M*A*S*H(约瑟夫环问题的变形——变换步长值)
- UVa 402 M*A*S*H (STL&list)
- A, S, M模式
- N o v e m b e r 8 t h T h u r s d a y
- N o v e m b e r 2 9 t h T h u r s d a y
- S.M.A.R.T.
- p a r e n t . f r a m e s . l e n g t h
- I N T E R V I E W S W I T H T H E V A M P I R E S 1
- I N T E R V I E W S W I T H T H E V A M P I R E S 2
- H-Updating a Dictionary (模拟)
- H - A Knight's Journey
- 模拟实现一个printf,函数可以实现my_printf("s ccc.","hello", 'n','i','h','a','o');//遇到s表示字符串
- 英语介词用法
- 最小费用最大流
- HDU 5399 Too Simple (2015年多校比赛第9场)
- Struts2 国际化
- 数据结构之---C语言实现最短路径之Dijkstra(迪杰斯特拉)算法
- POJ 1591 M*A*S*H 水模拟
- 通知
- 《断舍离》笔记二
- 存在即更新反之插入的三种防唯一键冲突和死锁的写法
- [leetcode-142]Linked List Cycle II(c)
- Android (小纸条便签问题记录)使用layout方法导致被父View遮挡问题
- GDOI2016模拟8.18总结
- unity3d 关于游戏暂停
- C语言实现直接插入排序,冒泡排序以及二分查找(巩固理解记忆)