zoukankan      html  css  js  c++  java
  • 牛客假日团队赛6 A:Card Stacking (模拟)

    链接:https://ac.nowcoder.com/acm/contest/993/A
    来源:牛客网
     

    题目描述

    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.

    输入描述:

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

    输出描述:

    * 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.

    示例1

    输入

    复制

    3 9 2

    输出

    复制

    3
    7
    8

    说明

    Bessie should put the "good" cards in positions 3, 7, and 8. The cards will be dealt as follows; the card numbers are "position in original deck":
    Card Deck         P1      P2    Bessie
    Initial configuration           1 2 3 4 5 6 7 8 9  - - -   - - -   - - -
    Deal top card [1] to Player 1   2 3 4 5 6 7 8 9    1 - -   - - -   - - -
    Top card to bottom (#1 of 2)    3 4 5 6 7 8 9 2    1 - -   - - -   - - -
    Top card to bottom (#2 of 2)    4 5 6 7 8 9 2 3    1 - -   - - -   - - -
    Deal top card [4] to Player 2   5 6 7 8 9 2 3      1 - -   4 - -   - - -
    Top card to bottom (#1 of 2)    6 7 8 9 2 3 5      1 - -   4 - -   - - -
    Top card to bottom (#2 of 2)    7 8 9 2 3 5 6      1 - -   4 - -   - - -
    Deal top card [7] to Bessie     8 9 2 3 5 6        1 - -   4 - -   7 - -
    Top card to bottom (#1 of 2)    9 2 3 5 6 8        1 - -   4 - -   7 - -
    Top card to bottom (#2 of 2)    2 3 5 6 8 9        1 - -   4 - -   7 - -
    Deal top card [2] to Player 1   3 5 6 8 9          1 2 -   4 - -   7 - -
    Top card to bottom (#1 of 2)    5 6 8 9 3          1 2 -   4 - -   7 - -
    Top card to bottom (#2 of 2)    6 8 9 3 5          1 2 -   4 - -   7 - -
    Deal top card [6] to Player 2   8 9 3 5            1 2 -   4 6 -   7 - -
    Top card to bottom (#1 of 2)    9 3 5 8            1 2 -   4 6 -   7 - -
    Top card to bottom (#2 of 2)    3 5 8 9            1 2 -   4 6 -   7 - -
    Deal top card [3] to Bessie     5 8 9              1 2 -   4 6 -   7 3 -
    Top card to bottom (#1 of 2)    8 9 5              1 2 -   4 6 -   7 3 -
    Top card to bottom (#2 of 2)    9 5 8              1 2 -   4 6 -   7 3 -
    Deal top card [9] to Player 1   5 8                1 2 9   4 6 -   7 3 -
    Top card to bottom (#1 of 2)    8 5                1 2 9   4 6 -   7 3 -
    Top card to bottom (#2 of 2)    5 8                1 2 9   4 6 -   7 3 -
    Deal top card [5] to Player 2   8                  1 2 9   4 6 5   7 3 -
    Top card to bottom (#1 of 2)    8                  1 2 9   4 6 5   7 3 -
    Top card to bottom (#1 of 2)    8                  1 2 9   4 6 5   7 3 -
    Deal top card [8] to Bessie     -                  1 2 9   4 6 5   7 3 8
    Bessie will end up with the "good cards" that have been placed in positions 3, 7, and 8 in the original deck.

    题意分析:

    有n个人玩牌,一个k张牌,有k/n张好牌,每次发牌要符合以下规则:

    1.把牌发给右边的人

    2.拿出两张牌放到牌尾

    3.继续发牌

    求把好牌放到什么位置可以让自己拿到所有好牌

    解题思路:

    模拟发牌的次序,因为自己是最后一个拿牌的人,所以记录发出的牌的数量,当发出的牌数量len%n==0

    时是自己的牌,最后在把排队顺序排序输出。

    #include <stdio.h>
    #include <algorithm>
    #include <queue>
    #define N 120000
    using namespace std;
    queue<int>q;
    int a[N];
    int main()
    {
    	int i, n, k, p, l, s, len;
    	scanf("%d%d%d", &n, &k, &p);
    	for(i=1; i<=k; i++)
    		q.push(i);
    	l=0;
    	len=0;
    	while(!q.empty())
    	{
    		s=q.front();
    		q.pop();
    		
    		l++;
    		if(l%n==0)
    			a[len++]=s;
    		if(len==k/n)
    			break;
    		for(i=1; i<=p; i++)
    		{
    			s=q.front();
    			q.pop();
    			q.push(s);
    		}
    	}
    	sort(a, a+len);
    	for(i=0; i<len; i++)
    		printf("%d
    ", a[i]);
    	return 0;
    }
  • 相关阅读:
    Dotfuscator 保护您的应用程序
    IOS 类方法
    播放音乐与视频
    windows phone 手机信息的查看
    更改枢轴视图的Item字的大小
    IOS 总结
    Windows Phone 中HttpWebRequest用法
    关于Listbox的 SelectionChanged 事件 (同一个Item只触发一次问题)
    windows phone 标准色值
    IOS GPS 定位
  • 原文地址:https://www.cnblogs.com/zyq1758043090/p/11852597.html
Copyright © 2011-2022 走看看