这题贪心停水的,找\(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(贪心)的更多相关文章

  1. CF360E Levko and Game【贪心+dijsktra】

    先把所有边可动设为r[i]又这些边不是l就是r(如果想一个方向改变能更优的话就尽量多的改变),每次跑dijsktra,对于可动边(x,y),如果dis1[x]<=dis2[x],那么就把这条边改 ...

  2. CF 360E Levko and Game——贪心

    题目:http://codeforces.com/contest/360/problem/E 官方题解与证明:http://codeforces.com/blog/entry/9529 一条可以调整的 ...

  3. CF 360 E Levko and Game —— 贪心+最短路

    题目:http://codeforces.com/contest/360/problem/E 首先,每条边不是选 \( l[i] \) 就是选 \( r[i] \): 做法就是先把边权都设成 \( r ...

  4. 有意思的DP(CF360B Levko and Array)

    刚才面试了一个蛮有意思的DP题目,脑子断片,没写出来,不过早上状态还是蛮好的 一个长度为n的序列最多改变k次,使相邻两数之差绝对值的最大值最小 三维的dp我先尝试写一下 Codeforces 360B ...

  5. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  6. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. MUI+html5+script 不同页面间转跳(九宫格)

    在点击图片/标题需要跳转到详情页面的使用场景中,首先定义图片元素的id为"tyzc",是同一类下的第一个图片 <img src="img/img3.png" ...

  2. flex布局的总结

    1.开启了flex布局的元素叫: flex container 2.里面的直接子元素叫:flex items(默认情况下,所有item都会在一行显示) 3.display属性由flex和inline- ...

  3. IDEA windows版本快捷键

    使用本快捷键前,可以在idea使用下面方法确认版本! Ctrl 快捷键 介绍 Ctrl + F 在当前文件进行文本查找 (必备)Ctrl + R 在当前文件进行文本替换 (必备) Ctrl + Z 撤 ...

  4. Python数据分析--Numpy常用函数介绍(6)--Numpy中矩阵和通用函数

    在NumPy中,矩阵是 ndarray 的子类,与数学概念中的矩阵一样,NumPy中的矩阵也是二维的,可以使用 mat . matrix 以及 bmat 函数来创建矩阵. 一.创建矩阵 mat 函数创 ...

  5. Spring Security整合企业微信的扫码登录,企微的API震惊到我了

    本文代码: https://gitee.com/felord/spring-security-oauth2-tutorial/tree/wwopen/ 现在很多企业都接入了企业微信,作为私域社群工具, ...

  6. 【clickhouse专栏】新建库角色用户初始化

    一.创建新的database clickhouse创建数据库的语法几乎和其他的关系型数据库是一样的,区别就是clickhouse存在集群cluster和库引擎engine的概念,可以根据需要进行指定. ...

  7. 开发工具-SSMS官方下载地址

    更新记录 2022年6月10日 完善标题. SQL Server Management Studio官方下载地址 https://docs.microsoft.com/en-us/sql/ssms/d ...

  8. 开始讨论离散型随机变量吧!《考研概率论学习之我见》 -by zobol

    上一文中,笔者给出了随机变量的基本定义:一个可测映射,从结果空间到实数集,我们的目的是为了引入函数这个数学工具到考研概率论中,但是我们在现实中面对的一些事情结果,映射而成的随机变量和其对应的概率值,并 ...

  9. vue封装手机验证码

    // 获取验证码 let endMsRes = new Date().getTime() + 45000; localStorage.setItem("myEndTime", JS ...

  10. 【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构

    redis 是使用 C 语言编写的,但是 C 语言是没有字典这个数据结构的,因此 C 语言自己使用结构体来自定义一个字典结构 typedef struct redisDb src\server.h 中 ...