zoukankan      html  css  js  c++  java
  • Hdu 4930 斗地主

      模拟题,只是想纪念下,WA到死了…… 看到好多代码都好长,其实想说不用这么暴力。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <algorithm>
     7 #include <string>
     8 #include <queue>
     9 #include <stack>
    10 #include <vector>
    11 #include <map>
    12 #include <set>
    13 #include <functional>
    14 #include <time.h>
    15 
    16 using namespace std;
    17 
    18 const int INF = 1<<30;
    19 const int MAXN = 22;
    20 
    21 char str[2][MAXN];
    22 int id[256];
    23 int cnt[2][MAXN];
    24 int MAX[2][5];
    25 int tr[2][10];
    26 
    27 bool check() {
    28     int len[2] = {strlen(str[0]), strlen(str[1])};
    29     if (len[0]==0) return true;
    30     memset(cnt, 0, sizeof(cnt));
    31     memset(MAX, 0, sizeof(MAX));
    32     memset(tr, 0, sizeof(tr));
    33 
    34     for (int i = 0; i < 2; i++) //统计每张牌出现的数量
    35         for (int j = 0; j < len[i]; j++)
    36             cnt[i][id[str[i][j]]]++;
    37 
    38     for (int k = 0; k < 2; k++) //找出最大的牌
    39         for (int i = 4; i > 0; i--)
    40             for (int j = 17; j > 0; j--)
    41                 if (cnt[k][j]>=i) {
    42                     MAX[k][i] = j;
    43                     break;
    44                 }
    45     for (int k = 0; k < 2; k++) //3带1、2
    46         for (int i = 1; i < 3; i++)
    47             for (int j = 0; j < 18; j++)
    48                 if (MAX[k][3]>0 && j!=MAX[k][3] && cnt[k][j]>=i)
    49                     tr[k][i] = MAX[k][3];
    50 
    51     if (len[0]<5 && MAX[0][len[0]]>0) return true; //能出完
    52     if (MAX[0][4]>0&&len[0]==6) return true; //4带2
    53     if ((len[0]==4&&tr[0][1]>0)||(len[0]==5&&tr[0][2]>0)) return true; //能出完+1
    54     if (cnt[0][16]>0&&cnt[0][17]>0) return true; //有王炸
    55     if (cnt[1][16]>0&&cnt[1][17]>0) return false; //对方有王炸
    56     if (MAX[0][4]<MAX[1][4]) return false; //对方有炸弹
    57 
    58     for (int i = 4; i > 0; i--)
    59         if (MAX[0][i]>=MAX[1][i] && MAX[0][i]>0) //有大过对方的牌
    60             return true;
    61 
    62     return false;
    63 }
    64 
    65 int main() {
    66     #ifdef Phantom01
    67         freopen("HDU4930.txt", "r", stdin);
    68     #endif //Phantom01
    69 
    70     id['3'] = 3;
    71     id['4'] = 4;
    72     id['5'] = 5;
    73     id['6'] = 6;
    74     id['7'] = 7;
    75     id['8'] = 8;
    76     id['9'] = 9;
    77     id['T'] = 10;
    78     id['J'] = 11;
    79     id['Q'] = 12;
    80     id['K'] = 13;
    81     id['A'] = 14;
    82     id['2'] = 15;
    83     id['X'] = 16;
    84     id['Y'] = 17;
    85 
    86     int T;
    87     scanf("%d", &T);
    88     gets(str[0]);
    89 
    90     while (T--) {
    91         gets(str[0]);
    92         gets(str[1]);
    93         if (check()) puts("Yes");
    94         else puts("No");
    95     }
    96 
    97     return 0;
    98 }
    View Code
  • 相关阅读:
    <转>程序员的心理疾病
    lua与c++ 中布尔布bool值对应关系
    php根据身份证号码计算年龄
    Java中List与Map初始化的一些写法
    在ASP.NET中发送电子邮件的实例教程
    C#中Messagebox.Show()常用参数用法详解
    Js判断CSS文件加载完毕的实例教程
    PHP CURL访问HTTPS使用详解
    下拉导航菜单被遮住解决办法
    Struts2基本包作用详解
  • 原文地址:https://www.cnblogs.com/Phantom01/p/3898801.html
Copyright © 2011-2022 走看看