dfs -cogs 5 P服务点设置
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=FSXJmiJSg
问题描述
为了进一步普及九年义务教育,政府要在某乡镇建立P所希望小学,该乡镇共有n个村庄,村庄间的距离已知,请问学校建在哪P个村庄最好?(好坏的标准是学生就近入学,即在来上学的学生中,以最远的学生走的路程为标准。或者说最远的学生与学校的距离尽可能的小。)
.gif)
0 2 10
0 4 30
0 5 100
1 2 5
2 3 50
3 5 10
4 3 20
4 5 60
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#define MAXN 110
using namespace std;
int edge[MAXN][MAXN];
int res[MAXN];
int temp[MAXN]; //临时数组
int n, m, p, maxDis, minDis = , ans = ; void dfs(int x, int now) //x表示往数组里加了几个,now表示加的点
{
if (x == p + )
{
maxDis = ;
for (int i = ; i < n; i++)
{
minDis = ;
for (int j = ; j <= p; j++)
{
minDis = min(minDis, edge[i][temp[j]]); //找到村庄i与p个学校最近的那个学校的距离
}
maxDis = max(maxDis, minDis); //找到以后更新最远的距离
}
if (ans > maxDis) //最远的学生走的路最少
{
ans = maxDis;
memset(res, , sizeof(res));
for (int i = ; i < n; i++)
res[i] = temp[i];
}
return;
}
for (int i = now + ; i < n; i++)
{
temp[x] = i;
dfs(x + , i);
}
} int main()
{
freopen("djsc.in", "r", stdin);
freopen("djsc.out", "w", stdout);
int x, y, v;
scanf("%d %d %d", &n, &m, &p);
for(int i = ; i < n; i++)
for (int j = ; j < n; j++)
{
edge[i][j] = ;
edge[i][i] = ;
}
for (int i = ; i < m; i++)
{
scanf("%d%d%d", &x, &y, &v);
edge[x][y] = edge[y][x] = v;
}
for (int k = ; k < n; k++)
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
dfs(, -);
for (int i = ; i <= p; i++)
printf("%d ", res[i]);
return ;
}
dfs -cogs 5 P服务点设置的更多相关文章
- COGS 5. P服务点设置
5. P服务点设置 http://www.cogs.pro/cogs/problem/problem.php?pid=5 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对 ...
- cogs p服务点设置
5. P服务点设置 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对比时间限制:2 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立 ...
- cogs 双服务点设置
4. 双服务点设置 ☆ 输入文件:djsb.in 输出文件:djsb.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立两 ...
- cogs 服务点设置
3. 服务点设置 ☆ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立一所 ...
- cogs服务点设置(不凶,超乖) x
cogs3. 服务点设置 ★ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇 ...
- cogs 3. 服务点设置 dijkstra
3. 服务点设置 ★ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 为了进一步普及九年义务教育,政府要在某乡镇建 ...
- 8.1.2hadoop Streaming 作业原理和参数设置
1.1.1 Stream 作业 (1)hadoop streaming Hadoop streaming是hadoop的一个工具,用于运行费java的maper或reducer作业,例 ...
- Hadoop总结篇之三---一个Job到底被提交到哪去了
我们会定义Job,我们会定义map和reduce程序.那么,这个Job到底是怎么提交的?提交到哪去了?它到底和集群怎么进行交互的呢? 这篇文章将从头讲起. 开发hadoop的程序时,一共有三大块,也就 ...
- hadoop日常运维与升级总结
日常运维 升级 问题处理方法 日常运维 进程管理 由于配置文件的更改,需要重启生效, 或者是进程自己因某种致命原因终止, 或者发现进程工作出现异常等情况下,需要进行手动进程的关闭或启动, 或者是增删节 ...
随机推荐
- 数字签名 转载:http://www.youdzone.com/signature.html
What is a Digital Signature?An introduction to Digital Signatures, by David Youd Bob (Bob's public k ...
- confluence配置搭建
1.环境准备:需要安装jdk.需要mysql5.7数据库,创建数据库confluence并创建用户和密码 CREATE DATABASE `confluence` DEFAULT CHARACTER ...
- retrying failed action with response code: 403 错误解决
[2019-06-10T06:52:51,610][INFO ][logstash.outputs.elasticsearch] retrying failed action with respons ...
- Codeforces Round #590 (Div. 3) C. Pipes
链接: https://codeforces.com/contest/1234/problem/C 题意: You are given a system of pipes. It consists o ...
- 牛客寒假算法基础集训营2 【处女座与复读机】DP最小编辑距离【模板题】
链接:https://ac.nowcoder.com/acm/contest/327/G来源:牛客网 一天,处女座在牛客算法群里发了一句“我好强啊”,引起无数的复读,可是处女座发现复读之后变成了“处女 ...
- Educational Codeforces Round 33 (Rated for Div. 2) D题 【贪心:前缀和+后缀最值好题】
D. Credit Card Recenlty Luba got a credit card and started to use it. Let's consider n consecutive d ...
- JAVA日期格式转换---让人不得不说的故事
链接:https://my.oschina.net/xinxingegeya/blog/394821 这是给我自己参考的,大家不惜勿喷 1.举例使用 2.各种作用 3.坑(默认中文日期,加上这个就是英 ...
- centos 7配置静态IP,并配置DNS
注意:四 个文件 cat /etc/sysconfig/network-scripts/ifcfg-eth0 cat /etc/sysconfig/network cat /etc/resolv.co ...
- python 获取数字在内存的内容
#coding=utf- from struct import pack,unpack byte=pack('f',1.5) print(byte) print([i for i in byte]) ...
- Codeforces 126B. Password(KMP,DP)
Codeforces 126B. Password 题意:一个字符串,找出最长的子串t,它既是前缀又是后缀,还出现在中间.输出t,不存在则输出Just a legend. 思路:利用KMP算法处理出n ...