标签:cst print lin main span return exist ble SQ
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1196 | Accepted: 502 |
Description
Input
Output
Sample Input
3 4 1 2 2 1 4 1 5 2
Sample Output
4
Hint
|* *Below is one 4x4 solution (C‘s show most of the corral‘s area); many others exist.
| * *
+------
|CCCC
|CCCC
|*CCC*
|C*C*
+------
Source
二分边长进去检查
#include<cstdio> #include<algorithm> using namespace std; struct my{ int x,y; }; my a[1000]; int mid; int tmp[1000]; int c,n; bool cmp(const my &a,const my &b){ return a.x<b.x; } bool judge(int l,int r) { int cnt=0; for(int i=l; i<=r; ++i) tmp[++cnt]=a[i].y; sort(tmp+1,tmp+cnt+1); for(int i=c; i<=cnt; ++i) if(tmp[i]-tmp[i-c+1]<=mid) return 1; return 0; } bool check(int x) { int l=1,r=1; for(; r<=n; ++r) { if(a[r].x-a[l].x>x) if(judge(l,r-1)) return 1; for(; a[r].x-a[l].x>x; ) l++; } return judge(l,n); } int main(){ int x,y; scanf("%d%d",&c,&n); for (int i=1;i<=n;i++){ scanf("%d%d",&x,&y); a[i].x=x; a[i].y=y; } sort(a+1,a+1+n,cmp); int l=0,r=10000; int ans=0; while(l<=r){ mid=(l+r)>>1; if(check(mid)){ r=mid-1; ans=mid+1; } else l=mid+1; } printf("%d",ans); return 0; }
标签:cst print lin main span return exist ble SQ
原文地址:https://www.cnblogs.com/lmjer/p/8970478.html