[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$的关系,那么这两个玩具一定在不同的栈中间. 现在 ...
随机推荐
- 谈谈ThreadLocal的设计及不足
用Java语言开发的同学对 ThreadLocal 应该都不会陌生,这个类的使用场景很多,特别是在一些框架中经常用到,比如数据库事务操作,还有MVC框架中数据跨层传递.这里我们简要探讨下 Thread ...
- Mybatis教程-实战看这一篇就够了
转自:https://blog.csdn.net/hellozpc/article/details/80878563 1.从JDBC谈起 1.1.使用IDEA创建maven工程 1.2.引入mysql ...
- CentOS 7.2:Failed to start IPv4 firewall with iptables
问题 系统是centos7.2,且已经安装了iptables服务,但是在执行启动命令后,却报了iptables服务无法正常启动的错误. 启动命令如下: systemctl start iptables ...
- [UWP 自定义控件]了解模板化控件(5.1):TemplatePart vs. VisualState
1. TemplatePart vs. VisualState 在前面两篇文章中分别使用了TemplatePart及VisualState的方式实现了相同的功能,其中明显VisualState的方式更 ...
- slurm用户快速入门手册
1. 概述2. 架构3. 命令3.1 sacct3.2 sattach3.4 sbatch3.5 sbcast3.6 scancel3.7 scontrol3.8 sinfo3.9 smap3.10 ...
- Object-Oriented(二)原型对象
自用备忘笔记 1. 理解原型对象 只要创建函数,函数上就会创建一个 prototype 属性指向函数的原型对象. function Person() {} Person.prototype //指向该 ...
- 支持自定义协议的虚拟仪器【winform版】
首先,这个程序的由来,额,工作以来,做的最久的就是上位机,对市面上的大部分组态软件都感到不满,不好用,LabView虽然用起来不错,但是入门还是不够简单,刚好现在工作比较闲(已经不再做上位机了),所以 ...
- ubuntu系统升级和其他相关操作记录
之前在openstack中安装了ubuntu 12.04虚拟机,版本较低,需要升级为高版本.下面分享下升级过程: ubuntu系统升级操作:$ cat /etc/issueUbuntu 12.04.5 ...
- 线上mongodb 数据库用户到期时间修改的操作记录
登陆版权数据库,显示"此用户已到期",数据库使用的是mongodb,顾 需要将此用户的到期时间延长. 解决过程: 1)到网站对应tomcat配置里找出等里mongodb的信息(mo ...
- css3 动画效果实现
前沿 在工作中,经常有一些需要切换的交互样式.如果直接在两种状态之间切换,就显得有点生硬.加上一些动画效果就会好很多. 示例1:点击的三角切换 实现过程 第一步实现这个三角形 用的svg 的多边形画法 ...