最小生成树,一次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)相关推荐

  1. Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies

    这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...

  2. 2021-11-28比赛博客

    CodeForces 1196A-Three Piles of Candies 题意: 两个人分三堆糖果,第一个人任选一堆,另一个人在剩下的两堆中任选一堆,最后一堆协商分配,如果其中一个人糖果多,则丢 ...

  3. Codeforces 1196A Three Piles of Candies

    https://codeforces.com/contest/1196/problem/A 题解: /* *@Author: STZG *@Language: C++ */ #include < ...

  4. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  5. 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 ...

  6. Codeforces Round #636 (Div. 3) ——A. Candies 题解

    题目链接:https://codeforces.com/contest/1343/problem/A 签到题,for循环暴力枚举即可. 代码如下: #include <bits/stdc++.h ...

  7. 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 ​ ...

  8. codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]

    A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...

  9. 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> ...

最新文章

  1. 近期上海面试总结(一)
  2. Python 技术篇-通过管道命令获取cmd执行的结果,获取os.system()、subprocess.Popen()执行命令返回的结果
  3. 王亚楠:基于强化学习的自动码率调节
  4. 用c语言实现0到59的数码管,跪求单片机0~99数码管显示用C语言编写的程序
  5. 实际操作之路考的这些事
  6. 关于更改当前公司(一)--ChangeCompany
  7. mysql 导入导出脚本_MySQL导入和导出sql脚本
  8. listdir在python3_Python3 os.listdir() 方法
  9. Jquery append 方法在ie8不兼容问题
  10. sql limit 子句_SQL有子句–综合指南
  11. 如何在C#窗体中定义全局变量
  12. 请详细描述listview与gridview的异同点_专利和著作权有什么异同点,听听专业人士怎么说...
  13. 苹果手机怎么投屏王者荣耀
  14. 【PostgreSQL逻辑复制数据同步到kafka】
  15. IT 行业:前端和后端分别是要做什么?哪个方向加班时间更多?
  16. uniapp 小程序实现 RSA 加密
  17. Api 数据自动入库
  18. 编译Android源码,执行lunch命令时报错“No such file: /root/.lunchrc”的解决办法
  19. Netty游戏服务器实战开发(6):Netty整合Zookeeper实现分布式服务发现与注册
  20. 上线MSF(Metasploit)的几种常见方式

热门文章

  1. C++的学习心得和知识总结 第十三章(完)
  2. Linux热插拔硬盘导致盘符漂移,一种解决热插拔时磁盘盘符漂移方法及装置与流程...
  3. cocos2dx tolua ++ 使用 常见得错误
  4. C# Microsoft.Office.Interop.Excel 引用的用法
  5. hone hone clock 人体时钟
  6. 【爱软测】Jmeter数据关联之json提取器
  7. 一文搞定晶晨S905L3A电视盒子刷Armbian
  8. cmake的file命令
  9. fixed定位 input在IOS设备上光标位置异常问题
  10. 医疗卫生行业数据如何保护?云备份不惧勒索攻击