zoukankan      html  css  js  c++  java
  • hdu-4023-博弈(模拟)

    Game

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
    Total Submission(s): 1238    Accepted Submission(s): 432


    Problem Description
    Alice and Bob are playing game with each other. They play the game on a 2D board. Alice has many vertical 1*2 tiles while Bob has many horizontal 2*1 tiles. They take turn to place their own tiles on the board. Considering about that the tiles cannot overlap each other, the player cannot do the placement any more loses. Since this is such a complex game that they could not find optimal method to play that, Alice decide to simplify this game by replace the large 2D board by some small ones. Alice set up a lot of Tetris tiles instead of the original 2D board. In the other words, the player can only place their own vertical or horizontal tiles on the Tetris-like board. Each player can choose one possible place on any Tetris tiles to place its own tiles. In fact, there are following 15 types of Tetris playground.

    The playground cannot be transformed in any ways, including reflection and rotation.
    Given the number of each type of tiles, you are asked to determine who will win the game if Alice plays first and both players are playing optimal.
     
    Input
    There are multiple test cases; the first line of input contains a single integer denoting the number of test cases.
    For each test case, there are only one line contains 15 integers denoting the number of Tetris tiles of the above 15 types. All the numbers are no greater than 100.
     
    Output
    For each test cases, output “Alice” if Alice will win the game and both player plays optimally, “Bob” otherwise.
     
    Sample Input
    3 5 4 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 100 100 0 0 0 0 0 0 0 0 0 2 1 0 0
     
    Sample Output
    Case #1: Alice Case #2: Bob Case #3: Alice
     
    Source
     
      其实方法还是不难想的,由于数据不大可以模拟博弈过程,我们只要知道对于每一方,先占领那种砖块对自己更有利就可以直接模拟了,最后统计一下各自剩余步数就好了。
      对于Alice,(15)>(3,4,5,6)>(11,12,13,14)>(7,8)>(9,10)
      对于Bob,(15)>(3,4,5,6)>(11,12,13,14)>(9,10)>(7,8)
      1 #include<bits/stdc++.h>
      2 using namespace std;
      3 int num[15];
      4 int main(){
      5     int t,i,j,k,n,m;
      6     cin>>t;
      7     for(int cas=1;cas<=t;++cas){
      8         int tot1=0,tot2=0;
      9         bool op=0,ok=1;
     10         for(i=0;i<15;++i) cin>>num[i];
     11         tot1+=num[0]*2,num[0]=0;
     12         tot2+=num[1]*2,num[1]=0;
     13         while(ok){
     14             if(op==0){
     15                 if(num[14]){
     16                     num[14]--;
     17                     tot1++;
     18                 }
     19                 else if(num[2]){
     20                     num[2]--;
     21                 }
     22                 else if(num[3]){
     23                     num[3]--;
     24                 }
     25                 else if(num[4]){
     26                     num[4]--;
     27                     tot1++;
     28                 }
     29                 else if(num[5]){
     30                     num[5]--;
     31                     tot1++;
     32                 }
     33                 else if(num[10]){
     34                     num[10]--;
     35                 }
     36                 else if(num[11]){
     37                     num[11]--;
     38                 }
     39                 else if(num[12]){
     40                     num[12]--;
     41                 }
     42                 else if(num[13]){
     43                     num[13]--;
     44                 }
     45                 else if(num[6]){
     46                     num[6]--;
     47                 }
     48                 else if(num[7]){
     49                     num[7]--;
     50                 }
     51                 else if(num[8]){
     52                     num[8]--;
     53                     tot2++;
     54                 }
     55                 else if(num[9]){
     56                     num[9]--;
     57                     tot2++;
     58                 }
     59                 else if(tot1){
     60                     tot1--;
     61                 }
     62                 else{
     63                     break;
     64                 }
     65                 op=1;
     66             }
     67             else{
     68             if(num[14]){
     69                     num[14]--;
     70                     tot2++;
     71                 }
     72                 else if(num[2]){
     73                     num[2]--;
     74                     tot2++;
     75                 }
     76                 else if(num[3]){
     77                     num[3]--;
     78                     tot2++;
     79                 }
     80                 else if(num[4]){
     81                     num[4]--;
     82                 }
     83                 else if(num[5]){
     84                     num[5]--;
     85                 }
     86                 else if(num[10]){
     87                     num[10]--;
     88                 }
     89                 else if(num[11]){
     90                     num[11]--;
     91                 }
     92                 else if(num[12]){
     93                     num[12]--;
     94                 }
     95                 else if(num[13]){
     96                     num[13]--;
     97                 }
     98                 else if(num[8]){
     99                     num[8]--;
    100                     
    101                 }
    102                 else if(num[9]){
    103                     num[9]--;
    104                 }
    105                 
    106                 else if(num[6]){
    107                     num[6]--;
    108                     tot1++;
    109                 }
    110                 else if(num[7]){
    111                     num[7]--;
    112                     tot1++;
    113                 }
    114                 else if(tot2){
    115                     tot2--;
    116                 }
    117                 else{
    118                     break;
    119                 }
    120                 op=0;
    121             }
    122         }
    123         printf("Case #%d: ",cas);
    124         if(op) tot2--;
    125         tot1>tot2?puts("Alice"):puts("Bob");
    126     }
    127     return 0;
    128 }
  • 相关阅读:
    delphi idhttpserver ajax 跨域解决方法
    【转】安卓apk反编译(三件套) (com.googlecode.d2j.DexException: not support version问题解决)
    C++ volatile的作用
    GetProcAddress函数
    c++ CArray函数
    CString中TrimLeft()与TrimRight()的用法
    使用Windows API进行串口编程
    SetCommMask
    AttachThreadInput
    关于CoInitialize和CoUninitialize调用的有关问题
  • 原文地址:https://www.cnblogs.com/zzqc/p/9350986.html
Copyright © 2011-2022 走看看