PAT 甲级 1012 The Best Rank 题目表达不清晰

只玩真实

题目中存在的问题

表达不清楚!!!
他压根就没有提到 当两个人分数一样的情况如何排名

比如说,两个人所有分数都是 90 分,
那么, 是共同排名,结果为 1 ,1 呢
还是和输入的顺序? 还是和学生的ID number 有关?

经过折磨发现, 就是共同排名
这样的话 , 90 , 90 , 85 , 85 , 80
排名为 1,1,3,3,5

只能说,这种未定义的行为能不能少一点?

#include<bits/stdc++.h>
#define endl "\n"
#define B 0x3f3f3f3f
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<int,int> PII;

typedef struct{
	int id,a,b,c,ave;
	int rk;
	char sub;
}type;

struct rule1{
	bool operator() (const type &a1,const type &a2)
	{
		return a1.ave>a2.ave;
	}
};
struct rule2{
	bool operator() (const type &a1,const type &a2)
	{
		return a1.a>a2.a;
	}
};
struct rule3{
	bool operator() (const type &a1,const type &a2)
	{
		return a1.b>a2.b;
	}
};
struct rule4{
	bool operator() (const type &a1,const type &a2)
	{
		return a1.c>a2.c;
	}
};

map<int,int> mp;

const int N=2e3+10;
type ar[N];
int n,m;

int main()
{
	cin>>n>>m;
	For(i,1,n)
	{
		cin>>ar[i].id>>ar[i].a>>ar[i].b>>ar[i].c;
		ar[i].ave=(ar[i].a+ar[i].b+ar[i].c );
		ar[i].rk=n+1;
		//if (ar[i].ave%3==2)ar[i].ave ++;
		
		ar[i].ave /=3;
		ar[i].sub ='A';
	}
	
	sort(ar+1,ar+n+1,rule1());
	int p=1,x=ar[1].ave;
	
	for (int i=1;i<=n;i++)
	{
		if (ar[i].ave < x)
		{
			p=i;
			ar[i].rk = i;x=ar[i].ave;
		}
		else
		{
			ar[i].rk = p;
		}
	}
	
	p=1;
	sort(ar+1,ar+n+1,rule2());
	x=ar[1].a ;
	
	for (int i=1;i<=n;i++)
	{
		if (ar[i].a < x)
		{
			p=i;x=ar[i].a;
			if (ar[i].rk>i)
			{
				ar[i].rk=i;ar[i].sub='C';
			}
		}
		else
		{
			if (ar[i].rk>p)
			{
				ar[i].rk=p;ar[i].sub='C';
			}
		}
	}

	p=1;
	sort(ar+1,ar+n+1,rule3());
	x=ar[1].b ;
	
	for (int i=1;i<=n;i++)
	{
		if (ar[i].b < x)
		{
			p=i;x=ar[i].b;
			if (ar[i].rk>i)
			{
				ar[i].rk=i;ar[i].sub='M';
			}
		}
		else
		{
			if (ar[i].rk>p)
			{
				ar[i].rk=p;ar[i].sub='M';
			}
		}
	}

	sort(ar+1,ar+n+1,rule4());
	p=1;
	x=ar[1].c ;
	
	for (int i=1;i<=n;i++)
	{
		if (ar[i].c < x)
		{
			p=i;x=ar[i].c ;
			if (ar[i].rk>i)
			{
				ar[i].rk=i;ar[i].sub='E';
			}
		}
		else
		{
			if (ar[i].rk>p)
			{
				ar[i].rk=p;ar[i].sub='E';
			}
		}
	}

	For(i,1,n)
	{
		mp[ar[i].id  ]=i;
		//cout<<ar[i].id <<" "<<ar[i].rk <<" "<<ar[i].sub<<endl;
	}
	
	while(m--)
	{
		cin>>x;
		if (mp[x])
		{
			cout<<ar[mp[x]].rk <<" "<<ar[mp[x]].sub <<"\n";
		}
		else
		{
			cout<<"N/A\n";
		}
	}
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值