CodeForces 436C (Dungeons and Candies)
最小生成树,一次ac(兴奋ing)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct edge
{int x, y, w;
}e[1001];
const int N = 1e5 + 5,MAX=99999999;
int n, m, k, w;
char s[1001][121]; int dis[1001][1001], low[1001]; edge ee[1001];
int main() {scanf("%d%d%d%d", &n, &m, &k, &w);int cnt = 0;for (int i = 0; i < k; i++){for (int j = 0; j < n; j++){scanf("%s", s[i] + j*m);}}for (int i = 0; i < k; i++){for (int j = i + 1; j < k; j++){for (int l = 0; l < n*m; l++){dis[i+1][j+1] += s[i][l] != s[j][l];}dis[i + 1][j + 1] *= w;dis[j+1][i+1] = dis[i+1][j+1];}}for (int i = 1; i <= k; i++){dis[0][i] = dis[i][0] = n*m;}for (int j = 1; j <= k; j++){low[j] = n*m; ee[j] = edge{ j, 0, n*m };}int ans = 0;for (int i = 0; i < k; i++){int index = -1, Min = MAX;for (int j = 1; j <= k; j++){if (low[j] != -1 && low[j] < Min){Min = low[j];index = j;}}e[cnt++] = edge{ index, ee[index].y, Min };low[index] = -1;ans += Min;for (int j = 1; j <= k; j++){if (low[j] != -1 && low[j]>dis[index][j]){low[j] = dis[index][j];ee[j].y = index;ee[j].w = low[j];}}}printf("%d\n", ans);for (int i = 0; i < cnt; i++){printf("%d %d\n", e[i].x, e[i].y);}return 0;
}
CodeForces 436C (Dungeons and Candies)相关推荐
- Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies
这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...
- 2021-11-28比赛博客
CodeForces 1196A-Three Piles of Candies 题意: 两个人分三堆糖果,第一个人任选一堆,另一个人在剩下的两堆中任选一堆,最后一堆协商分配,如果其中一个人糖果多,则丢 ...
- Codeforces 1196A Three Piles of Candies
https://codeforces.com/contest/1196/problem/A 题解: /* *@Author: STZG *@Language: C++ */ #include < ...
- CF思维联系– CodeForces - 991C Candies(二分)
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...
- Codeforces Round #634 (Div. 3)A. Candies and Two Sisters
题目: A. Candies and Two Sisters time limit per test : 1 second memory limit per test : 256 megabytes ...
- Codeforces Round #636 (Div. 3) ——A. Candies 题解
题目链接:https://codeforces.com/contest/1343/problem/A 签到题,for循环暴力枚举即可. 代码如下: #include <bits/stdc++.h ...
- B - Equal Candies CodeForces - 1676B
There are nn boxes with different quantities of candies in each of them. The ii-th box has a_ia i ...
- codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]
A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...
- Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1
A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...
最新文章
- 近期上海面试总结(一)
- Python 技术篇-通过管道命令获取cmd执行的结果,获取os.system()、subprocess.Popen()执行命令返回的结果
- 王亚楠:基于强化学习的自动码率调节
- 用c语言实现0到59的数码管,跪求单片机0~99数码管显示用C语言编写的程序
- 实际操作之路考的这些事
- 关于更改当前公司(一)--ChangeCompany
- mysql 导入导出脚本_MySQL导入和导出sql脚本
- listdir在python3_Python3 os.listdir() 方法
- Jquery append 方法在ie8不兼容问题
- sql limit 子句_SQL有子句–综合指南
- 如何在C#窗体中定义全局变量
- 请详细描述listview与gridview的异同点_专利和著作权有什么异同点,听听专业人士怎么说...
- 苹果手机怎么投屏王者荣耀
- 【PostgreSQL逻辑复制数据同步到kafka】
- IT 行业:前端和后端分别是要做什么?哪个方向加班时间更多?
- uniapp 小程序实现 RSA 加密
- Api 数据自动入库
- 编译Android源码,执行lunch命令时报错“No such file: /root/.lunchrc”的解决办法
- Netty游戏服务器实战开发(6):Netty整合Zookeeper实现分布式服务发现与注册
- 上线MSF(Metasploit)的几种常见方式
热门文章
- C++的学习心得和知识总结 第十三章(完)
- Linux热插拔硬盘导致盘符漂移,一种解决热插拔时磁盘盘符漂移方法及装置与流程...
- cocos2dx tolua ++ 使用 常见得错误
- C# Microsoft.Office.Interop.Excel 引用的用法
- hone hone clock 人体时钟
- 【爱软测】Jmeter数据关联之json提取器
- 一文搞定晶晨S905L3A电视盒子刷Armbian
- cmake的file命令
- fixed定位 input在IOS设备上光标位置异常问题
- 医疗卫生行业数据如何保护?云备份不惧勒索攻击