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 ...
随机推荐
- php输出缓冲区
ob_start(); echo 'aaa'; $string = ob_get_contents(); file_put_contents('a.html', $string); ob_flush( ...
- 【python】-- 文件操作
一.概述 我们工作中需要经常操作文件,下面就讲讲如何用Python操作文件 1.文件操作的流程: 打开文件,得到文件句柄赋值给一个变量 通过文件句柄,对文件进行操作 关闭文件 #获取文件句柄 f = ...
- 几则js表达式
过滤大段文本里的标签.标签格式 <...>,如下匹配标签然后替换成空 校验邮箱是否符合: 去掉行首行尾空格: 检测字符串是否包含中文:(utf8编码)
- js实现粘贴板复制
<a href = '#' onclick ='javascript:window.clipboardData.setData('text','${form.param}');alert('クリ ...
- Tensorflow官方文档中文版——第一章
第一示例: import tensorflow as tf import numpy as np x_data=np.float32(np.random.rand(,))#随机输入 y_data=np ...
- VMware下所有的系统网卡启动不起来
昨天新装了一台Linux,装好之后网络起不来,搞了半天也没弄好,总是报错: Failed to start LSB: Bring up/down networking.... 我以为是我的设置出了问题 ...
- model特性
1.scope http://blog.csdn.net/lissdy/article/details/51107883 2.ActiveConcern http://www.tuicool.com/ ...
- 关于scrollLeft的获取在不同浏览器或相同浏览器的不同版本下的获取
chrome61向w3c规则靠拢,document.body.scrollLeft获取的值一直为0,需要使用document.documentElement.scrollLeft(或document. ...
- hd acm1048
Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caes ...
- android6.0 外部存储设备插拔广播以及获取路径(U盘)【转】
本文转载自:https://blog.csdn.net/zhouchengxi/article/details/53982222 这里我将U盘作为例子来说明解析. android4.1版本时U盘插拔时 ...