前言:结论题似乎是我的硬伤…… 题意是给你一个无向图,已知连接到每一个点的边的权值和(为整数,且属于区间[-n,n]),需要求出每条边权值的一个合法解(都要是在区间[-2*n^2,2*n^2]内的整数). 第一个想法当然是O(n^2*m)的高斯消元.在此基础上,我想过通过选取某些节点,在边权总和中减去与之相邻的边,来逐个解出边的权值.这个本质上是优化解方程的办法难以适应全部情况,且难以通过编程实现.于是只能舍弃这个想法. 后来通过漫无边际的瞎想,观察标题,容易发现对于一棵树求解这个问题是极为容易…
题意 一个 \(n\) 个点 \(m\) 条边的无向连通图中每个点都有一个权值,现在要求给每条边定一个权值,满足每个点的权值等于所有相连的边权之和,权值可负. 题解 如果图是一棵树,那么方案就是唯一的,直接判一下就可以了,因为可以从叶子开始逐个确定回去. 否则先搞一棵 \(Dfs\) 树,先不管其他边,跑一遍,这时根节点可能还不满足条件(权值不为 \(0\) ). 这时考虑其他的边,一条非树边(返祖边)由于会形成一个环: 如果是偶环,无论这条边权值如何变,都不会对根节点产生贡献: 如果是奇环,当…
Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出perfect solution 首先判断什么时候是perfect:当不存在相邻两层的节点数均大于\(0\)时,输出perfect. 接下来就是构造的问题.若上一层只有一个节点,那么这一层的所有节点只能连到那个唯一的节点,否则分为两棵树不同的构造: 所有点都连到上一层的第一个节点 第一个点连到上一层…
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <string> #include <queue> #include <map> #include <se…
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> #include <iostream> #include <cstring> #include <string> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f;…
题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",…
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; int main(void) //Codeforces Round #304 (Div. 2) A. Soldier…
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during the collision. 是指i,j两辆车,而不是全部 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <iostream>…
题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <vector> using namespace std; ; const int INF = 0x3f3f3f3f; vector<c…
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(void) //Codeforces Round #…