Codeforces Round #579 (Div. 3) B. Equal Rectangles

本文探讨了一种解决矩形配对问题的算法,通过判断边的数量是否为偶数并进行排序,每次选取首尾数字构成矩形,最终判断是否能形成统一大小的矩形集合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接

点击查看题目

题解

第一次见识了取消流同步之后同时用 c o u t cout cout p r i n t f printf printf的后果…

输出会变得很混乱,然后就莫名其妙 W A \color{red}WA WA

这题就是直接先判断一下每种边是不是都有偶数个,如果满足的话就把所有边个数除以 2 2 2然后排个序

每次选择首尾两个数字(代表了四条边)组成矩形

代码

#include <bits/stdc++.h>
#define linf (1ll<<60)
#define iinf 0x3f3f3f3f
#define rep(_,__) for(_=1;_<=(__);_++)
using namespace std;
#define maxn 100010
typedef long long ll;
ll cnt[10010];
int main()
{
    ios::sync_with_stdio(false);
    ll i, n, x, T;
    cin>>T;
    while(T--)
    {
        deque<ll> q;
        cin>>n;
        rep(i,10000)cnt[i]=0;
        rep(i,4*n)
        {
            cin>>x;
            cnt[x]++;
        }
        rep(i,10000)
            if(cnt[i]%2==1)break;
        if(i<=10000)
        {
            cout<<"NO\n";
            continue;
        }
        rep(i,10000)
        {
            cnt[i]/=2;
            while(cnt[i]--)q.emplace_back(i);
        }
        set<ll> s;
        while(!q.empty())
        {
            s.emplace( q.front()*q.back() );
            q.pop_front(), q.pop_back();
        }
        if(s.size()==1)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值