CF 360 E Levko and Game —— 贪心+最短路
题目:http://codeforces.com/contest/360/problem/E
首先,每条边不是选 \( l[i] \) 就是选 \( r[i] \);
做法就是先把边权都设成 \( r[i] \),然后做 \( dijkstra \),如果有一条可改的边 \( (a,b) \) 而且 \( dis1[a] < dis2[a] \),那么就改边权为 \( l[i] \);
然后重复这个过程直到无边可改;
因为要考虑平局,所以只要 \( dis1[a] <= dis2[a] \) 就改,这样先让第一个人的路是最优的;
其实也不用一条一条改,一次改所有能改的就行,因为据题解的证明,一次改了一条边后,不会使一个 \( dis1[a] <= dis2[a] \) 的边突然变得 \( dis1[a] > dis2[a] \)
题解的证明...看不动了...感性理解...
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int const xn=1e4+,xm=;
int n,m,cnt,hd[xn],ct,to[xn],nxt[xn],w[xn],s1,s2,f;
ll dis[][xn],inf=1e17;
bool vis[xn];
struct E{int u,v,bh,l,r,w;}ed[xm];
struct N{
ll d; int id;
N(ll d=,int i=):d(d),id(i) {}
bool operator < (const N &y) const
{return d>y.d;}
};
priority_queue<N>q;
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
void add(int x,int y,int z){to[++ct]=y; nxt[ct]=hd[x]; hd[x]=ct; w[ct]=z;}
void dij(int t)
{
for(int i=;i<=n;i++)dis[t][i]=inf;
for(int i=;i<=n;i++)vis[i]=;
int st=(t?s2:s1);
dis[t][st]=; q.push(N(,st));
while(q.size())
{
int x=q.top().id; q.pop();
if(vis[x])continue; vis[x]=;
for(int i=hd[x],u;i;i=nxt[i])
if(dis[t][u=to[i]]>dis[t][x]+w[i])
{
dis[t][u]=dis[t][x]+w[i];
q.push(N(dis[t][u],u));
}
}
}
int main()
{
n=rd(); m=rd(); cnt=rd();
s1=rd(); s2=rd(); f=rd();
for(int i=,x,y,z;i<=m;i++)x=rd(),y=rd(),z=rd(),add(x,y,z);
for(int i=;i<=cnt;i++)
ed[i].u=rd(),ed[i].v=rd(),ed[i].l=rd(),ed[i].r=rd(),
ed[i].bh=ct+,ed[i].w=,add(ed[i].u,ed[i].v,ed[i].r);
dij(); dij();
while(dis[][f]>=dis[][f])
{
int i;
for(i=;i<=cnt;i++)
if(dis[][ed[i].u]<=dis[][ed[i].u]&&ed[i].w)break;
if(i>cnt)
{
if(dis[][f]>dis[][f])puts("LOSE");
else
{
puts("DRAW");
for(int j=;j<=cnt;j++)printf("%d ",ed[j].w?ed[j].r:ed[j].l);
puts("");
}
return ;
}
ed[i].w=; w[ed[i].bh]=ed[i].l; dij(); dij();
}
puts("WIN");
for(int j=;j<=cnt;j++)printf("%d ",ed[j].w?ed[j].r:ed[j].l);
puts("");
return ;
}
CF 360 E Levko and Game —— 贪心+最短路的更多相关文章
- [codeforces 360]A. Levko and Array Recovery
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...
- CF 360E Levko and Game——贪心
题目:http://codeforces.com/contest/360/problem/E 官方题解与证明:http://codeforces.com/blog/entry/9529 一条可以调整的 ...
- [ 10.05 ]CF每日一题系列—— 962B贪心和思维?
Description: 非 * 号的地方可以放A或B,不能AA或BB,一共有a个A,b个B,问你最多放几个 Solution: 1.模拟一下,找连续空位长度,如果长度为奇数,则我可以有一个位置放任意 ...
- [ 10.03 ]CF每日一题系列—— 534B贪心
Descripe: 贪心,贪在哪里呢…… 给你初始速度,结尾速度,行驶秒数,每秒速度可变化的范围,问你行驶秒数内最远可以行驶多少距离 Solution: 贪心,我是否加速,就是看剩下的时间能不能减到原 ...
- CF GukiZ hates Boxes 【二分+贪心】
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...
- CF 990B. Micro-World【数组操作/贪心/STL/二分搜索】
[链接]:CF [题意]:对任意一个数a[i] ,可以对任意 满足 i != j 且 a[i] > a[j] && a[i] <= a[j] +k 的 a[j] 可以被删掉 ...
- CF R 639 div2 F Review 贪心 二分
LINK:Résumé Review 这道题让我眼前一亮没想到二分这么绝. 由于每个\(b_i\)都是局部的 全局只有一个限制\(\sum_{i=1}^nb_i=k\) 所以dp没有什么用 我们只需要 ...
- CF 321B Kefa and Company(贪心)
题目链接: 传送门 Kefa and Company time limit per test:2 second memory limit per test:256 megabytes Desc ...
- CF#301 B:School Marks(贪心)
B:School Marks 有n个测试,已经完成了k个,每个测试得分为a[i],接下来的分数不知道,让我们求出任何一个满足题意的即可,满足题意就是n个测试的得分总和<=x, 中位数>=y ...
随机推荐
- java线程 同步临界区:thinking in java4 21.3.5
java线程 同步临界区:thinking in java4 21.3.5 thinking in java 4免费下载:http://download.csdn.net/detail/liangru ...
- [Java面试一]Spring总结以及在面试中的一些问题.(转发:http://www.cnblogs.com/wang-meng/p/5701982.html)
1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ...
- 基于Spring框架的Shiro配置(转发:http://kdboy.iteye.com/blog/1103794)
一.在web.xml中添加shiro过滤器 <!-- Shiro filter--> <filter> <filter-name>shiroFilter</f ...
- QT修改应用程序图标
要准备一个ico的图标,必须是ico格式,切记!! 可以用png或者其他的在线转换:http://www.easyicon.net/covert/ 用记事本 新建文件icon.rc,内容为: IDI_ ...
- 关于python2中的unicode和str以及python3中的str和bytes
python3有两种表示字符序列的类型:bytes和str.前者的实例包含原始的8位值:后者的实例包含Unicode字符. python2中也有两种表示字符序列的类型,分别叫做str和unicode. ...
- this.Hide()与this.Visible、Application.Exit与this.Close()区别
首先明确this.Hide()和this.Visible作用完全一样,都是隐藏当前窗体,使其不可见:Application.Exit与this.Close()虽然都有关闭当前应用的作用,但作用不同. ...
- Python 3 并发编程多进程之队列(推荐使用)
Python 3 并发编程多进程之队列(推荐使用) 进程彼此之间互相隔离,要实现进程间通信(IPC),multiprocessing模块支持两种形式:队列和管道,这两种方式都是使用消息传递的. 可以往 ...
- mutation与action
mutation 作用: 更改state的状态 说明: 每个mutation对象都有字符串类型(type)与回调函数,在回调函数内进行状态修改,回调函数的第一个参数为state eg: mutatio ...
- EntityFramework 学习 一 CRUD using Stored Procedure: 使用存储过程进行CRUD操作
我们先创建如下3个存储过程 1.Sp_InsertStudentInfo: CREATE PROCEDURE [dbo].[sp_InsertStudentInfo] -- Add the param ...
- developerWorks 图书频道: 深入分析 Java Web 技术内幕,第 10 章
developerWorks 图书频道: 深入分析 Java Web 技术内幕,第 10 章 深入理解 Session 与 Cookie Session 与 Cookie 不管是对 Java Web ...