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 ...
随机推荐
- ADB和Fastboot最新版的谷歌官方下载链接
ADB和Fastboot for Windows https://dl.google.com/android/repository/platform-tools-latest-windows.zip ...
- Git:修改Git Bash默认打开位置(win10)
1.起因 大家写的代码不可能直接保存在根目录下,但是Git Bash每次一打开就是根目录,每次都要切换路径很麻烦. 2.修改Git Bash默认打开位置 1)Git Bash右键 -> 属性 2 ...
- npm缺少css-loader,/style-compiler,stylus-loader问题,npm没有权限无法全局更新问题【已解决】
ERROR in ./node_modules/css-loader!./node_modules/vue-loader/lib/style-compiler?{"vue":tru ...
- 定时删除所有文件夹下的_desktop.ini文件
写个批处理,删除对应的文件,命名为DELDesktopIni.bat,存于D盘根目录 @echo off :delini for %%a in ( C: D: E: ) DO ( del /f/s/a ...
- 操作DataTable数据,修改某列的值
DataTable table : DataRow row=table.Rows[i];//DataTable的第i行 row.BeginEdit();//开始编辑行 row["column ...
- MySQL:1366 - Incorrect string value错误解决办法
今天使用navicat向MySQL中插入中文时,报错: - Incorrect string value:... 在我自己数据库设计之初,没有设计好字符编码格式的问题. 使用如下语句解决: alter ...
- 电脑出现问题如何修复Windows 10
也许Windows 10无法启动.或者它可能会靴子,但会崩溃很多.在任何一种情况下,您都需要在使用PC之前解决问题.以下是修复Windows 10的几种方法. 方法1:使用Windows启动修复 如果 ...
- SQLServer之DEFAULT约束
DEFAULT约束添加规则 1.若在表中定义了默认值约束,用户在插入新的数据行时,如果该行没有指定数据,那么系统将默认值赋给该列,如果我们不设置默认值,系统默认为NULL. 2.如果“默认值”字段中的 ...
- Python中的一些小技巧
1.Boolean值可以当做一个数值 a = [5,6,7,8,9] print(a[True]) #prints 6 print(a[False]) #prints 5 2.两种方法实现 a = 1 ...
- realm swift调研--草稿
realm swift调研: After you have added the object to the Realm you can continue using it, and all chang ...