CF360E Levko and Game(贪心)
这题贪心停水的,找\(dis1<=dis2\)的点往歇斯底里地砍,砍到没法砍就是。
写博客是为了记录下遇到的神奇bug
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++a)
#define nR(a,b,c) for(register int a = (b); a >= (c); --a)
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ON_DEBUGG
#ifdef ON_DEBUGG
#define D_e_Line printf("\n-----------\n")
#define D_e(x) std::cout << (#x) << " : " <<x << "\n"
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#define Pause() system("pause")
#include <ctime>
#define TIME() fprintf(stderr, "\nTIME : %.3lfms\n", clock() * 1000.0 / CLOCKS_PER_SEC)
#else
#define D_e_Line ;
#define D_e(x) ;
#define FileOpen() ;
#define FilSave ;
#define Pause() ;
#define TIME() ;
#endif
struct ios {
template<typename ATP> ios& operator >> (ATP &x) {
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x *= f;
return *this;
}
}io;
using namespace std;
template<typename ATP> inline ATP Min(ATP a, ATP b) {
return a < b ? a : b;
}
template<typename ATP> inline ATP Max(ATP a, ATP b) {
return a > b ? a : b;
}
#include <queue>
const int N = 100007;
const int M = 1000007;
#define int long long
struct Edge {
int nxt, pre, from, w;
} e[M];
int head[N], cntEdge;
inline void add(int u, int v, int w) {
e[++cntEdge] = (Edge){ head[u], v, u, w}, head[u] = cntEdge;
}
struct nod {
int x, w;
bool operator < (const nod &com) const {
return w > com.w;
}
};
priority_queue<nod> q;
int dis1[N], dis2[N];
int n, m, K, S1, S2, T;
inline void Dijkstra(int st, int *dis) {
// Fill(dis, 0x3f); This sentence lead to a bug
/*
[Warning] argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is
the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
*/
R(i,0,n) dis[i] = 0x7fffffff;
dis[st] = 0;
q.push((nod){ st, 0});
while(!q.empty()){
int u = q.top().x, w = q.top().w;
q.pop();
if(w != dis[u]) continue;
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(dis[v] > dis[u] + e[i].w){
dis[v] = dis[u] + e[i].w;
q.push((nod){ v, dis[v]});
}
}
}
}
int l[N], r[N], pos[N];
#undef int
int main() {
#define int long long
io >> n >> m >> K >> S1 >> S2 >> T;
R(i,1,m){
int u, v, w;
io >> u >> v >> w;
add(u, v, w);
}
R(i,1,K){
int u, v;
io >> u >> v;
io >> l[i] >> r[i];
add(u, v, r[i]);
pos[i] = cntEdge;
}
while(1){
int flag = false;
Dijkstra(S1, dis1);
Dijkstra(S2, dis2);
R(i,1,K){
int v = e[pos[i]].from;
if((dis1[v] <= dis2[v]) && e[pos[i]].w != l[i]){
e[pos[i]].w = l[i];
flag = true;
}
}
if(flag == false) break;
}
if(dis1[T] < dis2[T]) printf("WIN\n");
else if(dis1[T] == dis2[T]) printf("DRAW\n");
else{
printf("LOSE\n");
return 0;
}
R(i,1,K){
printf("%lld ", e[pos[i]].w);
}
return 0;
}
cdecl:
sizeof 一个指针肯定会死啊
这样只会 memset 前 4(64 位机的话,8)个 bit
CF360E Levko and Game(贪心)的更多相关文章
- CF360E Levko and Game【贪心+dijsktra】
先把所有边可动设为r[i]又这些边不是l就是r(如果想一个方向改变能更优的话就尽量多的改变),每次跑dijsktra,对于可动边(x,y),如果dis1[x]<=dis2[x],那么就把这条边改 ...
- CF 360E Levko and Game——贪心
题目:http://codeforces.com/contest/360/problem/E 官方题解与证明:http://codeforces.com/blog/entry/9529 一条可以调整的 ...
- CF 360 E Levko and Game —— 贪心+最短路
题目:http://codeforces.com/contest/360/problem/E 首先,每条边不是选 \( l[i] \) 就是选 \( r[i] \): 做法就是先把边权都设成 \( r ...
- 有意思的DP(CF360B Levko and Array)
刚才面试了一个蛮有意思的DP题目,脑子断片,没写出来,不过早上状态还是蛮好的 一个长度为n的序列最多改变k次,使相邻两数之差绝对值的最大值最小 三维的dp我先尝试写一下 Codeforces 360B ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- 快速选择 第k个数
快速选择 第k个数 题目描述 给定一个序列,求第k小的数 算法思想 利用快速排序思想,算法复杂度能达到O(n)步骤如下: 1.找到排序分界点x,这里选择区间最左值 2.排序,让左边的值都小于x,右边都 ...
- 论文阅读 Real-Time Streaming Graph Embedding Through Local Actions 11
9 Real-Time Streaming Graph Embedding Through Local Actions 11 link:https://scholar.google.com.sg/sc ...
- JS:object
object:对象 1.对象是拥有属性和方法的数据,也是一个变量,但值有多个,以key-value的形式. 2.对象有继承属性: 每当创建一个对象,对象里面就会有一个原型对象prototype,可以从 ...
- go-zero微服务实战系列(五、缓存代码怎么写)
缓存是高并发服务的基础,毫不夸张的说没有缓存高并发服务就无从谈起.本项目缓存使用Redis,Redis是目前主流的缓存数据库,支持丰富的数据类型,其中集合类型的底层主要依赖:整数数组.双向链表.哈希表 ...
- vue开发必须知道的小技巧
近年来,vue越来越火,使用它的人也越来越多.vue基本用法很容易上手,但是还有很多优化的写法你就不一定知道了.本文列举了一些vue常用的开发技巧.require.context() 在实际开发中,绝 ...
- Windows 通过本地计算机IP链接Mysql设置
前言 1.Mysql-1130错误:无法远程连接 错误:ERROR 1130: Host '192.168.1.3' is not allowed to connect to thisMySQL se ...
- 全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
气象数据一直是一个价值较高的数据,它被广泛用于各个领域的研究当中.气象数据包括有气温.气压.相对湿度.降水.蒸发.风向风速.日照等多种指标,但是包含了这些全部指标的气象数据却较难获取 ...
- 实时数据引擎系列(五): 关于 SQL Server 与 SQL Server CDC
摘要:在企业客户里, SQL Server 在传统的制造业依然散发着持久的生命力,SQL Server 的 CDC 复杂度相比 Oracle 较低, 因此标准的官方派做法就是直接使用这个 CDC ...
- echart图表中y轴小数位数过长展示效果不佳
业务中后端返回的精密数据,小数过长,导致所有数据差距不大,在图表中显示重合为一条直线 解决方法设置echart的min属性 min: "dataMin", 但是设置了以后又出现了问 ...
- java中AOP的环绕通知
pom.xml <dependencies> <dependency> <groupId>org.springframework</groupId> & ...