这题贪心停水的,找\(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. application.properties文件中暗藏玄机

    上次分享了如何一步一步搭建一个springboot的项目,详细参见<5分钟快速搭建一个springboot的项目>,最终的结果是在"8080"端口搭建起了服务,并成功访 ...

  2. Spring Ioc源码分析系列--容器实例化Bean的四种方法

    Spring Ioc源码分析系列--实例化Bean的几种方法 前言 前面的文章Spring Ioc源码分析系列--Bean实例化过程(二)在讲解到bean真正通过那些方式实例化出来的时候,并没有继续分 ...

  3. Navicat 连接 MySQL

    目录 简述 新建连接 常见错误 简述 Navicat 是一套快速.可靠和全面的数据库管理工具,专门用于简化数据库管理和降低管理成本.Navicat 图形界面直观,提供简便的管理方法,设计和操作 MyS ...

  4. c++ 辗转相除(动图)

    #include<iostream> #include<cstdio> #include<iomanip> #include<cstring> usin ...

  5. @vue/cli3+配置build命令构建测试包&正式包

    上一篇博客介绍了vue-cli2.x配置build命令构建测试包和正式包,但现在前端开发vue项目大多数使用新版@vue/cli脚手架搭建vue项目(vue create project-name) ...

  6. 深度学习与CV教程(13) | 目标检测 (SSD,YOLO系列)

    作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/37 本文地址:http://www.showmeai.tech/article-det ...

  7. WTM框架使用技巧之:CI/CD(持续集成/持续部署)

    1. 什么是WTM框架? 一个快速.灵活.社区活跃.最最最最高效的.netcore 后台管理系统.详见 https://wtmdoc.walkingtec.cn/ 欢迎大家付费支持WTMPlus,反哺 ...

  8. ABAP CDS - DEFINE VIEW, view_annot

    Syntax ... @annotation ... Effect Specifies Annotation annotation in the definition of a CDS view of ...

  9. 基于slate构建文档编辑器

    基于slate构建文档编辑器 slate.js是一个完全可定制的框架,用于构建富文本编辑器,在这里我们使用slate.js构建专注于文档编辑的富文本编辑器. 描述 Github | Editor DE ...

  10. raid划分及创建

    RAID 的划分 RAID 0 - RAID 0是最早出现的,是数据分条技术.组建磁盘阵列中最简单的一种形式,可以提高整个磁盘的性能和吞吐量,利用率100%,缺点:一但磁盘损坏,raid0将失效,数据 ...