zoukankan      html  css  js  c++  java
  • Card Game Cheater HDU

    #include<bits/stdc++.h> 
    #define PI acos(-1.0)
    #define E 1e-9
    #define INF 0x3f3f3f3f
    #define LL long long
    const int N=1000+5;
    using namespace std;
    int n;
    bool vis[N];//vis[i]表示是否在交替路中
    int match[N];//存储连接点
    int e[N],ne[N],h[N];
    int idx;
    void add(int a,int b)
    {
    	e[idx]=b;
    	ne[idx]=h[a];
    	h[a]=idx++;
     } 
    bool find(int x) {
    	for(int i=h[x];i!=-1;i=ne[i]) {
    		int y=e[i];
    		if(!vis[y]) { 
    			vis[y]=true;
    			if(match[y]==-1 || find(match[y])) {
    				match[y]=x;
    				return true;
    			}
    		}
    	}
    	return false;
    }
    int solve() {
    	int ans=0;
    	memset(match,-1,sizeof(match));
    	for(int i=1; i<=n; i++) { 
    		memset(vis,false,sizeof(vis));
    		if(find(i))
    			ans++;
    	}
    	return ans;
    }
    int getScore(string str) { //将牌转换为分数
    	int ans=0;
    	if(str[0]>='2'&&str[0]<='9')
    		ans+=(str[0]-'0')*10;
    	else if(str[0]=='T')
    		ans+=100;
    	else if(str[0]=='J')
    		ans+=110;
    	else if(str[0]=='Q')
    		ans+=120;
    	else if(str[0]=='K')
    		ans+=130;
    	else if(str[0]=='A')
    		ans+=140;
    
    	if(str[1]=='C')
    		ans+=1;
    	else if(str[1]=='D')
    		ans+=2;
    	else if(str[1]=='S')
    		ans+=3;
    	else if(str[1]=='H')
    		ans+=4;
    
    	return ans;
    }
    int main() {
    	int t;
    	scanf("%d",&t);
    	while(t--) {
    		idx=0;
    		memset(h,-1,sizeof h);
    		scanf("%d",&n);
    		string str;
    		int scoreAdam[2000],scoreEve[2000];
    		// 
    		for(int i=1; i<=n; i++) 
    		{
    			cin>>str;
    			scoreAdam[i]=getScore(str);
    		}
    		for(int i=1; i<=n; i++) 
    		{ 
    			cin>>str;
    			scoreEve[i]=getScore(str);
    		}
    		for(int i=1; i<=n; i++)
    			for(int j=1; j<=n; j++)
    				if(scoreEve[i]>scoreAdam[j])//eve的牌大于adam
    					add(i,j);
    		printf("%d
    ",solve());
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    USACO Section 1.4 Mother's Milk
    USACO Section 1.5 Checker Challenge
    USACO Section 1.5 Number Triangles
    九度 1140 八皇后
    九度 1091 棋盘游戏
    USACO Section 2.1 Sorting A ThreeValued Sequence
    USACO Section 1.4 The Clocks
    USACO Section 1.5 Superprime Rib
    USACO Section 2.1 Ordered Fractions
    双目测距与三维重建
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12402117.html
Copyright © 2011-2022 走看看