[JOI2017] サッカー (Soccer)
原题题面看不懂的可以看下面的\(CJ\)版中文题面












$
$
\(CJ\)版:






$
$
这道题是\(JOI\)的\(T4\),放到联赛大概就是\(Day2,T3\)的难度
$
$
\(5\)分:
这一档分就是一个分类讨论,因为\(N=2\)
一共有\(3\)种情况可以出现最优解:
- \(1\)带球跑到\(2\),\(ans=C*(\left|h1-h2\right|+\left|w1-w2\right|)\)
- \(1\)带球纵向跑到与\(2\)齐平,踢球,\(ans=C*\left|h1-h2\right|+A*\left|w1-w2\right|+B\)
- \(1\)带球横向跑到与\(2\)齐平,踢球,\(ans=C*\left|w1-w2\right|+A*\left|h1-h2\right|+B\)
另外\(30\)分:
\(A=0\),也就是说踢球不取决于距离,踢球的花费完全取决于踢球的次数。
所以这里有两个结论,为了达到最优解,一个人不会踢球两次,一个人不会跑到其他地方去捡球来踢,这个结论画几个图就能够看出来,就不证明了。
那么整个过程就可以简化成:一个人带球跑,踢球,另一人接球,带球,再踢球。。。
这样就可以通过这个求出一个点到另一个点的最小花费,最后跑个最短路就可以求出来
\(100\)分:
这一问没有了\(A=0\)的条件,不过没有关系,上面的结论依然能用,一个人不会踢球两次。
而且这一问的\(N\)比较大,所以不可能直接对运动员进行处理。
然后我们就来想一下其他的做法。满数据的\(H\),\(W\)都比较小,我们可以把对运动员的处理换成直接对网格的处理。
设\(a[x][y]\)为步行到\((x,y)\)这个点的最小花费,这个可以\(bfs\)处理出来。
设\(ans[x][y][k]\),为在\((x,y)\)这个点时的几个状态的最小疲劳值,当\(0\le k\le3\)时,表示球从\(k\)方向滚到\((x,y)\)的最小疲劳值;当\(k=4\)时,表示运动员在\((x,y)\)持球的最小疲劳值。
那么具体怎么转移呢?
对于一个\(k=4\)的状态,它可以这样转移:
- 向各个方向走一格,\(ans[x'][y'][4]=ans[x][y][4]+C\);
- 向各个方向踢出球,\(ans[x][y][k']=ans[x][y][4]+B\);
对于一个\(k!=4\)的状态,它可以这样转移:
- 继续向前滚,\(ans[x'][y'][k]=ans[x][y][k]+A\);
- 一个运动员跑过来持球,\(ans[x][y][4]=ans[x][y][k]+C*a[x][y]\);
这个算法可以通过\(Dij\)来实现,最终的答案就是\(ans[hn][wn][4]\)。
时间复杂度:\(O(HW*logHW)\)
$
$
//made by Hero_of_Someone
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define inf (1e17)
#define ll long long
#define il inline
#define RG register
using namespace std;
il int gi(){ RG int x=0,q=1; RG char ch=getchar(); while( ( ch<'0' || ch>'9' ) && ch!='-' ) ch=getchar();
if( ch=='-' ) q=-1,ch=getchar(); while(ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; }
il void File(){freopen("soccer.in","r",stdin); freopen("soccer.out","w",stdout);}
int h,w,n;
ll A,B,C;
ll a[540][540];
ll dis[50000010];
int H[1000010],W[1000010];
int qh[1000010],qw[1000010];
bool vis[540][540],v[50000010];
int dh[]={0,-1,0,1},dw[]={-1,0,1,0};
struct heap{
#define fa (x>>1)
#define ls (x<<1)
#define rs (x<<1|1)
int b[50000010],id[50000010],len;
il int top(){ return b[1]; }
il void push(RG int u){
if(!id[u]) id[u]=++len,b[len]=u; RG int x=id[u];
while(fa){
if(dis[b[x]]>=dis[b[fa]]) break;
swap(b[x],b[fa]),id[b[x]]=x,id[b[fa]]=fa,x=fa;
}
return;
}
il void pop(){
id[b[1]]=0,b[1]=b[len--]; if (len) id[b[1]]=1; RG int x=1,son;
while(ls<=len){
son=(rs<=len && dis[b[rs]]<dis[b[ls]]) ? rs : ls;
if(dis[b[x]]<=dis[b[son]]) break;
swap(b[x],b[son]),id[b[x]]=x,id[b[son]]=son,x=son;
}
return;
}
#undef fa
#undef ls
#undef rs
}que;
il void init(){
h=gi(),w=gi(),A=gi(),B=gi(),C=gi(),n=gi();
for(RG int i=0;i<n;i++){
H[i]=gi(),W[i]=gi();
if(!vis[H[i]][W[i]])
vis[H[i]][W[i]]=1;
else continue;
}
for(RG int i=0;i<=h;i++)
for(RG int j=0;j<=w;j++)
a[i][j]=inf;
RG int hd=0,tl=0;
for(RG int i=0;i<=h;i++)
for(RG int j=0;j<=w;j++)
if(vis[i][j]){ a[i][j]=0;
qh[tl]=i,qw[tl++]=j;
}
while(hd<tl){
RG int x=qh[hd],y=qw[hd];
for(RG int i=0;i<4;i++){
RG int xx=x+dh[i],yy=y+dw[i];
if(xx<0||xx>h||yy<0||yy>w) continue;
if(a[xx][yy]!=inf) continue;
a[xx][yy]=a[x][y]+1;
qh[tl]=xx,qw[tl++]=yy;
}
hd++;
}
}
il void work(){
for(RG int i=0;i<=h;i++)
for(RG int j=0;j<=w;j++)
for(RG int k=0;k<=4;k++)
dis[i*5000+j+k*10000000]=inf;
RG int t=H[0]*5000+W[0]+40000000;
dis[t]=0; que.push(t);
while(que.len){
RG int q=que.top();que.pop();
if(v[q]) continue; v[q]=1;
RG ll c=dis[q];
RG int dir=q/10000000;q%=10000000;
RG int x=q/5000,y=q%5000;
if(dir==4){
for(RG int i=0;i<4;i++){
RG int xx=x+dh[i],yy=y+dw[i];
if(xx<0||xx>h||yy<0||yy>w) continue;
RG int t=xx*5000+yy+40000000;
if(c+C<dis[t]){ dis[t]=c+C; que.push(t); }
}
for(RG int i=0;i<4;i++){
RG int t=x*5000+y+10000000*i;
if(c+B<dis[t]){ dis[t]=c+B; que.push(t); }
}
}
else{
RG int t=x*5000+y+40000000;
if(c+C*a[x][y]<dis[t]){
dis[t]=c+C*a[x][y]; que.push(t);
}
RG int xx=x+dh[dir],yy=y+dw[dir];
if(xx<0||xx>h||yy<0||yy>w) continue;
t=xx*5000+yy+10000000*dir;
if(c+A<dis[t]){ dis[t]=c+A; que.push(t); }
}
}
printf("%lld\n",dis[H[n-1]*5000+W[n-1]+40000000]);
}
int main(){ File(); init(); work(); return 0; }
(没事干写手写堆来玩玩)
[JOI2017] サッカー (Soccer)的更多相关文章
- UVA 10194 Football (aka Soccer)
Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (america ...
- [JOI2017/2018]美術展
[JOI2017/2018]美術展 题目大意: 有\(n(n\le5\times10^5)\)个物品,每个物品有两个属性:尺寸\(A_i\)和收益\(B_i\).从中选取一个子集,总收益为\(\sum ...
- D - Football (aka Soccer)
Football the most popular sport in the world (americans insist to call it "Soccer", but we ...
- 每日英语:A Chinese Soccer Club Has Won Something!
A 1-1 tie at home was sufficient for Guangzhou Evergrande to clinch the Asian Champions League title ...
- CodeChef CHEFSOC2 Chef and Big Soccer 水dp
Chef and Big Soccer Problem code: CHEFSOC2 Tweet ALL SUBMISSIONS All submissions for this prob ...
- codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- 【codeforces 752F】Santa Clauses and a Soccer Championship
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- UVALive 5111 Soccer Teams (动态规划)
题意:给指定数量的数字“1”,“2”,“3”……,“9”.用所有这些数字加上任意个0组成一个数,要求数能被11整除,且数的位数尽量小. 能被11整除的数有一个特点,奇数位数字之和与偶数位之和的差为11 ...
- UOJ356 [JOI2017春季合宿] Port Facility 【启发式合并】【堆】【并查集】
题目分析: 好像跑得很快,似乎我是第一个启发式合并的. 把玩具看成区间.首先很显然如果有两个玩具的进出时间有$l1<l2<r1<r2$的关系,那么这两个玩具一定在不同的栈中间. 现在 ...
随机推荐
- 计算2个时间之间经过多少Ticks
Ticks是一个周期,存储的是一百纳秒,换算为秒,一千万分之一秒.我们需要计算2个时间之间,经过多少Ticks,可以使用下面的方法来实现,使用2个时间相减. 得到结果为正数,是使用较晚的时间减去较早的 ...
- 基于uFUN开发板的心率计(二)动态阈值算法获取心率值
前言 上一篇文章:基于uFUN开发板的心率计(一)DMA方式获取传感器数据,介绍了如何获取PulseSensor心率传感器的电压值,并对硬件电路进行了计算分析.心率计,重要的是要获取到心率值,本篇文章 ...
- Scrum与看板区别
看板:在制品(work-in-progress, WIP)必须被限制 WIP上限和拉动式生产 1. Scrum与看板简述 Scrum:组织拆分,工作拆分,开发时间拆分,优化发布计划,过程优化 看板 ...
- CSS 字体(font)实例
CSS 字体(font)实例CSS 字体属性定义文本的字体系列.大小.加粗.风格(如斜体)和变形(如小型大写字母).CSS 字体系列在 CSS 中,有两种不同类型的字体系列名称: 通用字体系列 - 拥 ...
- B. Heaters Div3
链接 [http://codeforces.com/contest/1066/problem/B] 分析 具体看代码,贪就完事了 代码 #include<bits/stdc++.h> us ...
- 手工编程:hello world
全部用命令行工具和Notepad编辑器,用手工创建并编译一个C的命令行程序:hello world. public class Hello{ public static void ma ...
- 第三个spring冲刺第10天
进入最后阶段冲刺最后一天了,基本的需求已经完成了,最后的布局问题也解决了,我们的软件正式推出了.
- mongoDB的配置和使用
如何启动mongodb? mongod --dbpath C:\appStore\mongodata //数据库地址 再开一个cmder窗口 进入C:\Program Files\MongoDB\Se ...
- 记Git报错-refusing to merge unrelated histories
记Git报错-refusing to merge unrelated histories 系统:win7 git版本: 2.16.2.windows.1 问题 1.本地初始化了git仓库,放了一些 ...
- SQLserver 使用网络驱动器恢复数据库
1. 公司内有多台虚拟机,因为公司提供出来的机器 硬盘总是不够大...所以想到了使用 映射网络驱动器的方式进行备份恢复工作. 学到的方法主要如下: 0. 首先打开sqlcmd 启动命令行界面 1. ...