"NOIP Simulation" Assassination of Ambassadors (two-point answer + and check set)

Source: Internet
Author: User


" Solution" "Two-point answer "

"See the maximum value of the smallest, that must be two points, ah, the exam did not know what the brain did go ..." "

"First find the largest value in the entire matrix, as the right boundary of the two points, and then, the two-point answer, the matching conditions of the adjacent lattice and check set and to a set, when using less than equal to the current value of the lattice can be 1 and n*m Unicom, the current value is valid"

#include <cstdio> #include <cstring> #include <algorithm> using namespace std;
int N,M,A[1010][1010],ANS,MAXN;
int f[1000010];
	int find (int x) {if (f[x]==x) return f[x];
	F[x]=find (F[x]);
 return f[x];
	} inline void link (int x,int y) {int f1=find (x), F2=find (y);
F[F1]=F2;
	} inline bool Check (int t) {for (int i=1;i<=n*m;++i) f[i]=i;
	   	for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) if (a[i][j]<=t) {int now= (i-1) *m+j;
	   	if (i+1<=n&&a[i+1][j]<=t) link (now,i*m+j);
	   if (j+1<=m&&a[i][j+1]<=t) link (now,now+1);
	} if (find (1) ==find (n*m)) return 1;
return 0;
	} inline void qsort (int l,int r) {int mid;
	 	while (l<=r) {mid= (l+r) >>1;
	 	 if (check (mid)) R=mid-1,ans=mid;
	 else l=mid+1;
	}} int main () {freopen ("murder.in", "R", stdin);
	Freopen ("Murder.out", "w", stdout);
	int i,j;
	scanf ("%d%d", &n,&m); for (I=1;i<=n;++i) for (j=1;j<=m;++j) scanf ("%d", &a[i][j]), Maxn=max (A[I][J],MAXN);
	Qsort (0,MAXN);
	printf ("%d\n", ans);
 return 0;  }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.