求助一道atcoder上的题目
  • 板块学术版
  • 楼主Harryfan
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/10/16 20:44
  • 上次更新2023/11/4 03:34:58
查看原帖
求助一道atcoder上的题目
553444
Harryfan楼主2021/10/16 20:44

题目网址:

https://vjudge.net/problem/AtCoder-abc222_c

想出思路了,代码也写出来了,但是样例都没过······哪位大神可以帮忙看一下,谢谢!

#include<bits/stdc++.h>
using namespace std;
string s[105];
int n,m;
struct node
{
	int id,val;
}player[105];
bool cmp(node a,node b)
{
	if(a.val==b.val)
		return a.id<b.id;
	return a.val>b.val;
}
int win(int p1,int p2,int t)
{
	char a=s[p1][t];
	char b=s[p2][t];
	if(a==b)
		return -1;
	if(a=='G')
		return (b='C');
	if(a=='C')
		return (b='P');
	if(a=='P')
		return (b='G');
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	n*=2;
	for(int t=0; t<n; t++)
		cin>>s[t];
	for(int t=0; t<n; t++)
		player[t].id=t;
	
	for(int t=0; t<n; t++)
	{
		for(int i=0; i<n; i+=2)
		{
			int w;
			if(win(player[i].id,player[i+1].id,t))
				w=i;
			else
				w=i+1;
			if(win(player[i].id,player[i+1].id,t)!=-1)
				player[w].val++;
		}
		sort(player,player+n,cmp);
	}
	for(int t=0;t<n;t++)
	cout<<player[t].val+1<<endl;
	return 0;
}
2021/10/16 20:44
加载中...