扑克老师版:
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;

int n,a[5][14]={0},ans=52;//全局变量 

int main(){
  char h,d;
  int hh,dd;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>h>>d;
    if(h=='D'){hh=1;}
    if(h=='C'){hh=2;}
    if(h=='H'){hh=3;}
    if(h=='S'){hh=4;}
    if(d=='T'){dd=10;}
    if(d=='J'){dd=11;}
    if(d=='Q'){dd=12;}
    if(d=='K'){dd=13;}
    if(d=='A'){dd=1;}
    if( d>='2' && d<='9' ){ dd=d-48; }//-'0'

    if(a[hh][dd]==0){ ans--; a[hh][dd]=1; }
  }
  cout<<ans<<"\n";

  return 0;
}

扑克map版:
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
map<string,int> m;
int n,cnt = 52;
int main()
{
	freopen("poker.in","r",stdin);
	freopen("poker.ans","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i ++ )
	{
		string s;
		cin >> s;
		if(!m[s])
		{
			m[s] = 1;
			cnt -- ;
		}
	}
	printf("%d",cnt);
	return 0;
}

决斗小根堆和大根堆

#include<bits/stdc++.h>
using namespace std;
int n,ans,a[100010];
int main(){
	freopen("duel.in","r",stdin);
	freopen("duel.out","w",stdout);
	priority_queue<int> q;
	cin>>n;
	ans=n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(!q.empty() && -q.top()<a[i]){
			q.pop();
			ans--;
		}
		q.push(-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}



#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n;
int r[N];
priority_queue<int>q;
int main()
{
	freopen("duel.in","r",stdin);
	freopen("duel.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>r[i];
	sort(r+1,r+1+n);
	for(int i=1;i<=n;++i)
	{
		if(q.empty())
			q.push(-r[i]);
		else
		{
			int now=-q.top();
			if(r[i]>now)
				q.pop();
			q.push(-r[i]);
		}
	}
	int ans=q.size();
	cout<<ans<<endl;
	return 0;
}


0 条评论

目前还没有评论...