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 ...
随机推荐
- Sum of Remainders(数学题)
F - Sum of Remainders Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 经典的css reset代码 (reset.css)
<style> html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, ...
- [Tjoi2018]数学计算
[Tjoi2018]数学计算 BZOJ luogu 线段树分治 是不是想问为什么不暴力做? 模数没说是质数,所以不一定有逆元. 然后就是要每次build一下把线段树权值init成1, 博猪不知道为什么 ...
- 我的Android进阶之旅------>Android关于TextWatcher的初步了解
首先来看一下TextWatcher的源代码 package android.text; /** * When an object of a type is attached to an Editabl ...
- SpringBoot学习笔记(3):静态资源处理
SpringBoot学习笔记(3):静态资源处理 在web开发中,静态资源的访问是必不可少的,如:Html.图片.js.css 等资源的访问. Spring Boot 对静态资源访问提供了很好的支持, ...
- php输入输出
php是服务器脚本语言,js是客户端脚本语言 php用表单接收数据,echo 输出数据,$定义变量. <?php echo $_POST["sub"]; // POST后是表 ...
- 牛客小白月赛1 A 简单题 【数学】
题目链接 https://www.nowcoder.com/acm/contest/85/A 思路 这个 就是 E 但是 运算的时候 要保证 其精度 AC代码 #include <cstdio& ...
- mysql日志总结
1.mysql慢查询设置 log-slow-queries=/alidata/mysql-log/mysql-slow.loglong_query_time = 1log-queries-not-us ...
- Python- 列表内置方法
列表,元组 查 索引(下标) ,都是从0开始 切片 .count 查某个元素的出现次数 .index 根据内容找其对应的位置 "haidilao ge" in a 增加 a.app ...
- BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊:分块
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆 ...