CF GYM 100703A Tea-drinking
题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值。
解法:克鲁斯卡尔。将茶的配方作为点,将每两个点之间的差值作为边权,求最小生成树,这棵树中最大的边即为答案。
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
string s[1005];
int cal(int i, int j)
{
int res = 0;
for(int k = 0; k < s[i].size(); k++)
res = max(res, abs(s[i][k] - s[j][k]));
return res;
}
struct node
{
int u, v;
int val;
node(int u, int v, int val) : u(u), v(v), val(val) {}
node() {}
bool operator < (const node &tmp) const
{
return val < tmp.val;
}
};
vector <node> edge;
int father[1005];
int Find(int a)
{
if(a != father[a])
father[a] = Find(father[a]);
return father[a];
}
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m))
{
for(int i = 0; i < 1005; i++)
father[i] = i;
for(int i = 0; i < n; i++)
{
cin >> s[i];
}
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++)
{
edge.push_back(node(i, j, cal(i, j)));
}
int ans = 0;
sort(edge.begin(), edge.end());
int len = edge.size();
for(int i = 0; i < len; i++)
{
int a = Find(edge[i].u), b = Find(edge[i].v);
if(a != b)
{
father[a] = b;
ans = edge[i].val;
}
}
printf("%d\n", ans);
}
return 0;
}
CF GYM 100703A Tea-drinking的更多相关文章
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
- cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)
题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CF Gym 100685E Epic Fail of a Genie
传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...
- CF GYM 100703B Energy Saving
题意:王子每月买m个灯泡给n个房间换灯泡,如果当前有的灯泡数够列表的第一个房间换的就全换,直到灯泡不够为止,给出q个查询,查询x月已经换好几个房子,手里还剩多少灯泡. 解法:水题……小模拟. 代码: ...
- CF GYM 100703F Game of words
题意:两个人玩n个游戏,给出每人玩每个游戏的时间,两个人需要在n个游戏中挑m个轮流玩,求最短时间. 解法:dp.(这场dp真多啊……话说也可以用最小费用最大流做……然而并不会XD)dp[i][j][k ...
- CF GYM 100703G Game of numbers
题意:给n个数,一开始基数为0,用这n个数依次对基数做加法或减法,使基数不超过k且不小于0,输出最远能运算到的数字个数,输出策略. 解法:dp.dp[i][j]表示做完第i个数字的运算后结果为j的可能 ...
- CF GYM 100703I Endeavor for perfection
题意:有n个学习领域,每个领域有m个课程,学习第i个领域的第j个课程可以获得sij个技能点,在每个领域中选择一个课程,要求获得的n个技能点的最大值减最小值最小,输出符合要求的策略. 解法:尺取法.将课 ...
随机推荐
- PDF ITextSharp
示例源码 //Document:(文档)生成pdf必备的一个对象,生成一个Document示例 Document document = new Document(PageSize.A4, 30, 30 ...
- 元类metaClass
metaClass 实现动态改变对象的能力,这点特别像python(metaClass),Python中类(不是元类)的概念借鉴于Smalltalk groovy demo: class Person ...
- 可视化Windows服务定时任务
思路:1.新建一个<Windows服务项目>,在里面建服务文件(可以多个),用来做要执行的任务. 2.新建一个<Windows窗体应用程序>,在这个程序里管理服务.如:安装.卸 ...
- 软件测试 -- 软件缺陷记录的5C原则
Correct(准确):每个组成部分的描述准确,不会引起误解: Clear(清晰):每个组成部分的描述清晰,易于理解: Concise(简洁):只包含必不可少的信息,不包括任何多余的内容: Compl ...
- Bootstrap 内核引用(一)
方法一: Bootstrap CDN推荐 本站实例采用的是百度的静态资源库(http://cdn.code.baidu.com/)上的Bootstrap资源. 百度的静态资源库的 CDN 服务,访问速 ...
- ubuntu系统使用快捷键打开终端方式总结
ctrl + alt + T 三键齐下打开虚拟终端 ctrl + alt + F1 (~F6)打开系统终端ctrl + alt + F7 返回图形界面都可以使用exit命令关闭, 不同的是虚拟终端ex ...
- Delphi XE5 如何设计并使用FireMonkeyStyle(转)
如何设计并使用FireMonkeyStyle FireMonkey使用Style来控制控件的显示方式. 每个控件都有一个StyleLookup属性,FireMonkey就是通过控件的这个属性来在当前窗 ...
- 【贪心】bzoj 3709:[PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 653 Solved: ...
- bzoj 1228: [SDOI2009]E&D 阿达马矩阵
1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 448 Solved: 240[Submit][Sta ...
- 关于.net中的脚本语言使用
基于.net中drl框架的脚本现在有很多,最近也由于工作的需要,目前有lua.python.ruby.javascript的.net实现,对ruby不怎么了解,python.lua.js就成了试验的对 ...