Codeforces 360E 贪心 最短路
题意及思路:https://blog.csdn.net/huanghongxun/article/details/49846927
在假设所有边都是最大值的情况下,如果第一个人能比第二个人先到,那就缩短这条边。
代码:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 10010;
int head[maxn], Next[maxn * 2], ver[maxn * 2], f[maxn * 2], tot;
LL l[maxn * 2], r[maxn * 2];
LL d[2][maxn];
bool v[2][maxn];
queue<int> q[2];
int s1, s2, t, n, m, k;
void add(int x, int y, LL lb, LL rb) {
ver[++tot] = y, l[tot] = lb, r[tot] = rb, Next[tot] = head[x], head[x] = tot, f[tot] = x;
}
void spfa(int pos, int s) {
// memset(d[pos], 0x3f, sizeof(d[pos]));
// memset(v[pos], 0, sizeof(v[pos]));
// q[pos].push(s), v[pos][s] = 1, d[pos][s] = 0;
while(q[pos].size()) {
int x = q[pos].front();
q[pos].pop();
v[pos][x] = 0;
for (int i = head[x]; i; i = Next[i]) {
int y = ver[i], z = r[i];
if(d[pos][y] > d[pos][x] + z) {
d[pos][y] = d[pos][x] + z;
if(!v[pos][y])
q[pos].push(y), v[pos][y] = 1;
}
}
}
}
bool solve(int flag) {
memset(d, 0x3f, sizeof(d));
memset(v, 0, sizeof(v));
d[0][s1] = d[1][s2] = 0;
v[0][s1] = v[1][s2] = 1;
q[0].push(s1), q[1].push(s2);
bool flag1 = 1;
while(flag1) {
spfa(0, s1), spfa(1, s2);
flag1 = 0;
for (int i = m + 1; i <= k + m; i++) {
if(d[0][f[i]] + flag <= d[1][f[i]] && l[i] != r[i]) {
flag1 = 1;
q[0].push(f[i]), q[1].push(f[i]);
v[0][f[i]] = 1, v[1][f[i]] = 1;
r[i] = l[i];
}
}
}
return d[0][t] + flag <= d[1][t];
}
int main() {
int x, y;
LL z, t1;
scanf("%d%d%d", &n, &m, &k);
scanf("%d%d%d", &s1, &s2, &t);
for (int i = 1; i <= m; i++) {
scanf("%d%d%lld", &x, &y, &z);
add(x, y, z, z);
}
for (int i = 1; i <= k; i++) {
scanf("%d%d%lld%lld", &x, &y, &z, &t1);
add(x, y, z, t1);
}
if(solve(1)) {
printf("WIN\n");
for (int i = m + 1; i <= m + k; i++)
printf("%d ", r[i]);
printf("\n");
return 0;
}
if(solve(0)) {
printf("DRAW\n");
for (int i = m + 1; i <= m + k; i++)
printf("%d ", r[i]);
printf("\n");
return 0;
}
printf("LOSE\n");
}
Codeforces 360E 贪心 最短路的更多相关文章
- codeforces DIV2 D 最短路
http://codeforces.com/contest/716/problem/D 题目大意:给你一些边,有权值,权值为0的表示目前该边不存在,但是可以把0修改成另外一个权值.现在,我们重新建路, ...
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- [CSP-S模拟测试]:午餐(贪心+最短路)
题目传送门(内部题115) 输入格式 第一行两个正整数$n,m$. 接下来$m$行,每行$4$个正整数$u_j,v_j,L_j,R_j$. 接下来一行$n$个数,若第$i$个数为$1$,则$i$号同学 ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
随机推荐
- 【LeetCode】队列 queue(共8题)
[346]Moving Average from Data Stream [353]Design Snake Game [363]Max Sum of Rectangle No Larger Than ...
- Sass-加法
程序中的运算是常见的一件事情,但在 CSS 中能做运算的,到目前为止仅有 calc() 函数可行.但在 Sass 中,运算只是其基本特性之一.在 Sass 中可以做各种数学计算 (一).加法 加法运算 ...
- gulp为css,js添加版本号
由于cdn缓存,更改样式后会有一段时间不生效,解决方法就是给css,js加上版本号效果如下: 1.安装gulp插件 npm install --save-dev gulp-rev (version:9 ...
- call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数
<?php function foobar($arg, $arg2) { echo __FUNCTION__, " got $arg and $arg2\n"; } clas ...
- Ubuntu12.04安装配置vncserver
安装 sudo apt-get install vnc4server 修改配置文件 sudo vim ~/.vnc/xstartup #!/bin/sh # Uncomment the followi ...
- SQLServer 链接服务器及同义词
链接服务器 1. openrowse exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc ...
- springboot2集成pagehelper
springboot2集成pagehelper超级简单,本示例直接抄袭官方示例,仅将数据库由H2改成MySQL而已. 1. pom.xml <?xml version="1.0&quo ...
- SCJP读书之知识点:
1:实例变量和局部变量 实例变量:是在类中进行声明的,可以有public,private等修饰符进行修饰. 局部变量:在方法中进行声明,生命周期就是方法开始,到方法结束.但是可以进行对象的引用来调用. ...
- 08-图8 How Long Does It Take(25 分)邻接表和队列
Given the relations of all the activities of a project, you are supposed to find the earliest comple ...
- UOJ 418 【集训队作业2018】三角形——思路+线段树合并
题目:http://uoj.ac/problem/418 看了题解才会…… 很好的想法是把整个过程看成若干 “取一点 i ,值+=w[ i ],值-=\(\sum w[j]\)”(其中 j 是 i 的 ...