• luoguP4643 阿狸和桃子的挑战 思维



    看下数据范围:

    (n leq 14),emmmm,状压(dp)的分

    (n leq 10000, m leq 100000),emmmm.....???,这是什么数据范围?

    再观察一下所求

    点十分好控制,边非常不好控制

    能不能把边转化为点呢?

    把边给均分给两边的点?

    诶,好像可以了.....

    然后就没了.....


    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    #define ll long long
    #define ri register int
    #define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
    #define drep(io, ed, st) for(ri io = ed; io >= st; io --)
    	
    #define gc getchar
    inline int read() {
    	int p = 0, w = 1; char c = gc();
    	while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
    	while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
    	return p * w;
    }
    
    int n, m;
    ll val[200050];
    
    int main() {
    	n = read(); m = read();
    	rep(i, 1, n) val[i] = 2 * read();
    	rep(i, 1, m) {
    		int u = read(), v = read(), w = read();
    		val[u] += w; val[v] += w;
    	}
    	sort(val + 1, val + n + 1);
    	ll ans = 0;
    	drep(i, n, 1) 
    	if(!((n - i) & 1)) ans += val[i];
    	else ans -= val[i];
    	printf("%lld
    ", ans / 2);
    	return 0;
    }
    
    
  • 相关阅读:
    63.C++异常
    62.C++文件操作list实现内存检索,实现两千万数据秒查
    61.C++文件操作实现硬盘检索
    ios之数据持久化
    ios NSRange
    安排
    接口隔离原则
    Liskon替换原则
    开放封闭原则
    单一职责原则
  • 原文地址:https://www.cnblogs.com/reverymoon/p/10198399.html
Copyright © 2020-2023  润新知