首页 > 其他分享 > Counting Rectangles UVA - 10574

Counting Rectangles UVA - 10574

时间:2023-04-21 23:11:09浏览次数:49  
标签:include 个点 int tes 10574 UVA Counting

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

 

点按照x排序

 

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

 

 

#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);
 }

 

标签:include,个点,int,tes,10574,UVA,Counting
From: https://www.cnblogs.com/towboa/p/17342151.html

相关文章

  • Eigensequence UVA - 11133
    给你一个递增序列的第一位a1,最后一位an,求有多少个序列满足:以a1为首,an为尾 1、B(1)=A(1)2、后面每项满足A[j]=B[j], A(j-1)<B(j)≤A(j),且bj能整除A(j)-A(j-1)。   F[i][j]最后一位为j的方案数#include<iostream>#include<cstring>#include<a......
  • Counting
    CountingTypeRepetitionAllowed?Formular-permutationsNo$P_n^k=r!{n\choosek}$r-combinationsNo\(C_n^k={n\chooser}\)r-permutationsYes\(n^k\)r-combinationsYes$C_{n+k-1}^k={n+k-1\choosek}$r-combinationswit......
  • UVA Children’s Game(贪心)
    Description4thIIUCInter-University ProgrammingContest,2005AChildren’sGameInput:standardinputOutput:standardoutputProblemsetter: Md. KamruzzamanTherearelotsofnumbergamesforchildren.Thesegamesareprettyeasytoplaybutnotsoeasyt......
  • UVA Immediate Decodability(简单字典树)
    ImmediateDecodabilityTimeLimit:3000MS     MemoryLimit:0KB     64bitIOFormat:%lld&%lluSubmit StatusDescription  ImmediateDecodability Anencodingofasetofsymbolsissaidtobe immediately decodableifnocode......
  • UVA10237 Bishops
      #include<iostream>#include<cstring>#include<queue>usingnamespacestd;constintN=2e5+2;#defineintlonglongintn,m,f1[50][2000],f2[50][2000];voidsov(){ memset(f1,0,sizeoff1);memset(f2,0,sizeoff2); f1[0][0]=f2......
  • UVA How Many Points of Intersection?
      HowManyPointsofIntersection? a dotsonthetoprowand b dotsonthebottomrow.Wedrawlinesegmentsconnectingeverydotonthetoprowwitheverydotonthebottomrow.Thedotsarearrangedinsuchawaythatthenumberofinternalintersectio......
  • (UVA) The ? 1 ? 2 ? ... ? n = k problem
    The?1?2?...?n=kproblemTheproblemGiventhefollowingformula,onecansetoperators'+'or'-'insteadofeach'?',inordertoobtainagivenk?1?2?...?n=kForexample:toobtaink=12,theexp......
  • How Many O's? UVA - 11038
    写下区间[a,b]的所有数 ,问一共有多少个0 #include<iostream>#include<cstring>#include<vector>usingnamespacestd;#defineintlonglongintn,f[40][40][2][2];vector<int>a;intdfs(intx,intcnt0,intflg,intlead){ if(x<0){ i......
  • Investigating Div-Sum Property UVA - 11361
     定问在[A,B]中,有多少个整数本身能被m整除,各个数位上数字之和也能被m整除?  #include<iostream>#include<cstring>#include<vector>usingnamespacestd;vector<int>a;intm,f[40][105][105][2];intdfs(intx,intv1,intv2,intflg){ if(x<0) retur......
  • UVA11806 Cheerleaders
    你有一个n×m的网格图,现在你要将K个人放在网格中,满足一下条件:网格图的四个边都至少有一个人。每个格子上不能有两个人。每个人必须都有位置。注意:四个角的人可以同时算作在两个边上  容斥原理   J=0时就是allAnswer#include<iostream>#include<cstri......