HDU 3759(暴力映射)
来源:互联网 发布:淘宝投票活动说明 编辑:程序博客网 时间:2024/06/16 19:03
这个题目就是将手里的5张牌映射成一个个不同的等级
这种映射题目,很明显第一个node,然后再定义一个比较函数,然后排序即可。
需要注意的是:
一些预处理的值必须 , 再return之前
重用一个node必须保证不相互干扰。
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cstdlib>#include <set>#include <map>#include <vector>#include <list>#include <queue>#include <stack>#include <iterator>using namespace std;#define rep(i , n) for(int i = 0 ; i<(int)n;i++)#define rep1(i , x , y) for(int i = (int)x ; i<=(int)y;i++)typedef long long LL;const int N = 10;struct node{ int a[5]; int val; int ran; vector<int> v[5]; int rank(){ bool straight = 1; rep1(i , 1 ,4){ if(a[i - 1] + 1 == a[i]) continue; if(i == 4 && a[i] == 12 && a[0] == 0) { a[i] = -1; sort(a ,a + 5); break; } straight = false; break; } rep(i , 5){ int j = i , cnt = 0; for(;j < 5; j++){ if(a[j] != a[i]) break; ++cnt; } v[cnt].push_back(a[i]); i = j - 1; } if(val && straight) return 100; if(v[4].size() > 0) return 99; if(v[3].size() && v[2].size()) return 98; if(val) return 97; if(straight ) return 96; if(v[3].size()) return 95; if(v[2].size() == 2) return 94; if(v[2].size()) return 93; return 92; } void init(){ rep(i , 5) v[i].clear(); ran = rank(); if(v[1].size()) sort(v[1].begin(),v[1].end()); if(v[2].size()) sort(v[2].begin(),v[2].end()); } void show()const{ for(int i = 0; i<=4 ; i++){ cout<<i <<" *** \n"; for(int j = 0 ; j<v[i].size() ; j++) cout<<v[i][j]<<" "; cout<<endl; } } bool operator <(const node& rhs)const{ if(ran != rhs.ran) return ran < rhs.ran; for(int i = 4 ; i>=1 ; i--){ if(v[i].size()){ for(int j = v[i].size() - 1 ; j>=0; j--){ if(v[i][j] != rhs.v[i][j]) return v[i][j] < rhs.v[i][j]; } } } return 0; }};const char* str="23456789TJQKA";int id(char c){ for(int i = 0 ; i<13;i++) if(str[i] == c) return i;}int a[N];vector<node> ans;int cnt = 0 ;map<node , int> vis;void dfs(int p , int s, int num){ if(p == 5){ int ok = 1; for(int j = 1 ; j<5 ; j++) if(a[j - 1] == a[j]) { ok = 0; break; } node te; for(int i = 0 ; i<5;i++) te.a[i] = a[i]; te.val = 0; te.init(); ans.push_back(te); if(ok == 1) { te.val = 1; te.init(); ans.push_back(te); } return ; } for(int i = s;i<13;i++){ int nex = (i==s ? num + 1 : 1); if(nex <= 4){ a[p] = i; dfs(p + 1 , i , nex); } }}int main(){ dfs(0 , 0 , 0); sort(ans.begin(),ans.end()); int T; scanf("%d",&T); while(T--){ string ss; node te; int ok = 1 , c; for(int i = 0 ; i<5;i++){ cin>>ss; te.a[i] = id(ss[0]); if(i == 0) c = ss[1]; else if(c != ss[1]) ok = 0; te.val = ok; } sort(te.a , te.a + 5); te.init(); cout<<lower_bound(ans.begin(),ans.end(),te)-ans.begin() + 1<<endl; } return 0;}
0 0
- HDU 3759(暴力映射)
- 【字符串暴力】hdu 2847
- HDU **** 暴力模拟
- HDU-1128 暴力搜索
- hdu 2438 暴力吧
- HDU 4175 暴力求解
- hdu 3332 暴力枚举
- HDU 3823 暴力枚举
- hdu 4608 暴力大数
- hdu 1702 暴力
- hdu 4585 shaolin (暴力)
- HDU 4576 Robot (暴力)
- hdu 3711 暴力
- HDU 3697 暴力贪心
- hdu 4499 Cannon(暴力)
- hdu 1394 暴力
- hdu 3720 暴力枚举
- hdu 4995 暴力
- GET和POST的比较
- 动态规划
- XMG Quartz2D 设置裁剪区域
- 使用scrapy进行大规模抓取(一)
- idr 机制 radix tree
- HDU 3759(暴力映射)
- 《程序员的自我修养》第十一章读书笔记
- Android 6.0 向用户申请权限,运行时权限
- Discuz的forum_index.php文件的分析
- JAVA之路002-运算符
- pkg-config的用法
- 动态规划 problem o
- Android开发工具之Android Studio----Gradle
- microstation level2 0405