FZU ~APTX4869
来源:互联网 发布:下载软件的网站 编辑:程序博客网 时间:2024/05/07 07:01
<pre name="code" class="cpp">#include<stdio.h>#include<queue>#include<string.h>#include<algorithm>using namespace std;/*二分答案+并查集判定 http://acm.fzu.edu.cn/contest/problem.php?cid=151&sortid=5*/ const int maxn = 805;int mx[maxn][maxn];int flag[maxn];int father[maxn];void init(int n) { for(int i=0; i<n; i++) father[i] = i;}int getfather(int x) { if(x != father[x]) father[x] = getfather(father[x]); return father[x];}bool same(int x,int y) { return getfather(x)==getfather(y);}void unionAll(int x,int y) { x = getfather(x); y = getfather(y); if(x!= y) father[x]=y;}bool gao(int n, int x){init(n);for(int i = 0 ; i < n ; i ++){for(int j = i + 1; j < n; j++){if(mx[i][j] < x){unionAll(i,j);}}}int cnt = 0;for(int i =0 ; i < n;i ++){if(father[i] == i){cnt ++;}}return cnt == 1 ? false:true;} int main(){int n , i ,j;while(scanf("%d",&n)!=EOF){int l = 0, r = 0 , mid;for(i = 0 ; i < n; i ++){for(j = 0 ; j < n; j ++){scanf("%d",&mx[i][j]);if(r < mx[i][j]) r = mx[i][j];}}int ans = 0;while(l <= r){mid = (l + r) >>1;if(gao(n , mid)){ans = mid;l = mid + 1;}else{r = mid -1;}}printf("%d\n",ans);}return 0;}
0 0
- FZU ~APTX4869
- FZU 2233 ~APTX4869 (贪心 并查集)
- FZU 2233 ~APTX4869【贪心+并查集】
- FZU 2233 ~APTX4869(并查集)
- ~APTX4869
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- Pollard Rho因数分解
- ubuntu搭建单机版hadoop
- eclipse[Open In Explorer]
- elasticsearch 使用bulk导入数据
- Android ClassyShark vs ApkTool
- FZU ~APTX4869
- LA4254 STL优先队列+二分答案
- javaIO关于文件操作(读取,写入,复制,遍历所有文件)
- HD Tune结合硬盘再生器HDDREG快速修复硬盘错误
- LeetCode 280. Wiggle Sort
- php和lua的变量作用域
- 「JavaScript里的面向对象」— 5.原型模式
- 关于NSBundle获取文件路径的问题
- 自定义OpenStack Horizon(Mitaka)