Problem 2233 ~APTX4869
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
-1 100 300
100 -1 200
300 200 -1
Sample Output
Source
福州大学第十三届程序设计竞赛
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的更多相关文章
- FZu Problem 2233 ~APTX4869 (并查集 + sort)
题目链接: FZu Problem 2233 ~APTX4869 题目描述: 给一个n*n的矩阵,(i, j)表示第 i 种材料 和 第 j 种材料的影响值,这个矩阵代表这n个物品之间的影响值.当把这 ...
- FZU 2233 ~APTX4869 贪心+并查集
分析:http://blog.csdn.net/chenzhenyu123456/article/details/51308460 #include <cstdio> #include & ...
- (并查集)~APTX4869(fzu 2233)
http://acm.fzu.edu.cn/problem.php?pid=2233 Problem Description 为了帮助柯南回到一米七四,阿笠博士夜以继日地研究APTX4869的解药.他 ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
随机推荐
- bluetooth sig bluetooth asia-深圳之行
18年5月30日深圳参见蓝牙展会 主要了解下面 使用蓝牙和区块链构建室内导航定位系统和去中心化的MESH网络 -- 核心是通过iBeacon 来广播数据,典型用例是手机对手机的使用蓝牙进行交互,业界称 ...
- 巩固javaweb的第二十二天
巩固内容: 使用表单数据 : 要对用户输入的信息进行验证,需要先获取输入信息.每个表单元素都属于一个 form 表单,要获取信息,需要先获取 form,然后访问表单元素的值. 有两种方式可以获取 fo ...
- A Child's History of England.24
Besides all these troubles, William the Conqueror was troubled by quarrels among his sons. He had th ...
- pow()是如何实现的?
如1.5 ** 2.5,如何计算?似乎是这样的: 1. cmath calculates pow(a,b) by performing exp(b * log(a)). stackoverflow 2 ...
- C++11的auto自动推导类型
auto是C++11的类型推导关键字,很强大 例程看一下它的用法 #include<vector> #include<algorithm> #include<functi ...
- linux修改文件权限命令
先看个实例: [root@local opt]#ls -al ls -al 命令是列出目录的所有文件,包括隐藏文件.隐藏文件的文件名第一个字符为'.' -rw-r--r-- 1 root root ...
- 查看linux系统CPU和内存命令
cat /proc/cpuinfo查看linux系统的CPU型号.类型以及大小,如下图所示. 通过greap命令根据Physical Processor ID筛选出多核CPU的信息. cat ...
- 【Python】【Basic】【数据类型】运算符与深浅拷贝
运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 三元运算 三元运算(三目运算),是对简单的条件语句的缩写. # 书写格式 result = 值1 if 条件 ...
- 【Linux】【Basis】进程及作业管理
进程及作业管理 内核的功用:进程管理.文件系统.网络功能.内存管理.驱动程序.安全功能 Process: 运行中的程序的一个副本: 存在生命周期 L ...
- 对于HTML和XML的理解
1.什么是HTML??? HTML就是 超文本标记语言(超文本含义:超过文本 --图片 .视频.音频. 超链接) 2.HTML作用 把网页的信息格式化的展现,对网页信息进行规范化展示 连接(https ...