切割典中典

Problem - D - Codeforces

#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> P;
vector<P> q,p;
int n;
bool check(long long x,long long y) {
	multiset<P> st1,st2;
	for(int i=0;i<q.size();i++) {
		st1.insert(q[i]);
		st2.insert(p[i]);
	}
	for(int i=n;i>=1;i--) {
		int tx=st1.rbegin()->first;
		int ty=st1.rbegin()->second;
		if(tx==x) {
			y-=ty;
			st1.erase(st1.find({tx,ty}));
			st2.erase(st2.find({ty,tx}));
			continue;
		}
		tx=st2.rbegin()->second;
		ty=st2.rbegin()->first;
		if(ty==y) {
			x-=tx;
			st1.erase(st1.find({tx,ty}));
			st2.erase(st2.find({ty,tx}));
			continue;
		}
		return false;
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		long long sum=0;
		long long mx=0,my=0;
		q.clear();
		p.clear();
		for(int i=1;i<=n;i++)
		{
			long long x,y;
			cin>>x>>y;
			q.push_back(make_pair(x,y));
			p.push_back(make_pair(y,x));
			sum+=1ll*x*y;
			mx = max(x, mx);
			my = max(y, my);
		}
		long long My=-1,Mx=-1;
		int flag=0;
		if(sum%mx==0)
		{
			My=sum/mx;
			flag++;
		}
		if(sum%my==0)
		{
			Mx = sum/my;
			flag++;
		}
		if(Mx==mx&&My==my)
		{
			cout<<1<<endl;
			cout<<mx<<" "<<my<<endl;
			continue;
		}else if(flag==1)
		{
			cout<<flag<<endl;
			if(My!=-1)
			{
				cout<<mx<<" "<<My<<endl;
			}
			if(Mx!=-1)
			{
				cout<<Mx<<" "<<my<<endl;
			}
		}else
		{
			if(!check(mx,My))
			{
				My=-1;
				flag--;
			}
			if(!check(Mx,my))
			{
				Mx=-1;
				flag--;
			}
			cout<<flag<<endl;
			if(My!=-1)
			{
				cout<<mx<<" "<<My<<endl;
			}
			if(Mx!=-1)
			{
				cout<<Mx<<" "<<my<<endl;
			}
		}	
	}
	return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值