BZOJ2798/POI 2012 Bidding

Task
A和B两个人在玩一个游戏,这个游戏是他们轮流操作一对整数(x,y)。
初始时(x,y)=(1,0),可以进行三种操作:
1. 将(x,y)变成(1,x+y)。
2. 将(x,y)变成(2x,y)。
3. 将(x,y)变成(3x,y)。
给定正整数n (n<=30,000),如果x+y>=n时就不能进行后两种操作。
如果某个人操作后y>=n,他就输掉了。
假如A为先手,问他是否有必胜策略。

这题是道交互题,需要包含cliclib.h头文件,有下面三个函数可以使用:
1. int inicjuj(); 开始时调用,返回n的值。
2. void alojzy(int x); A进行一次操作,x表示操作编号。
3. int bajtazar(); 获得B的操作编号。

例如下面的程序每次选择操作1:


#include "cliclib.h"
int main() {
  int n = inicjuj();
  while (true) {
    alojzy(1);
    int x = bajtazar();
  }
  return 0;
}

Solution
对于”我”来说,为了赢交互库,需要每一步都采取最优策略,那么只要求出当前局面的后继局面中那些是必败态即可.
那么只要预处理出每个状态的性质就可以完成任务了.
问题是如何定义状态,x,y都可能很大,数组是存不下的,但是观察游戏的过程可以发现当前的x只可能是2的乘幂与3的乘幂的乘积,也就是
x=2a3b.
那么这样的x就不多了,直接dp即可.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cliclib.h>
#define my_op alojzy
#define he_op bajtazar
using namespace std;
const int M=30005;
const int S2=16,S3=11;
int f2[S2],f3[S3];
bool dp[S2][S3][M];
int inicjuj(){return 0;}
void my_op(int a){};
int he_op(){return 0;}
int main(){
    int i,j,k,n=inicjuj();
    int sum=0,a=0,b=0;
    f2[0]=f3[0]=1;
    for(i=1;i<S2;i++)f2[i]=f2[i-1]*2;
    for(i=1;i<S3;i++)f3[i]=f3[i-1]*3;
    for(k=n;k>=0;k--){
        for(i=S2-1;i>=0;i--){
            for(j=S3-1;j>=0;j--){
                int v=k+f2[i]*f3[j];
                if(v>=n)dp[i][j][k]=false;
                else{
                    int f=0;
                    if(i+1>=S2||j+1>=S3)f|=1;
                    else if(!dp[0][0][v]||!dp[i+1][j][k]||!dp[i][j+1][k])f=1;
                    dp[i][j][k]=f;
                }
            }
        }
    }
    while(true){
        if(a+1>=S2||!dp[a+1][b][sum])my_op(2),a++;
        else if(b+1>=S3||!dp[a][b+1][sum])my_op(3),b++;
        else my_op(1),sum+=f2[a]*f3[b],a=b=0;
        int y=he_op();
        if(y==1){sum+=f2[a]*f3[b];a=b=0;}
        else if(y==2)a++;
        else b++;
    }
    return 0;
} 

Bridge Bidding

12-04

Problem DescriptionnBridge is a very complicated card game, and the bidding part is particularly difficult to master. The bidding is made even more difficult because players use different bidding conventions (meanings assigned to bids). In this problem, you are asked to write a program that suggests the first bid that should be made. The bidding conventions described below are simplified from those used by a certain person who shall remain nameless. nnA bridge hand consists of 13 cards. Each card has a suit (spades, hearts, diamonds, or clubs) and a rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2). Here, the letter T denotes the card whose rank is 10. Before making a bid, an experienced bridge player studies the number of high card points (hcp) in the hand, as well as the distribution (the number of cards in each suit). The hcp contributed by each card is completely determined by its rank as follows: nRank hcpnA 4nK 3nQ 2nJ 1nOthers 0nnFor example, if the hand is: nnSpades: A, 2 nHearts: K, J, T, 9, 2 nDiamonds: 3 nClubs: K, Q, 7, 4, 3 nnThen this hand has 13 hcp and a distribution of 5-5-2-1 (the distribution is usually listed in non-increasing order). A balanced distribution is any one of 4-3-3-3, 4-4-3-2, and 5-3-3-2. nnIn bridge, an opening bid is either "pass" or consists of a level (1-7) and a trump suit. The trump suits are no trump, spades, hearts, diamonds, clubs ranked in decreasing order. Once a hand has been evaluated, the player applies the following list of (simplified) rules to determine the appropriate opening bid. In cases where multiple rules apply, the first one that applies should be used. An "x" in a distribution can be substituted with any non-negative number. Multiple "x"s in a distribution are not necessarily the same. nn1. With at least 10 hcp and a y-x-x-x distribution (y >= 8), bid the suit with y cards at the 4 level. This is known as a preemptive bid. n2. With 10-13 hcp and a 7-x-x-x distribution, bid the suit with 7 cards at the 3-level. This is known as a preemptive bid.n3. With 8-9 hcp and a y-x-x-x distribution (y >= 7), bid the suit with y cards at the 2-level if the y-card suit is Spades or Hearts. This is known as a "weak-two" bid.n4. With 8-11 hcp and a 6-x-x-x distribution, in which Spades or Hearts is one of the 6-card suits, bid the higher rank suit at the 2 level. This is known as a "weak-two" bid.n5. With 11-15 hcp, a distribution of 4-4-4-1 or 5-4-4-0, and at least 4 spades, bid Diamonds at the 2 level. This is called the "Mini Roman Convention".n6. With 15-17 hcp and a balanced distribution, bid No Trump at the 1 level provided that at least 3 suits are "stopped." A suit is considered stopped if the suit contains at least one of the following:nnan A;na K and one other;na Q and two others; orna J and three others;nn7. With 20-22 hcp and a balanced distribution, bid No Trump at the 2 level.n8.With at least 22 hcp, bid Clubs at the 2 level.n9. With 13-16 hcp:na. If there is a 5-card or longer suit in Spades or Hearts, bid it at the 1 level. If both bids are possible, bid the longer suit. If both suits have the same length, bid the higher ranking suit.nb. Without a 5-card suit in Spades or Hearts, bid the longer of Diamonds or Clubs at the 1 level (whichever one has the most number of cards) . If there is a tie, bid the higher ranking suit.nn10. With at least 17 hcp, bid the longest suit at the 1 level. If there is a tie, bid the lowest ranking suit. This is known as a "reverse".n11. If none of the rules above is applicable, bid Pass.nnIn the example above, rule 9a applies and a bid of 1 Hearts should be made.n nnInputnThe input consists of a number of cases. The bridge hand for each case is specified on one line, with a single space separating each of the 13 cards in the hand. Each card is given as a two-character string. The first letter is the suit (S, H, D, C) and the second character is the rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2). The end of input is terminated by end-of-file. nn nnOutputnFor each case, print the hand number (starting from 1), followed by a colon and a space, and then the suggested bid on a single line (see below for the exact format). Each bid is either "Pass" or a level and a suit ("No Trump", "Spades", "Hearts", "Diamonds", "Clubs") separated by a single space. nn nnSample InputnSA S2 HK HJ HT H9 H2 D3 CK CQ C7 C4 C3nSK SQ HT H8 H4 CA CQ CT C5 DK DQ DJ D8nSA SK SQ S3 S2 HT D7 D9 CA CK CQ C7 C5n nnSample OutputnHand #1: 1 HeartsnHand #2: 1 No TrumpnHand #3: 1 Clubs 问答

没有更多推荐了,返回首页