Jurisdiction Disenchantment

题目描述

The Super League of Paragons and Champions (SLPC) has been monitoring a plot by a corrupt politician to steal an election. In the past week, the politican has used a mind-control technique to enslave the n representatives responsible for choosing the election’s winner. Luckily, the SLPC has managed to recruit you and hence has access to your power to break mind-control. You are able to break mind-control in an axis-aligned rectangle. Unfortunately, your power comes at a steep cost; you get a headache the next day proportional to the size of the rectangle. You do not even want to risk or think about what would happen if you tried to use your power multiple times in one day.
You have done your research and you know the position that each representative will be standing when the votes are about to be cast. You need to free enough representatives to prevent the politician from having a majority (strictly more than one-half) vote. What is the area of the smallest axis-aligned rectangle that you can affect to do this?

 

输入

The first line of input contains a single integer T (1 ≤ T ≤ 10), the number of test cases. The first line of each test case contains a single integer n (1 ≤ n ≤ 299, n is odd), the number of representatives. Each of the next n lines of input contains two integers, denoting the x and y coordinates of a representative. It is guaranteed that all coordinates are between −10,000 and +10,000.

 

输出

For each test case, output a single line containing the area of the smallest axis-aligned rectangle containing more than n/2 of the representatives.


思路:读入数据,根据横坐标排序

暴力枚举水平边的边界i,j  。去查找方向竖直边的边界,用以判断是否满足(n+1)/2 。

#include<iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <map>
#include<deque>
#define ll long long
# define inf 0x3f3f3f3f
using namespace std;
struct node{
    ll x,y;
}a1[1008611],a2[1008611];
bool cmp1(node a,node b){
    if(a.x==b.x){
        return b.y<b.y;
    }
    return a.x<b.x;
}
bool cmp2(node a,node b){
    if(a.y==b.y){
        return a.x<b.x;
    }
    return a.y<b.y;
}
deque<ll>dq;
int main(){
    ll t,n,nx,ny;
    scanf("%lld",&t);
    while (t--) {
        dq.clear();
        scanf("%lld",&n);
        for(int i=0;i<n;i++){
            scanf("%lld%lld",&nx,&ny);
            a1[i].x=nx;
            a1[i].y=ny;
            a2[i]=a1[i];
        }
        sort(a1,a1+n,cmp1);
        sort(a2,a2+n,cmp2);
        ll ans=inf;
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                dq.clear();
                for(int k=0;k<n;k++){
                    if((a2[k].x>=a1[i].x)&&(a2[k].x<=a1[j].x)){
                        if(dq.size()<(n+1)/2){
                            dq.push_back(k);
                        }
                        if(dq.size()>=(n+1)/2){
                            ans=min(ans,((a1[j].x-a1[i].x)*(a2[dq.back()].y-a2[dq.front()].y)));
                            dq.pop_front();
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值