cogs服务点设置(不凶,超乖) x
cogs3. 服务点设置
★ 输入文件:djsa.in 输出文件:djsa.out 简单对比
时间限制:1 s 内存限制:128 MB
为了进一步普及九年义务教育,政府要在某乡镇建立一所希望小学,该乡镇共有n个村庄,村庄间的距离已知,请问学校建在哪个村庄最好?(好坏的标准是学生就近入学,即在来上学的学生中,以最远的学生走的路程为标准。或者说最远的学生与学校的距离尽可能的小。)

0 2 10
0 4 30
0 5 100
1 2 5
2 3 50
3 5 10
4 3 20
4 5 60
要最远的学生与学校的距离尽可能小.
所以 若找到了使得当前枚举的最远的学生与学校距离比以前枚举的更近的话,就进行更新最远距离和学校编号
坑点:
记得每次找最远距离的时候都要清空找到的上一个最远距离(minl)
上代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std; const int Maxint = ;
const int N = ;
int n,m,p,minl=Maxint,maxl=Maxint;
int map[N][N]; int main()
{
freopen("djsa.in","r",stdin);
freopen("djsa.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
map[i][j]=Maxint;
map[i][i]=;
}
for(int i=,u,v,w;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
map[u][v]=w,map[v][u]=w;
}
/*floyd*/
for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(map[i][j]>map[i][k]+map[k][j])
map[i][j]=map[i][k]+map[k][j];
for(int i=;i<n;i++)
{
minl=;
for(int k=;k<n;k++)
minl=max(minl,map[i][k]);
if(maxl>minl)
{
maxl=minl;
p=i;
}
}
printf("%d",p);
return ;
}
cogs4. 双服务点设置
☆ 输入文件:djsb.in 输出文件:djsb.out 简单对比
时间限制:1 s 内存限制:128 MB
问题描述
为了进一步普及九年义务教育,政府要在某乡镇建立两所希望小学,该乡镇共有n个村庄,村庄间的距离已知,请问学校建在哪两个村庄最好?(好坏的标准是学生就近入学,即在来上学的学生中,以最远的学生走的路程为标准。或者说最远的学生与学校的距离尽可能的小。)
.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
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std; const int Maxint = ;
const int N = ;
int n,m,p1,p2,minl=Maxint,maxl=Maxint;
int map[N][N]; int main()
{
freopen("djsb.in","r",stdin);
freopen("djsb.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
map[i][j]=Maxint;
map[i][i]=;
}
for(int i=,u,v,w;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
map[u][v]=w,map[v][u]=w;
}
/*floyd*/
for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(map[i][j]>map[i][k]+map[k][j])
map[i][j]=map[i][k]+map[k][j];
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
minl=;
for(int k=;k<n;k++)
{
/*
if(i==k || j==k)
continue;
*/
int emmmm=min(map[i][k],map[j][k]);
minl=max(minl,emmmm);
}
if(maxl>minl)
{
maxl=minl;
p1=i,p2=j;
}
}
}
printf("%d %d",p1,p2);
return ;
}
嘻嘻,5还没写啦~
cogs服务点设置(不凶,超乖) x的更多相关文章
- cogs 服务点设置
3. 服务点设置 ☆ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立一所 ...
- COGS 5. P服务点设置
5. P服务点设置 http://www.cogs.pro/cogs/problem/problem.php?pid=5 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对 ...
- cogs 3. 服务点设置 dijkstra
3. 服务点设置 ★ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 为了进一步普及九年义务教育,政府要在某乡镇建 ...
- cogs p服务点设置
5. P服务点设置 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对比时间限制:2 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立 ...
- cogs 双服务点设置
4. 双服务点设置 ☆ 输入文件:djsb.in 输出文件:djsb.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立两 ...
- dfs -cogs 5 P服务点设置
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=FSXJmiJSg 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立P所希望小学 ...
- 利用efi功能更改bios主板被隐藏的设置(如超频)
整理自(来源): http://tieba.baidu.com/p/4934345324 ([新手教程]利用EFI启动盘修改 隐藏bios设置) http://tieba.baidu.com/p/49 ...
- Charles设置断点- (超详解)
1.选择你要设置断点的接口 2.右键选择 Breakpoints 3.断点的相关配置, Proxy ——>Breakpoint Settings 5.双击刚刚已经设置的断点接口,进行设置 6. ...
- IDEA中设置背景图片(超详细)
文章目录 1.效果图 2.详细设置过程 1.效果图 2.详细设置过程
随机推荐
- js,bom,dom(相信我,你看不懂我写的)
js dom bom 2种结合方式: 1.在body中加入script标签,<script type="text/javascript" >alert(" 向 ...
- Contains Duplicate III -leetcode
Contains Duplicate III Given an array of integers, find out whether there are two distinct indices i ...
- asp.net练习②——Paginaton无刷新分页
aspx代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server" ...
- Separate String
Separate String 时间限制: 1 Sec 内存限制: 128 MB提交: 50 解决: 16 题目描述 You are given a string t and a set S of ...
- MyBatis 体系结构、根配置文件、Mapper映射文件
一.MyBatis的体系结构 1.SqlSessionFactory对象 SqlSessionFactory对象是MyBatis的管理核心,它是单个数据库映射关系经过编译后的内存镜像,是创建SqlSe ...
- JS基础_if语句
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- python numpy 的用法——diag函数
当 np.diag(array) 中 array是一个1维数组时,结果形成一个以一维数组为对角线元素的矩阵 array是一个二维矩阵时,结果输出矩阵的对角线元素
- python eval内置函数作用
功能:将字符串str当成有效的表达式来求值并返回计算结果. 语法: eval(source[, globals[, locals]]) -> value 参数: source:一个Python表 ...
- Win10 OpenCV3.3.0+VS2013配置大坑,OpenCV解决方案编译报错“找不到python36_d.lib”错误
今天因为想要用OpenCV做图像识别,小白一个,在网上找到一个教程,但是需要配置OpenCV3.3.0的环境,于是又在网上找OpenCV3.3.0+VS2013(因为我之前已经安过了VS2013),前 ...
- Delphi MSComm控件的错误消息