A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vect…
(多项式的)因式分解定理(factor theorem)是多项式剩余定理的特殊情况,也就是余项为 0 的情形. 0. 多项式长除法(Polynomial long division) Polynomial long division - Wikipedia 1. 因式分解定理 Factor theorem 该定理表达的是,多项式 f(x) 存在因子 x−k 当且仅当 f(k)=0(余数为 0,也即 k 是其根). 对于多项式 f(x)=x3+7x2+8x+2, x−1 是否为其因子?f(1)≠0…
Water Tree CodeForces 343D 树链剖分+线段树 题意 给定一棵n个n-1条边的树,起初所有节点权值为0. 然后m个操作, 1 x:把x为根的子树的点的权值修改为1: 2 x:把x结点到根路径上的点修改为0: 3 x:查询结点x的值. 解题思路 这个因为是在树上进行的操作,所以首先需要把树进行一些转化,比如使用dfs序列转变成一维的,这样方便使用线段树或则树状数组来进行操作.但是因为这里的操作2需要把x节点和它的父节点赋值为0,所以需要树链剖分来进行处理. 关于树链剖分的讲…
题目链接:https://vjudge.net/contest/175446#problem/J 题解:显然要用最多n个点构成的图要使的得到的最短路条数有1e9次个,显然要有几个数相乘容易想到2的几进制显然所有数都可以又2的几次方凑的于是利用一下别人的图 这就是构造方法我的稍稍有些不同我是先构造直线再构造交叉的我感觉这样简单一点 #include <iostream> #include <cstring> #include <cstdio> using namespac…
//构造中调用构造 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Point{ public: Point(int _x,int _y,int _z){ cout << "自定义的有参构造函数被调用了1" << endl; x = _x; y = _y; z = _z; } Point(int a,int b){ cout <<…
合理的函数可提升时间和空间的利用率 //Test1.h #include<iostream> using namespace std; struct ST { private: int a; short b; public: ST(int a=0, short b=0):a(a),b(b) { this->a = a; this->b = b; cout<<"Object was Built. "<<this<<endl; }…
大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include &l…
大意: 求构造一棵树, 每个节点回答它的祖先个数, 求最少打错次数. 挺简单的一个构造, 祖先个数等价于节点深度, 所以只需要确定一个最大深度然后贪心即可. 需要特判一下根的深度, 再特判一下只有一个结点的情况 #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #inclu…
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through…
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那么答案很简单,就是对(a[i]-1)求和再加1(每一层的结点都集中在上一层的一个结点上)   同理,我们考虑最少能有多少叶子结点,就是把上一个的答案再减去min(a[i]-1, a[i-1]-1)的求和,就是每一层的结点都尽可能的分散在上一层的结点 根据这个,那么如果要求有k个叶子节点,k在最大值与…