随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 

给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。

 

点按照x排序

 

n^2挑选出 垂直x轴的线段,按照y1排序

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5  ;
 
  
 struct T{
    int x,y;
     
    bool operator<(T &rh){
        if(x==rh.x) return y<rh.y;
        return x<rh.x;
    }
 }a[N];
  
 struct Q{
    int y1,y2;
    Q(int y1,int y2):y1(y1),y2(y2){}
    bool operator<(Q &rh){
        if(y1==rh.y1) return y2<rh.y2;
        return y1<rh.y1;
    }
 };
 int n;
 int C2(int x){ return x*(x-1)/2; }
 void sov(int cas){
    vector<Q> vec;
    int i,j,x,y;
    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
     
    sort(a+1,a+1+n) ;
    for(i=1;i<=n;i++)
     for(j=i+1;j<=n;j++){
        if(a[i].x-a[j].x) break;
        vec.push_back(Q(a[i].y,a[j].y));
         
     
    sort(vec.begin(),vec.end());
    int ans=0,cnt=1;
     for(i=0;i<vec.size();i++){
        if(vec[i].y1==vec[i-1].y1&&
           vec[i].y2==vec[i-1].y2)  cnt++;
        else
            ans+= C2(cnt), cnt=1;
     }
     ans+=C2(cnt) ;
    printf("Case %d: %d\n", cas, ans);
 }
 signed main(){
    int tes,cas=0;
    cin>>tes;
    while(tes--) sov(++cas);
 }

 

posted on   towboat  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示