Truck History(prim)
http://poj.org/problem?id=1789
读不懂题再简单也不会做,英语是硬伤到哪都是真理,sad++。
此题就是一个最小生成树,两点之间的权值是毎两串之间的不同字母数。
#include<stdio.h>
#include<string.h>
const int N=;
const int INF=<<;
int map[N][N],vis[N],dis[N];
int n,sum;
void prim()
{
int pos;
for (int i = ; i <= n; i ++)
{
dis[i] = map[][i];
}
vis[] = ;
for (int i = ; i <= n-; i ++)
{
int min = INF;
for (int j = ; j <= n; j ++)
{
if (!vis[j] && dis[j] < min)
{
min = dis[j];
pos = j;
}
}
sum += min;
vis[pos] = ;
for (int j = ; j <= n; j ++)
{
if (!vis[j] && dis[j] > map[pos][j])
dis[j] = map[pos][j];
} }
}
void init()
{
sum = ;
for (int i = ; i <= n; i ++)
{
for (int j = ; j <= n; j ++)
{
map[i][j] = INF;
}
map[i][i] = ;
vis[i] = ;
} }
int main()
{
char str[N][];
int cnt;
while(~scanf("%d",&n)&&n)
{ init();
for (int i = ; i <= n; i ++)
{
scanf("%s",str[i]+);
}
for (int i = ; i <= n; i ++)
{
for (int j = i+; j <= n; j ++)
{
cnt = ;
for (int k = ; k <= ; k ++)
{
if (str[i][k]!=str[j][k])
cnt++;
}
map[i][j] = cnt;
map[j][i] = cnt;
}
}
prim();
printf("The highest possible quality is 1/%d.\n",sum);
}
return ; }
Truck History(prim)的更多相关文章
- Truck History(prim & mst)
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19772 Accepted: 7633 De ...
- POJ1789 Truck History(prim)
题目链接. 分析: 最大的敌人果然不是别人,就是她(英语). 每种代表车型的串,他们的distance就是串中不同字符的个数,要求算出所有串的distance's 最小 sum. AC代码如下: #i ...
- POJ 1789 -- Truck History(Prim)
POJ 1789 -- Truck History Prim求分母的最小.即求最小生成树 #include<iostream> #include<cstring> #incl ...
- POJ1789 Truck History 【最小生成树Prim】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18981 Accepted: 7321 De ...
- POJ 1789:Truck History(prim&&最小生成树)
id=1789">Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17610 ...
- poj 1789 Truck History 最小生成树 prim 难度:0
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19122 Accepted: 7366 De ...
- Kuskal/Prim POJ 1789 Truck History
题目传送门 题意:给出n个长度为7的字符串,一个字符串到另一个的距离为不同的字符数,问所有连通的最小代价是多少 分析:Kuskal/Prim: 先用并查集做,简单好写,然而效率并不高,稠密图应该用Pr ...
- poj1789 Truck History
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20768 Accepted: 8045 De ...
- poj 1789 Truck History 最小生成树
点击打开链接 Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15235 Accepted: ...
随机推荐
- 13、scala模式匹配
1.模式匹配的基础语法 2.对类型进行模式匹配 3.对Array和List的元素进行模式匹配 4.case class与模式匹配 5.Option与模式匹配 1.模式匹配的基础语法 Scala提供了m ...
- codeforces_734C_二分
C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...
- HDU_Reward_拓扑排序
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- DOM节点的获取
document.getElementById();//id名,在实际开发中较少使用,选择器中多用class id一般只用在顶级层存在 不能太过依赖id document.getElements ...
- 【LeetCode】1、Two Sum
题目等级:Easy 题目描述: Given an array of integers, return indices of the two numbers such that they add u ...
- 18清明校内测试T3
扫雷(mine) Time Limit:1000ms Memory Limit:128MB 题目描述 rsy最近沉迷于一款叫扫雷的游戏. 这个游戏是这样的.一开始网格上有n*m个位置,其中有一些位 ...
- [LUOGU] 4933 大师
\(Orz\) \(ljt12138!\) 设状态\(f[i][j]\)表示以\(i\)为结尾,公差为\(j\)的长度大于\(1\)的数列有几个. 然后转移方程就很好想了. \(k=H[i]-H[j] ...
- 2017 Multi-University Training Contest - Team 4 Classic Quotation
Classic Quotation Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Othe ...
- Python 3 条件语句
条件语句: 用于判定,判定是否符合某条件,符合则执行,不符合则不执行该条件所定义的操作. 一步判定: 用于理解不会这样使用. if 1==1: if条件判定只能出现一次. print(&q ...
- python正则匹配——中文字符的匹配
# -*- coding:utf-8 -*- import re '''python 3.5版本 正则匹配中文,固定形式:\u4E00-\u9FA5 ''' words = 'study in 山海大 ...