Problem 2233 ~APTX4869

Accept: 55    Submit: 176
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

为了帮助柯南回到一米七四,阿笠博士夜以继日地研究APTX4869的解药。他得出了如下结果:

1.解药由n种原料构成;

2.对于两种不同的的原料a,b,它们之间有个影响值f(a,b);

3.需要把原料分成两个部分X,Y,每部分中至少有一种原料;

4.解药的效果由分别属于X,Y的原料之间,最小的影响值决定,即

效果=min{f(a,b)|a∈X,b∈Y)}

博士需要你帮忙求出:在所有的方案中,最大的效果值可以是多少?

Input

多组数据(<=10),处理到EOF。

每组数据输入第一行为一个正整数n。

接下去是一个n行n列的整数矩阵,同一行的数以空格隔开。矩阵第i行j列表示第i种和第j种材料的影响值f(i,j)。给出的矩阵是对称的,即f(i,j)=f(j,i)。当i=j时,f(i,i)没有意义,矩阵该处的值为-1。

2<=n<=800。当i!=j时,0<=f(i,j)<=1000000;当i=j时,f(i,j)=-1。

Output

每组数据输出一行,表示最大可能的效果值。

Sample Input

3
-1 100 300
100 -1 200
300 200 -1

Sample Output

200

Source

福州大学第十三届程序设计竞赛

思路:并查集;
按照贪心的思路,我们把小的边先合并,在合并小的边时,我们有两种选择,那么就是把两个点分开或合并,所以每当我们找到俩个当前不在一个集合的点,我们更新最小值。
如果当前两个点以合并,那么continue;
下面反证:如果在后面已经合并的点要更新最小值,那么,这两点必定通过前面的点相连通,那么必定要断开一些点将这些点加入到相反的集合,也就是比如这两点为x,y,那么x,y必定不能在同一集合,而且有一些开始在x中的点要到y中必定造成,最小值减小,而不会取x,y之间的值。
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 using namespace std;
7 int bin[1000];
8 int shen[1000];
9 int ju[1000][1000];
10 typedef struct pp
11 {
12 int x;
13 int y;
14 int cost;
15 } ss;
16 ss aa[1000000];
17 bool cmp(pp n,pp m)
18 {
19 return n.cost<m.cost;
20 }
21 int main(void)
22 {
23 int i,j,k;
24 while(scanf("%d",&k)!=EOF)
25 {
26 for(i=0; i<=1000; i++)
27 {
28 shen[i]=1;
29 bin[i]=i;
30 }
31 for(i=1; i<=k; i++)
32 {
33 for(j=1; j<=k; j++)
34 {
35 scanf("%d",&ju[i][j]);
36 }
37 }
38 int cnt=0;
39 for(i=1; i<=k; i++)
40 {
41 for(j=i+1; j<=k; j++)
42 {
43 aa[cnt].cost=ju[i][j];
44 aa[cnt].x=i;
45 aa[cnt].y=j;
46 cnt++;
47 }
48 }
49 sort(aa,aa+cnt,cmp);
50 int coutt=0;
51 for(i=0; i<cnt; i++)
52 {
53 int xx;
54 int yy;
55 for(xx=aa[i].x;xx!=bin[xx];)
56 xx=bin[xx];
57 for(yy=aa[i].y;yy!=bin[yy];)
58 yy=bin[yy];
59 if(xx!=yy)
60 {
61 coutt=aa[i].cost;
62 if(shen[xx]>shen[yy])
63 {
64 shen[xx]+=shen[yy];
65 bin[yy]=xx;
66 }
67 else
68 {
69 shen[yy]+=shen[xx];
70 bin[xx]=yy;
71 }
72 }
73 }printf("%d\n",coutt);
74 }return 0;
75 }

Problem 2233 ~APTX4869的更多相关文章

  1. FZu Problem 2233 ~APTX4869 (并查集 + sort)

    题目链接: FZu Problem 2233 ~APTX4869 题目描述: 给一个n*n的矩阵,(i, j)表示第 i 种材料 和 第 j 种材料的影响值,这个矩阵代表这n个物品之间的影响值.当把这 ...

  2. FZU 2233 ~APTX4869 贪心+并查集

    分析:http://blog.csdn.net/chenzhenyu123456/article/details/51308460 #include <cstdio> #include & ...

  3. (并查集)~APTX4869(fzu 2233)

    http://acm.fzu.edu.cn/problem.php?pid=2233 Problem Description 为了帮助柯南回到一米七四,阿笠博士夜以继日地研究APTX4869的解药.他 ...

  4. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  5. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  6. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  7. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  8. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  9. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

随机推荐

  1. 用前端表格技术构建医疗SaaS 解决方案

    电子健康档案(Electronic Health Records, EHR)是将患者在所有医疗机构产生的数据(病历.心电图.医疗影像等)以电子化的方式存储,通过在不同的医疗机构之间共享,让患者面对不同 ...

  2. Windows系统安装MySQL详细教程和安装过程中问题汇总(命令安装),更新时间2021-12-8

    安装包下载 下载地址:https://dev.mysql.com/downloads/mysql/ 点击下载之后,可以选择注册Oracle账号,也可以跳过直接下载. 下载完成后,选择一个磁盘内放置并解 ...

  3. 深入理解mysql锁与事务隔离级别

    一.锁 1.锁的定义     锁即是一种用来协调多线程或进程并发使用同一共享资源的机制 2.锁的分类 从性能上分类:乐观锁和悲观锁 从数据库操作类型上分类:读锁和写锁 从操作粒度上分类:表锁和行锁 2 ...

  4. 【leetcode】952. Largest Component Size by Common Factor(Union find)

    You are given an integer array of unique positive integers nums. Consider the following graph: There ...

  5. 【leetcode】222. Count Complete Tree Nodes(完全二叉树)

    Given the root of a complete binary tree, return the number of the nodes in the tree. According to W ...

  6. android TabLayout设置选项卡之间的距离无效已解决

    根据下面的链接设置完距离后无法生效 https://www.jb51.net/article/131304.htm layout <com.google.android.material.tab ...

  7. Linux系统信息查看命令(ZZ)

    http://hi.baidu.com/thinkdifferent/blog/item/22f4a80161630e011d958384.html转自一个baidu师兄的博客,很好的一个总结,推荐下 ...

  8. java通过反射获取Java对象属性值

    说明: 作为反射工具类,通过对象和属性的名字获取对象属性的值,如果在当前对象属性没有找到,依次向上收集所有父类的属 性,直到找到属性值,没有找到返回null: 代码: 1.classUtil pack ...

  9. 最基础前端路由实现,事件popstate使用

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. jQuery对象进行方法扩展

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>01 ...