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):前 ...
随机推荐
- Visual Studio Code常用操作整理
Live Server插件可以在保存html文件后实时地刷新页面 在html文件中键入"! +Tap"会生成一个html模板 保存文件:Ctrl+S 文件跳转:Ctrl+P 文件内 ...
- day9 图书设计项目
总路由层url from django.conf.urls import url from django.contrib import admin from app01 import views ur ...
- ceph块存储场景
1.创建rbd使用的存储池. admin节点需要安装ceph才能使用该命令,如果没有,也可以切换到ceph-node1节点去操作. [cephfsd@ceph-admin ceph]$ ceph os ...
- Shell学习(六)——条件判断总结
Shell学习(六)--条件判断总结 [1]https://www.cnblogs.com/zhw-626/p/8528001.html [2]https://www.cnblogs.com/yizh ...
- 【编程思想】【设计模式】【其他模式】graph_search
Python版 https://github.com/faif/python-patterns/blob/master/other/graph_search.py #!/usr/bin/env pyt ...
- Linux下部署Java项目(jetty作为容器)常用脚本命令
startup.sh #!/bin/bash echo $(basename $(pwd)) "jetty started" cd jetty nohup java -Xmx8g ...
- 【Java 基础】Arrays.asList、ArrayList的subList注意事项
1. 使用Arrays.asList的注意事项 1.1 可能会踩的坑 先来看下Arrays.asList的使用: List<Integer> statusList = Arrays.asL ...
- 通过 Ajax 发送 PUT、DELETE 请求的两种实现方式
一.普通请求方法发送 PUT 请求 1. 如果不用 ajax 发送 PUT,我们可以通过设置一个隐藏域设置 _method 的值,如下: <form action="/emps&quo ...
- .net 5 开发跨平台客户端程序
介绍下.net 跨平台开发服务端程序的过程, .net 5发布已经有段时间了,.net 5根据微软官方的说法将来只有一个.net版本,也就是不在有core之分.从.net5开始整合.net frame ...
- 了解C#的Expression
我们书接上文,我们在了解LINQ下面有说到在本地查询IEnumerbale主要是用委托来作为传参,而解析型查询 IQueryable则用Expression来作为传参: public static I ...