「百度之星」数长方形
枚举俩个竖的木棒,统计有多少横的木棒能和它们拼在一起
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 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#include<map> #include<set> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define inf 1000000000 #define ll long long using namespace std; int read() { int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } int T,n,ans; struct P{ int x,y; }; struct L{ P a,b; }a[105],b[105]; int main() { T=read(); int cas=0; while(T--) { cas++;printf("Case #%d:\n",cas); ans=0;int t1,t2;t1=t2=0; n=read(); for(int i=1;i<=n;i++) { int x1=read(),y1=read(),x2=read(),y2=read(); if(x1==x2) { if(y1>y2)swap(y1,y2); b[++t2]=(L){(P){x1,y1},(P){x2,y2}}; } if(y1==y2) { if(x1>x2)swap(x1,x2); a[++t1]=(L){(P){x1,y1},(P){x2,y2}}; } } for(int i=1;i<=t1;i++) for(int j=i+1;j<=t1;j++) { if(a[i].b.x<a[j].a.x||a[i].a.x>a[j].b.x)continue; int mx=min(a[i].b.x,a[j].b.x); int mn=max(a[i].a.x,a[j].a.x); int y1=min(a[i].b.y,a[j].b.y); int y2=max(a[i].b.y,a[j].b.y); int tot=0; for(int k=1;k<=t2;k++) if(b[k].a.x>=mn&&b[k].a.x<=mx) if(b[k].a.y<=y1&&b[k].b.y>=y2)tot++; ans+=tot*(tot-1)/2; } printf("%d\n",ans); } return 0; } |
Subscribe