Codeforces Round #530 (Div. 2) C D
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"<<endl;
}else{
string ans = "";
int sum = k-sumx;
;j<len-;j++){
])){
ans+=s[j];
}else{
] == '?'){
if(sum){
sum--;
ans+=s[j];
}
}] == '*'){
while(sum){
sum--;
ans+=s[j];
}
}
}
}
])){
ans+=s[len-];
}
if(ans.size()==k) cout<<ans<<endl;
else{
cout<<"Impossible"<<endl;
}
}
;
}
D:

把深度为偶数的节点隐藏掉(-1) 给出每个节点的父亲以及这个点到 根部的 value值总和 包括自己在内 求这棵树最小的value总和
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define inf 99999999999999
#define LL long long
#define debug(x) cout<<x<<endl
vector<LL>q[maxn];
LL a[maxn],ans[maxn],va=;
;
void dfs(LL u,LL fa,LL deep){
==){
LL mi = inf;
;j<q[u].size();j++){
mi = min(mi,a[q[u][j]]);
}
if(mi==inf){
ans[u] = ;
a[u] = a[fa];
}else{
a[u] = mi;
ans[u] = a[u] - a[fa];
}
}else{
){
ans[u] = a[u] - a[fa];
}
}
;j<q[u].size();j++){
int v = q[u][j];
dfs(v,u,deep+);
}
}
int main(){
LL n;
scanf("%lld",&n);
;j<=n;j++){
LL x;
scanf("%d",&x);
q[x].push_back(j);
}
;j<=n;j++){
scanf("%lld",&a[j]);
}
ans[]=a[];
dfs(,,);
;j<=n;j++){
va+=ans[j];
//cout<<ans[j]<<endl;
){
cout<<"-1"<<endl;
;
}
}
cout<<va<<endl;
}
Codeforces Round #530 (Div. 2) C D的更多相关文章
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- Codeforces Round #530 (Div. 2) A,B,C,D
A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...
- Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)
D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...
- Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)
https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...
- Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)
题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...
- Codeforces Round #530 (Div. 2)
RANK :2252 题数 :3 补题: D - Sum in the tree 思路:贪心 把权值放在祖先节点上 ,预处理 每个节点保存 他与他儿子中 权值最小值即可. 最后会有一些叶子节点依旧为 ...
- Codeforces Round #530 Div. 1 自闭记
A:显然应该让未确定的大小尽量大.不知道写了啥就wa了一发. #include<iostream> #include<cstdio> #include<cmath> ...
- Codeforces Round #530 (Div. 2) F - Cookies
F - Cookies 思路:我们先考虑如何算出在每个节点结束最多能吃多少饼干, 这个dfs的时候用线段树维护一下就好了, 然后有个这个信息之后树上小dp一下就好啦. #include<bits ...
- Codeforces Round #530 (Div. 1)
A - Sum in the tree 就是贪心选尽量让上面的点权尽量大,那么对于偶数层的点,其到根节点的和即为所有儿子中的最大值. #include<bits/stdc++.h> usi ...
随机推荐
- 测者的测试技术手册:AI的自动化单元测试
测者的测试技术手册:AI的自动化单元测试 谈新技术:AI的自动化单元测试
- idea连接服务器上传jar并运行
.打开idea tools-deployment-configuration.. .打开如图 点击 + 号 .如 ...
- UE4分支的Git Flow
UE4作为开源商业引擎,其代码托管在私有库:https://github.com/EpicGames/UnrealEngine 为了能看到并下载UE4的代码,开发者需要有GitHub账号和Unreal ...
- Spark之Pipeline处理模式
一.简介 Pipeline管道计算模式:只是一种计算思想,在数据处理的整个流程中,就想水从管道流过一下,是顺序执行的. 二.特点 1.数据一直在管道中,只有在对RDD进行持久化[cache,persi ...
- python2和python3的一些差别
未来python3是主流,但还是因为一部分原因,很多项目还在用python2.python3是不兼容python2的,做了一些优化和改进 1.字符编码 python2:ascii编码 python3: ...
- C#基础第六天
数组 方法 实现代码的重用 参数 返回值 注释 return 语法:[public] static 返回值类型 方法名([参数列表]){ 方法体;}public:访问修饰符,公开的,公共的s ...
- mysql安装和配置(windowns||centos)
windows10版本安装 1.获取mysql压缩包 https://dev.mysql.com/downloads/mysql/ 2.解压并配置文件my.ini .解压的文件路径 D:\Progra ...
- 删除网络中的本地连接*x等
1.运行-regedit 打开注册表 定位到 HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Control Network {4D36E972-E325-11 ...
- 推荐一套Angular2的UI模板
Core UI Core UI是一款基于Bootstrap4的UI模板,有html.angular2,react和vue版.我是在使用angular2版本中发现其项目结构不符合angular风格指南推 ...
- 验证二叉搜索树的golang实现
给定一个二叉树,判断其是否是一个有效的二叉搜索树. 一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右子树自身必须也是二叉搜索树. ...