zoukankan      html  css  js  c++  java
  • 2019牛客多校第三场H Magic Line 思维

    Magic Line

    题意

    给出n(偶)个整点 整点范围1000,找出一条直线,把n个点分成均等的两部分

    分析

    因为都是整数,并且范围比较小,所以直接按x排序找到在中间那一部分,并且把中间那一部分的点按照左右点的分布情况,分成两部分即可。如何分呢,因为范围比较小,所以可以找一条斜率特别极限的直线把其分成两部分。这题的关键是要同意直线的形状,要么从左上到右下,要么从左下到右上,混淆就会WA。

    #include<bits/stdc++.h>
    using namespace std;
    #define F first
    #define S second
    const int maxn=2e6+5;
    pair<int,int>a[maxn];
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
            int cntzuo=0,cntyou=0;
            int n;
            scanf("%d",&n);
            for(int i=1;i<=n;i++){
                scanf("%d%d",&a[i].F,&a[i].S);
            }
            sort(a+1,a+1+n,[](pair<int,int>a,pair<int,int>b){
                        if(a.F!=b.F)return a.F<b.F;
                        else return a.S<b.S;
                    });
            int tmp=n/2;
            int x=a[tmp].F;
            int xa=a[tmp].F;
            int xb=a[tmp+1].F;
            int ya,yb;
            for(int i=1;i<=n;i++){
                if(a[i].F<x)cntzuo++;
                else if(a[i].F>x) cntyou++;
            }
             
            if(cntzuo>=cntyou){
                ya=a[cntzuo+(tmp-cntzuo)].S;
                yb=a[cntzuo+(tmp-cntzuo+1)].S;
            }
            else {
                ya=a[(n-cntyou)-(tmp-cntyou)].S;
                yb=a[(n-cntyou)-(tmp-cntyou)+1].S;
            }
        printf("%d %d %d %d
    ",xa+1,ya-10000000,xb-1,yb+10000000);
     
        }
        return 0;
    }
    
    
  • 相关阅读:
    click event not triggered on bootstrap modal
    how to use datatables editor
    how to create modals with Bootstrap
    WebSite
    Spring Security OAuth 2开发者指南译
    security和oauth2.0的整合
    Spring Boot遇到的某些问题
    linux主机名莫名其妙变成了bogon,并解决修改为localhost
    Getway网关管理ZUUL
    feign中的hytrix和turbin配置
  • 原文地址:https://www.cnblogs.com/ttttttttrx/p/11396035.html
Copyright © 2011-2022 走看看