LGOJ3101 [USACO14JAN]滑雪等级Ski Course Rating
LGOJ3101 [USACO14JAN]滑雪等级Ski Course Rating
【问题描述】
The cross-country skiing course at the winter Moolympics is described by an M x N grid of elevations (1 <= M,N <= 500), each elevation being in the range 0 .. 1,000,000,000.
Some of the cells in this grid are designated as starting points for the course. The organizers of the Moolympics want to assign a difficulty rating to each starting point. The difficulty level of a starting point P should be the minimum possible value of D such that a cow can successfully reach at least T total cells of the grid (1 <= T <= MN), if she starts at P and can only move from cell to adjacent cell if the absolute difference in elevation between the cells is at most D. Two cells are adjacent if one is directly north, south, east, or west of the other.
Please help the organizers compute the difficulty rating for each starting point.
滑雪场用一个M*N(1 <= M,N <= 500)的数字矩阵表示海拔高度,每个数字表示一个范围在0 .. 1,000,000,000的高度。有些格子被指定为起点,组织者想对这些起点做难度评级。
如果起点P点是一个难度级别为D的起点,则D必须是满足以下条件的一个最小值:
(1)从一个格子只能滑到相邻的格子;
(2)这两个格子的海拔差不超过D;
(3)至少能够到达T(1 <= T <= M*N)个格子(包括起点本身)。
【输入样例】
3 5 10
20 21 18 99 5
19 22 20 16 17
18 17 40 60 80
1 0 0 0 0
0 0 0 0 0
0 0 0 0 1
【输出样例】
24
#include<bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
const int maxm = maxn * maxn;
long long am[maxm], fa[maxm], is[maxm];
//am amount 集合子点数量 ,fa father 父节点编号 , is is_start 集合内的起点个数
long long he[maxn][maxn], id[maxn][maxn];
//he height (i,j)高度
long long n, m, t, cntv, sign, cnte;
//cntv count_vertex,cnte count_edge
struct edge
{
long long beg, to, len; // beg起点 , to 终点 ,len 边权
} a[1000000]; //血泪(必须要开1000000)
edge mk(long long x,long long y, long long z)
{
edge t = (edge)
{
x, y, z
};
return t;
}//这是一个制作边的函数
bool cmp(edge a, edge b)
{
return a.len < b.len;
}//这是一个将边排序的函数(服务于贪心思想)
long long find(long long x)
{
if(x == fa[x])return x;
else return fa[x] = find(fa[x]);
}//并查集标准find函数
void merge(int x, int y)
{
if(x < y)swap(x, y); fa[y] = x;
am[x] += am[y];
// am[y] = 0;
is[x] += is[y];
}//这是一个合并函数(维护了两个集合的子点数个数,起点个数)
int main()
{
scanf("%lld%lld%lld", &n, &m, &t); for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
scanf("%lld", &he[i][j]);
cntv++;
id[i][j] = cntv;
//给坐标为(i,j)的点编号 cntv
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
scanf("%lld", &sign); if(sign)is[id[i][j]] = 1;//这个点是一个起点 if(i < n)
{
a[++cnte] = mk(id[i][j], id[i + 1][j], abs(he[i][j] - he[i + 1][j]));
} if(j < m)
{
a[++cnte] = mk(id[i][j], id[i][j + 1], abs(he[i][j] - he[i][j + 1]));
} //建边
}
} sort(a + 1, a + 1 + cnte, cmp); //贪心 long long ans = 0; for(int i = 1; i <= maxm; i++)
{
am[i] = 1; //i是自己的一个集
fa[i] = i;
}
for(int i = 1; i <= cnte; i++)
{
int x = a[i].beg;
int y = a[i].to;
int z = a[i].len;
int fx = find(x);
int fy = find(y);
if(fx==fy)continue; if(am[fx] + am[fy] >= t)
{
if(am[fx] < t)ans += z * is[fx];
//如果一个集合的数目小于t,则其没有算过边。
if(am[fy] < t)ans += z * is[fy];
} merge(fx, fy);
} printf("%lld", ans);
return 0;
}
LGOJ3101 [USACO14JAN]滑雪等级Ski Course Rating的更多相关文章
- [USACO14JAN]滑雪等级Ski Course Rating
题目描述 The cross-country skiing course at the winter Moolympics is described by an M x N grid of eleva ...
- 【USACO2009 Open】滑雪课程ski
[USACO2009 Open]滑雪课程 Ski Lessons Time Limit: 1000 ms Memory Limit: 131072 KBytes Description 约翰请贝西去科 ...
- [USACO14JAN]Ski Course Rating G
题目链接:https://www.luogu.com.cn/problem/P3101 Slove 这题我们可以尝试建立一个图. 以相邻的两个点建边,边的权值为两个点高度差的绝对值,然后把边按照边权值 ...
- [USACO09OPEN]滑雪课Ski Lessons
题目描述 Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good sk ...
- BZOJ 1571: [Usaco2009 Open]滑雪课Ski
Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S& ...
- [bzoj1571][Usaco2009 Open]滑雪课Ski
题目描述 Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S<=100 ...
- 【贪心优化dp决策】bzoj1571: [Usaco2009 Open]滑雪课Ski
还有贪心优化dp决策的操作…… Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里 ...
- BZOJ——1571: [Usaco2009 Open]滑雪课Ski
http://www.lydsy.com/JudgeOnline/problem.php?id=1571 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: ...
- [USACO2009 OPEN] 滑雪课 Ski Lessons
洛谷P2948 看到题目就觉得这是动规但一直没想到如何状态转移……看了别人的题解之后才有一些想法 f[i][j]:前i单位时间能力值为j可以滑的最多次数 lessons[i][j]:结束时间为i,获得 ...
随机推荐
- RocketMQ消息丢失解决方案:同步刷盘+手动提交
前言 之前我们一起了解了使用RocketMQ事务消息解决生产者发送消息时消息丢失的问题,但使用了事务消息后消息就一定不会丢失了吗,肯定是不能保证的. 因为虽然我们解决了生产者发送消息时候的消息丢失问题 ...
- Win32编程之控制线程
0x01. 如何让线程停下来 让自己停下来: Sleep() 函数 当程序执行到某段代码的时候可以使用sleep() 函数进行暂停 使用sleep()函数挂起的时候会自动恢复过来的 让别人停下来: S ...
- Redis---08Redis集群(一)
一.什么是Redis集群 Redis 集群实现了对Redis的水平扩容,即启动N个redis节点,将整个数据库分布存储在这N个节点中,每个节点存储总数据的1/N. Redis 集群通过分区(parti ...
- python中拿不到字典value值得问题解决
在python项目的练习中,根据字典的key值get不到value值,如图所示: 最后,将user = self.allUsers.get(cardNum)改成user = self.allUsers ...
- NB-IoT DTU是什么 NB-IoT的优势有哪些
NB-IoT DTU是什么 NB-IoT DTU是一种采用NB-IoT技术实现数据远距离无线传输功能的终端设备,采用工业级的硬件设施和工业级的32位高性能通信处理器,工业级的无线数据传输模块,可以自动 ...
- Django实现文件上传功能
文件上传 关注公众号"轻松学编程"了解更多. 1.创建上传文件夹 在static文件夹下创建uploads用于存储接收上传的文件 在settings中配置,MEDIA_ROOT=o ...
- (六)HTTP和HTTPS(转)
一.HTTP和HTTPS的基本概念 HTTP:用于从WWW服务器传输超文本到本地浏览器的传输协议,它可以使浏览器更加高效,使网络传输减少. HTTPS:是以安全为目标的HTTP通道,简单讲是HTTP的 ...
- 汉诺塔问题实验--一个简洁的JAVA程序
思路: 这里使用递归法 n==1的时候,直接把它从x移到z位置即可. 如果是n层,我们首先把上面的n- 1层移到y位置,然后把最 下面的那个最大的盘子,移到z位置,然后把y上面放的上面n-1层移到z位 ...
- 【SpringBoot】06.SpringBoot访问静态资源
SpringBoot访问静态资源 1.SpringBoot从classpath/static的目录 目录名称必须是static 启动项目,访问http://localhost:8080/0101.jp ...
- 15 CGI和WSGI
15 CGI和WSGI CGI是通用网关接口,是连接web服务器和应用程序的接口,用户通过CGI来获取动态数据或文件等. CGI程序是一个独立的程序,它可以用几乎所有语言来写,包括perl,c,lua ...