• 【UOJ 135】四轮车


    四轮车 car

    ##【题目描述】:

    在地图上散落着 n 个车轮,小 J 想用它们造一辆车。要求如下:

    1. 一辆车需要四个车轮,且四个车轮构成一个正方形

    2. 车轮不能移动

    你需要计算有多少种造车的方案(两个方案不同当且仅当所用车轮不全相同,坐标相同的两个车轮视为不同车轮)。

     

    ##【输入描述】:

    第一行一个整数 n

    接下来n 行,每行两个整数 x y,表示在(x,y)处有一个车轮

     

    ##【输出描述】:

    一行一个整数,表示方案数

     

    ##【样例输入】:

        9

        0 0

        1 0

        2 0

        0 2

        1 2

        2 2

        0 1

        1 1

        2 1

     

    ##【样例输出】:

        5

     

    ##【时间限制、数据范围及描述】:

    时间:1s 空间:128M

    30%的数据保证 n<=30

    100%的数据保证 1 <= n <= 1000; |x|, |y| < 20000

     

    题解:暴力+二分√

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    int n,m,cnt;
    struct node{
        int x,y,z;
    }b[1002]; 
    node a[1002];
    bool cmp(node p,node q){
        if(p.x==q.x) return p.y<q.y;
        return p.x<q.x;
    }
    
    int find(int xx,int yy,int l1,int r1){
        int l=l1,r=r1;
        while(l<=r){
            int m=(l+r)/2;
            if(b[m].x<xx || (b[m].x==xx && b[m].y<yy)) l=m+1;
            if(b[m].x>xx || (b[m].x==xx && b[m].y>yy)) r=m-1;
            if(b[m].x==xx && b[m].y==yy) return 1;
        }
        return 0;
    }
    
    ll overcome_jjj(int p,int q){
        int a1=b[p].x; int b1=b[p].y;
        int a2=b[q].x; int b2=b[q].y;
        if((a2-a1)!=(b2-b1)) return 0;
        int f1x=a2; int f1y=b1;
        int f2x=a1; int f2y=b2; 
        if(find(f1x,f1y,p,q) && find(f2x,f2y,p,q)) 
        {
            //printf("%d %d %d %d
    ",a1,b1,a2,b2);
            //printf("%d %d %d %d
    ",f1x,f1y,f2x,f2y);
            //printf("%d
    ",b[p].z*b[q].z);printf("
    ");
            return (ll)b[p].z*(ll)b[q].z;
        }
           
        return 0;
    }
    
    int main(){
        freopen("car.in","r",stdin);
        freopen("car.out","w",stdout);
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d %d",&a[i].x,&a[i].y);
        sort(a+1,a+n+1,cmp);
        b[1].x=a[1].x; b[1].z=1; 
        b[1].y=a[1].y; cnt=1;
        for(int i=2;i<=n;i++){
            if(a[i].x==a[i-1].x && a[i].y==a[i-1].y) 
               b[cnt].z++;
            else { b[++cnt].x=a[i].x; b[cnt].y=a[i].y; b[cnt].z=1; }
        } 
        ll ans=0;
        for(int i=1;i<=cnt;i++)
            for(int j=i+1;j<=cnt;j++)
                ans+=overcome_jjj(i,j);
        printf("%lld",ans);
        return 0;
    }
  • 相关阅读:
    第二季-专题11-世界一下变大了-MMU
    第二季-专题10-C语言环境初始化
    第二季-专题9--代码搬移不可少
    第二季-专题8-不用内存怎么行
    第二季-专题6-点亮指路灯
    第二季-专题7-ARM跑快了---时钟初始化
    第二季-专题5-核心初始化
    第二季-专题4-我是bootloader设计师
    消除苹果系统对边框的优化
    css3
  • 原文地址:https://www.cnblogs.com/wuhu-JJJ/p/14043964.html
Copyright © 2020-2023  润新知