zoukankan      html  css  js  c++  java
  • POJ-3629

    Card Stacking
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3927   Accepted: 1541

    Description

    Bessie is playing a card game with her N-1 (2 ≤ N ≤ 100) cow friends using a deck with K (N ≤ K ≤ 100,000; K is a multiple of N) cards. The deck contains M = K/N "good" cards and K-M "bad" cards. Bessie is the dealer and, naturally, wants to deal herself all of the "good" cards. She loves winning.

    Her friends suspect that she will cheat, though, so they devise a dealing system in an attempt to prevent Bessie from cheating. They tell her to deal as follows:

    1. Start by dealing the card on the top of the deck to the cow to her right

    2. Every time she deals a card, she must place the next P (1 ≤ P ≤ 10) cards on the bottom of the deck; and

    3. Continue dealing in this manner to each player sequentially in a counterclockwise manner

    Bessie, desperate to win, asks you to help her figure out where she should put the "good" cards so that she gets all of them. Notationally, the top card is card #1, next card is #2, and so on.

    Input

    * Line 1: Three space-separated integers: NK, and P

    Output

    * Lines 1..M: Positions from top in ascending order in which Bessie should place "good" cards, such that when dealt, Bessie will obtain all good cards.

    Sample Input

    3 9 2

    Sample Output

    3
    7
    8

    题意:

    Bessie跟朋友玩牌,总共n人k张牌,k是n的整数倍。k张牌中共有k/n张好牌,Bessie想要作弊得到所有好牌。可Bessie的同伴为了防止Bessie作弊而设定了如下规则:

    1.每次发牌从牌顶发,从Bessie右手边第一个人开始。

    2.每发出一张牌就要将接下来的p张牌依次放至牌底。

    按照这个方法发完所有牌。即使是这样,Bessie依然想要拿到所有好牌,请你帮她计算出将好牌放在哪些位置可以实现Bessie的愿望。

    用队列可以很方便的解决这个问题,将所有k张牌入队,发牌即为出队,过牌即出队后再入队,每循环到Bessie时将队首元素记录下来,即为好牌位置。

    附AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string>
     4 #include<algorithm>
     5 #include<queue>
     6 using namespace std;
     7 
     8 const int MAX=50500;
     9 
    10 int ans[MAX];
    11 int main(){
    12     int n,k,p;
    13     queue<int> q;//定义队列 
    14     memset(ans,0,sizeof(ans));
    15     while(~scanf("%d %d %d",&n,&k,&p)){
    16         for(int i=1;i<=k;i++){//入队 
    17             q.push(i);
    18         }
    19         int temp=1,sum=0;
    20         while(1){
    21             if(temp++%n==0){//temp从1开始每循环至Bessie处则为好牌 
    22                 ans[sum++]=q.front();
    23                 if(sum==k/n){//好牌放完则退出循环 
    24                     break;
    25                 }
    26             }
    27             q.pop();//发出的牌出队 
    28             for(int i=0;i<p;i++){//其他牌移到牌底 
    29                 q.push(q.front());
    30                 q.pop();
    31             } 
    32         }
    33         sort(ans,ans+sum);
    34         for(int i=0;i<sum;i++){
    35             printf("%d
    ",ans[i]);
    36         }
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    KeBugCheckEx0xD1
    Ti DSP编程入门
    动态链接库
    Hello,world! x86版本
    用回调函数联系两个模块
    DataGrid模版列超级链接列传递参数问题总结(多个参数传递)
    后台代码里执行弹出脚本方法!(Response.Write)
    Oracle数据导入导出imp/exp
    安装sql2000: 出现 A previous program installation created pending file operations on the installation machine. You must restart the computer before running setup
    解决问题:  An unhandled exception of type 'System.Exception' occurred in system.data.oracleclient.dll
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5523548.html
Copyright © 2011-2022 走看看