80pts求助!在线等!急!
  • 板块题目总版
  • 楼主poor_OIer
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/22 23:00
  • 上次更新2024/8/23 10:32:50
查看原帖
80pts求助!在线等!急!
704634
poor_OIer楼主2024/8/22 23:00

P2902 [USACO08MAR] Pearl Pairing G

TLE #2 #10 求调

已经很尽力了。

时间复杂度大概是Θ(n+n2log⁡n)\Theta(n+n^2\log n)

#include<bits/stdc++.h>
using namespace std;
int n,c,sum;
struct node{
	int color;
	int cnt;
	bool operator<(const node a)const{
		return cnt>a.cnt;
	}
}pearl[100005];
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int main()
{
	n=read();
	c=read();
	sum=n;
	for(int i=1;i<=c;i++)
		pearl[i].cnt=read(),pearl[i].color=i;
	while(sum)
	{
		sort(pearl+1,pearl+c+1);
		cout<<pearl[2].color<<' '<<pearl[1].color<<endl;
		pearl[1].cnt--;
		pearl[2].cnt--;
		sum-=2;
	}
	return 0;
}
2024/8/22 23:00
加载中...