首页 > 代码库 > HDU 4930 Fighting the Landlords(扯淡模拟题)
HDU 4930 Fighting the Landlords(扯淡模拟题)
Fighting the Landlords
大意:
斗地主。。。。 分别给出两把手牌,肯定都合法。每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3。
给你8种组合:1.单牌:一张牌
2.对子:两张相同的牌
3.三重奏(百度翻译出来的。。):三张相同的牌
4.三带一:三张相同的带一张牌(大小只考虑前面的牌,不考虑带的)
5.三带二:三张相同的带两张牌,带的两张牌可以一样,也可以不一样(大小只考虑前面的牌,不考虑带的)
6.四带二:四个相同的带两张牌,带的两张牌可以一样,也可以不一样(大小只考虑前面的牌,不考虑带的)
7.炸弹:四个相同的一起出,不带任何东西(能管除了核弹所有的)
8.核弹:大小王一起(能管所有的牌)
然后规则其实很简单,就是你先出,如果你出了之后,手牌没有了,输出Yes,或者你出了之后,对方没有比你出的这一把大的,也输出Yes,剩下就是输出No了。。。
思路:
比赛的时候一直卡1007,T到死。。。。 也没来的及管这个题。。其实不难。。
主要注意几个坑的地方就行:
1.不能四带一。
2.炸弹可以干掉四带二
3.理解好题意什么时候输出Yes
发这篇博客的目的不是粘代码,代码写的实在是太挫了。。。。 要看的话只看题目描述吧。。。。就是想记录一下这个题-。- 我好无聊~
1 #include <stdio.h> 2 #include <string.h> 3 4 int Hash1[20], Hash2[20]; 5 int T; 6 char s1[20], s2[20]; 7 8 int main() 9 { 10 scanf("%d", &T); 11 while(T--){ 12 memset(Hash1, 0, sizeof(Hash1)); 13 memset(Hash2, 0, sizeof(Hash2)); 14 scanf("%s", s1); 15 int len1 = strlen(s1); 16 for(int i = 0; i < len1; ++i){ 17 if(s1[i] >= ‘3‘ && s1[i] <= ‘9‘){ 18 Hash1[s1[i]-‘0‘]++; 19 } 20 else if(s1[i] == ‘T‘){ 21 Hash1[10]++; 22 } 23 else if(s1[i] == ‘J‘){ 24 Hash1[11]++; 25 } 26 else if(s1[i] == ‘Q‘){ 27 Hash1[12]++; 28 } 29 else if(s1[i] == ‘K‘){ 30 Hash1[13]++; 31 } 32 else if(s1[i] == ‘A‘){ 33 Hash1[14]++; 34 } 35 else if(s1[i] == ‘2‘){ 36 Hash1[15]++; 37 } 38 else if(s1[i] == ‘X‘){ 39 Hash1[16]++; 40 } 41 else if(s1[i] == ‘Y‘){ 42 Hash1[17]++; 43 } 44 } 45 // for(int i = 3; i <= 17; ++i){ 46 // printf("%d ", Hash1[i]); 47 // } 48 scanf("%s", s2); 49 int len2 = strlen(s2); 50 for(int i = 0; i < len2; ++i){ 51 if(s2[i] >= ‘3‘ && s2[i] <= ‘9‘){ 52 Hash2[s2[i]-‘0‘]++; 53 } 54 else if(s2[i] == ‘T‘){ 55 Hash2[10]++; 56 } 57 else if(s2[i] == ‘J‘){ 58 Hash2[11]++; 59 } 60 else if(s2[i] == ‘Q‘){ 61 Hash2[12]++; 62 } 63 else if(s2[i] == ‘K‘){ 64 Hash2[13]++; 65 } 66 else if(s2[i] == ‘A‘){ 67 Hash2[14]++; 68 } 69 else if(s2[i] == ‘2‘){ 70 Hash2[15]++; 71 } 72 else if(s2[i] == ‘X‘){ 73 Hash2[16]++; 74 } 75 else if(s2[i] == ‘Y‘){ 76 Hash2[17]++; 77 } 78 } 79 // for(int i = 3; i <= 17; ++i){ 80 // printf("%d ", Hash2[i]); 81 // } 82 if(Hash1[16] == 1 && Hash1[17] == 1){ 83 printf("Yes\n"); 84 continue; 85 } 86 87 ///clear 88 int cnt = 0; 89 for(int i = 3; i <= 17; ++i){ 90 if(Hash1[i] > 0){ 91 cnt++; 92 } 93 } 94 if(cnt == 1){ 95 printf("Yes\n"); 96 continue; 97 } 98 else if(cnt == 2){ 99 int t1 = 0, t2 = 0;100 for(int i = 3; i <= 17; ++i){101 if(Hash1[i] > 0){102 if(t1 == 0){103 t1 = i;104 }105 else {106 t2 = i;107 }108 }109 }110 if(Hash1[t1] == 3 && Hash1[t2] == 1){111 printf("Yes\n");112 continue;113 }114 if(Hash1[t2] == 3 && Hash1[t1] == 1){115 printf("Yes\n");116 continue;117 }118 if(Hash1[t1] == 3 && Hash1[t2] == 2){119 printf("Yes\n");120 continue;121 }122 if(Hash1[t2] == 3 && Hash1[t1] == 2){123 printf("Yes\n");124 continue;125 }126 if(Hash1[t1] == 4 && Hash1[t2] == 2){127 printf("Yes\n");128 continue;129 }130 if(Hash1[t2] == 4 && Hash1[t1] == 2){131 printf("Yes\n");132 continue;133 }134 }135 else if(cnt == 3){136 int t1 = 0, t2 = 0, t3 = 0;137 for(int i = 3; i <= 17; ++i){138 if(Hash1[i] > 0){139 if(t1 == 0){140 t1 = i;141 }142 else if(t2 == 0){143 t2 = i;144 }145 else {146 t3 = i;147 }148 }149 }150 if(Hash1[t1] == 4 && Hash1[t2] == 1 && Hash1[t3] == 1){151 printf("Yes\n");152 continue;153 }154 else if(Hash1[t1] == 1 && Hash1[t2] == 4 && Hash1[t3] == 1){155 printf("Yes\n");156 continue;157 }158 else if(Hash1[t1] == 1 && Hash1[t2] == 1 && Hash1[t3] == 4){159 printf("Yes\n");160 continue;161 }162 }163 164 165 if(Hash2[16] == 1 && Hash2[17] == 1){166 printf("No\n");167 continue;168 }169 170 bool flag = false;171 ///bomb172 for(int i = 15; i >= 3; --i){173 if(Hash1[i] == 4){174 int j;175 for(j = i+1; j <= 15; ++j){176 if(Hash2[j] == 4){177 break;178 }179 }180 if(j == 16){181 flag = true;182 }183 }184 }185 if(flag){186 printf("Yes\n");187 continue;188 }189 190 ///Four-Dual191 for(int i = 15; i >= 3; --i){192 if(Hash1[i] == 4 && len1 >= 6){193 int j;194 for(j = i+1; j <= 15; ++j){195 if(Hash2[j] == 4 && len2 >= 6){196 break;197 }198 }199 int k;200 for(k = 3; k <= 15; ++k){201 if(Hash2[k] == 4){202 break;203 }204 }205 if(j == 16 && k == 16){206 flag = true;207 //printf("Four-Dual\n");208 }209 }210 }211 if(flag){212 printf("Yes\n");213 continue;214 }215 216 ///Trio-Pair217 for(int i = 15; i >= 3; --i){218 if(Hash1[i] == 3){219 for(int j = 3; j <= 15; ++j){220 if(Hash1[j] == 2){221 int k;222 int t = 0;223 for(k = i+1; k <= 15; ++k){224 if(Hash2[k] == 3){225 for(int l = 3; l <= 15; ++l){226 if(Hash2[l] == 2){227 t = 1;228 break;229 }230 }231 if(t == 1){232 break;233 }234 }235 }236 int p;237 for(p = 3; p <= 15; ++p){238 if(Hash2[p] == 4){239 break;240 }241 }242 if(k == 16 && p == 16){243 flag = true;244 //printf("Trio-Pair\n");245 }246 }247 }248 }249 }250 if(flag){251 printf("Yes\n");252 continue;253 }254 255 ///Trio-Solo256 for(int i = 15; i >= 3; --i){257 if(Hash1[i] == 3 && len1 >= 4){258 int j;259 for(j = i+1; j <= 15; ++j){260 if(Hash2[j] == 3 && len2 >= 4){261 break;262 }263 }264 int k;265 for(k = 3; k <= 15; ++k){266 if(Hash2[k] == 4){267 break;268 }269 }270 if(j == 16 && k == 16){271 flag = true;272 //printf("Trio-Solo\n");273 }274 }275 }276 if(flag){277 printf("Yes\n");278 continue;279 }280 281 ///Trio282 for(int i = 15; i >= 3; --i){283 if(Hash1[i] == 3){284 int j;285 for(j = i+1; j <= 15; ++j){286 if(Hash2[j] >= 3){287 break;288 }289 }290 int k;291 for(k = 3; k <= 15; ++k){292 if(Hash2[k] == 4){293 break;294 }295 }296 if(j == 16 && k == 16){297 flag = true;298 //printf("Trio\n");299 }300 }301 }302 if(flag){303 printf("Yes\n");304 continue;305 }306 307 ///Pair308 for(int i = 15; i >= 3; --i){309 if(Hash1[i] == 2){310 int j;311 for(j = i+1; j <= 15; ++j){312 if(Hash2[j] >= 2){313 break;314 }315 }316 int k;317 for(k = 3; k <= 15; ++k){318 if(Hash2[k] == 4){319 break;320 }321 }322 if(j == 16 && k == 16){323 flag = true;324 //printf("Pair\n");325 }326 }327 }328 if(flag){329 printf("Yes\n");330 continue;331 }332 333 ///Solo334 for(int i = 17; i >= 3; --i){335 if(Hash1[i] == 1){336 int j;337 for(j = i+1; j <= 17; ++j){338 if(Hash2[j] >= 1){339 break;340 }341 }342 int k;343 for(k = 3; k <= 15; ++k){344 if(Hash2[k] == 4){345 break;346 }347 }348 if(j == 18 && k == 16){349 flag = true;350 //printf("Solo\n");351 }352 }353 }354 if(flag){355 printf("Yes\n");356 continue;357 }358 printf("No\n");359 }360 361 return 0;362 }