标签:输入 scan logs amp long col names ++ 一个
Description
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define maxn 100005 4 #define ll long long 5 int f[maxn],tot[maxn]; 6 int n,m,ans,mx; 7 ll c; 8 struct node{ 9 ll x,y;int id; 10 }a[maxn]; 11 inline int read(){ 12 int x,f;char ch=getchar(); 13 while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)f=-1;ch=getchar();} 14 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 15 return x*f; 16 } 17 multiset<node> b; 18 multiset<node>:: iterator it; 19 bool cmp(node a,node b){ 20 return a.x<b.x; 21 } 22 bool operator<(node a,node b){return a.y<b.y;} 23 int find(int x){ 24 if(f[x]!=x)return find(f[x]); 25 else return x; 26 } 27 void work(int x,int y){//将两个群合并在一起 28 int p=find(x),q=find(y); 29 if(p!=q){ 30 tot[p]+=tot[q];tot[q]=0;ans--; 31 f[q]=p; 32 } 33 } 34 void solve(){ 35 node k;int i,he=1; 36 sort(a+1,a+n+1,cmp);b.insert(a[1]); 37 k.x=0;k.y=1e10;k.id=0;b.insert(k); 38 k.x=0;k.y=-1e10;k.id=0;b.insert(k); 39 for(i=2;i<=n;i++){ 40 while(a[i].x-a[he].x>c)b.erase(b.find(a[he])),++he;//判断x是否合法 41 it=b.lower_bound(a[i]); 42 k=*it; 43 if(k.y-a[i].y<=c)work(k.id,a[i].id); 44 k=*--it; 45 if(a[i].y-k.y<=c)work(k.id,a[i].id); 46 b.insert(a[i]); 47 } 48 } 49 int main(){ 50 scanf("%d%d",&n,&c); 51 int kx,ky; 52 ans=n;//ans是群数,tot是每个群里牛的数量 53 for(int i=1;i<=n;i++){ 54 scanf("%d%d",&kx,&ky); 55 f[i]=i;tot[i]=1; 56 a[i].x=kx+ky; 57 a[i].y=kx-ky; 58 a[i].id=i; 59 } 60 solve(); 61 for(int i=1;i<=n;i++)mx=max(tot[i],mx); 62 printf("%d %d",ans,mx); 63 return 0; 64 }
标签:输入 scan logs amp long col names ++ 一个
原文地址:http://www.cnblogs.com/Elfish/p/7632538.html