Cod sursa(job #826932)

Utilizator ion824Ion Ureche ion824 Data 1 decembrie 2012 13:55:52
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<algorithm>
#include<fstream>
using namespace std;

int x[1005],y[1005],I[1005];

struct cmp{
       bool operator()(const int &i,const int &j){
            if(x[j]<x[i])return 1; else return 0;}
       };
       
struct cmp1{
       bool operator()(const int &i,const int &j){
            if(y[j]<y[i])return 1; else return 0;}
       };       

int main(){
    ifstream fin("trapez.in");
    ofstream fout("trapez.out");
    int N,i,j,nrpair=0,r;
    
    fin>>N;
    
    for(i=1;i<=N;++i){ fin>>x[i]>>y[i]; I[i]=i; }
    
    sort(I+1,I+N+1,cmp());
    
    i=1;
    while(i<=N)
      if(x[I[i]]==x[I[i+1]] && i<N){ ++nrpair; i+=2; }
        else ++i;
    r=((nrpair-1)*nrpair)/2;
    
    sort(I+1,I+N+1,cmp1()); 
    
    i=1; nrpair=0;
    while(i<=N)
      if(y[I[i]]==y[I[i+1]] && i<N){ ++nrpair; i+=2; }
        else ++i;
    r+=((nrpair-1)*nrpair)/2;            
                   
    fout<<r;    
 return 0;   
}