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的更多相关文章

  1. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  2. Codeforces Round #530 (Div. 2) A,B,C,D

    A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...

  3. 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号结 ...

  4. Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)

    https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...

  5. Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)

    题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...

  6. Codeforces Round #530 (Div. 2)

    RANK :2252 题数 :3 补题: D - Sum in the tree 思路:贪心 把权值放在祖先节点上 ,预处理 每个节点保存 他与他儿子中 权值最小值即可. 最后会有一些叶子节点依旧为 ...

  7. Codeforces Round #530 Div. 1 自闭记

    A:显然应该让未确定的大小尽量大.不知道写了啥就wa了一发. #include<iostream> #include<cstdio> #include<cmath> ...

  8. Codeforces Round #530 (Div. 2) F - Cookies

    F - Cookies 思路:我们先考虑如何算出在每个节点结束最多能吃多少饼干, 这个dfs的时候用线段树维护一下就好了, 然后有个这个信息之后树上小dp一下就好啦. #include<bits ...

  9. Codeforces Round #530 (Div. 1)

    A - Sum in the tree 就是贪心选尽量让上面的点权尽量大,那么对于偶数层的点,其到根节点的和即为所有儿子中的最大值. #include<bits/stdc++.h> usi ...

随机推荐

  1. Android为TV端助力(转载)

    作者地址http://www.jianshu.com/u/63915ef020e2 针对Android Tv的自定义RecyclerView 作者 wenju_song 关注 2016.12.09 1 ...

  2. Android下实现一个简单的计算器源码

    下面的内容是关于Android下实现一个简单的计算器的内容. import android.app.Activity; import android.os.Bundle;import android. ...

  3. ARM汇编指令集_学习笔记(1)

    一.什么是ARM汇编? 运行在ARM处理器上的汇编语言就叫ARM汇编. C程序运行在X86平台,底层就是X86汇编:运行在ARM平台,底层就是ARM汇编.ARM汇编与X86汇编有显著区别. X86属于 ...

  4. 安卓开发:UI组件-布局管理器和文本显示

    接下来的随笔,记录了在学习b站up主:天哥在奔跑,录制的教学视频的同时,进行一个app开发. up主:天哥在奔跑 视频地址:https://www.bilibili.com/video/av38409 ...

  5. spring学习总结——高级装配学习二(处理自动装配的歧义性)

    我们已经看到如何使用自动装配让Spring完全负责将bean引用注入到构造参数和属性中.自动装配能够提供很大的帮助.不过,spring容器中仅有一个bean匹配所需的结果时,自动装配才是有效的.如果不 ...

  6. git 更新分支的信息

    假如服务器的某个分支删除了,但是本地通过git branch -av还是可以看得到,感觉很烦,通过以下命令就可以更新分支的情况. git fetch origin --prune

  7. nginx多server配置记录

    直接在配置文件(/etc/nginx/nginx.conf)中添加如下代码: server { listen 8080; server_name 192.168.100.174:8080; root ...

  8. Go 语言笔记

    Go 语言笔记 基本概念 综述 Go 语言将静态语言的安全性和高效性与动态语言的易开发性进行有机结合,达到完美平衡. 设计者通过 goroutine 这种轻量级线程的概念来实现这个目标,然后通过 ch ...

  9. [转] Linux Asynchronous I/O Explained

    Linux Asynchronous I/O Explained (Last updated: 13 Apr 2012) *************************************** ...

  10. JavaScript -- JSON.parse 函数 和 JSON.stringify 函数

    JavaScript -- JSON.parse 函数 和 JSON.stringify 函数 1. JSON.parse 函数: 使用 JSON.parse 可将 JSON 字符串转换成对象. &l ...