D. Sum in the tree 题意 给出一颗树,奇数层数的点有值,值代表从1到该点的简单路的权值的和,偶数层数的点权值被擦去了 问所有节点的和的最小可能是多少 思路 对于每一个-1(也就是值未知的点)其所填的值的最小值小于等于他的自己点中已知的点的权值 换个说法就是 一个-1点有多个子树 那么这个点的值最小也是这几个子树里面的最大的值,才能使得其合法 从根节点递归求值即可 其中注意 这里计算权值和的时候,因为已知每个点到根节点的路径的点的权值和所以计算一个节点以及其子树到根节点的权值和的…
D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结点到根节点的权值和.但是有些si=-1,这就相当于丢失了当前结点的数据. 假设原本每个点的权值为ai,那么现在求sum{ai}的最小为多少,ai为非负数. 题解: 这题可以单独看每一条链上的s值,假设当前结点为u,儿子结点v,那么就有几种情况: 1.su==-1&&sv==-1,这种不用管,继…
A. Sum in the tree Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each vertex vv initially had an integer number av≥0av≥0 written on it. For every vertex vv Mitya has computed svsv: the sum of all values…
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positiv…
A - Sum in the tree 就是贪心选尽量让上面的点权尽量大,那么对于偶数层的点,其到根节点的和即为所有儿子中的最大值. #include<bits/stdc++.h> using namespace std; char gc() { // static char buf[100000],*p1,*p2; // return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin))?EOF:*p1++; return get…
D. Sum in the tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each vertex vv initially had…
A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define mid int m = (l + r) >> 1 ; ],y[]; int…
RANK :2252 题数 :3 补题: D - Sum in the tree 思路:贪心 把权值放在祖先节点上 ,预处理 每个节点保存 他与他儿子中 权值最小值即可. 最后会有一些叶子节点依旧为 INF 权值按0算即可,然后其他的权值计算为 它 - 它父亲的. 注意判断时候会出现父亲比儿子大的这种非法情况. #include<bits/stdc++.h> using namespace std; #define inf 0x7f7f7f7f #define ll long long #de…
A. Snowball 签. #include <bits/stdc++.h> using namespace std; ], d[]; int main() { while (scanf("%d%d", &w, &h) != EOF) { ; i < ; ++i) scanf("%d%d", u + i, d + i); ; --i) { w += i; ; j < ; ++j) if (i == d[j]) { w -=…
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干需要花费bi时间,有两个玩家,玩家一可以移动到当前点的子节点也可以申请游戏结束返回根节点并吃沿途的饼干,玩家二可以删除当前点到儿子节点的一条边,走路和吃饼干都消耗时间,会给出一个总时间,在总时间内尽可能的多吃饼干,问最多能吃多少个? 思路: 由于是玩家一先手,那么最开始的最大边则不会被删除,但之后路…
https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\),有n-1条边,每条边有边权w为经过一条边所需时间,你从树根开始先手向下走,然后对手割掉你所在节点到子节点的任意一条边,你可以在任何时间选择返回,在返回的过程中你可以选择性吃掉经过节点的饼干,问在双方最优的情况下,你最多能在T时间之内吃掉多少饼干并返回根节点(在足够时间返回根节点的情况下吃掉尽可能多…
C: *可以保留删除或者增加 ? 保留或者删除 #include<bits/stdc++.h> using namespace std; int main(){ string s; int k,len; cin>>s>>k; ; len = s.size(); ;j<len;j++){ if(isalpha(s[j])) sumx++; else sumx--; } if(sumx>k){ cout<<"Impossible"…
F - Cookies 思路:我们先考虑如何算出在每个节点结束最多能吃多少饼干, 这个dfs的时候用线段树维护一下就好了, 然后有个这个信息之后树上小dp一下就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #…
这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <iostream> #include <fstream> #include <vector> #include <set> #include <map> #include <bitset> #include <algorithm> #in…
C. Sum Balance Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are…
题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的时间.然后有先手和后手俩个人. ◉先手可以这么操作:在规定总时间T到达某个节点然后一定要返回根节点1,期间可以选择吃掉某些节点上的某些饼干(前提是保证剩下的时间能够回到根节点): ◉后手可以这么操作:在先手到达的位置和这个位置的孩子之间的连边选择一条让先手吃得更多的边摧毁掉,也可以跳过这个过程: 问…
A:显然应该让未确定的大小尽量大.不知道写了啥就wa了一发. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 200010 #define inf 100000001…
C. Postcard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowe…
B. Squares and Segments time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home…
A. Snowball time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Lu…
总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高度的模拟,如果遇到石头就去判断一下会不会小于0其他没有什么好说的了 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int…
Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find . Input The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Each of the following t li…
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the g…
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来...... 先从小到大排一下序,然后从最上层向下找,只要能承受住重量就行.而且因为已经排序了找的都是尽量小的... #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib>…
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there…
A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year.…
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every verte…
地址:http://codeforces.com/contest/842/problem/C 题目: C. Ilya And The Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya is very fond of graphs, especially trees. During his last trip…
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edg…
题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最大. 解法:考虑树形dp,若当前节点是nownownow,我们可以假设编号最大的一些数分布在当前节点的子节点中,显然,若当前节点为叶子节点,那么这个这个编号就是最大的.然后往上回溯,假设当前节点取得是maxmaxmax,那么就从子节点中取最大的数为当前节点的答案,如果取得是minminmin的话,就…