一场比较简单的div2 电脑出了点问题 所以在比赛中理论ac了ACD 除了爆int这种事情之外..

A 一个人想从a到b 移动的花费这么定义 如果初始点和到达点类型相同 就不花钱 反之花距离差的绝对值的钱 并且是直接移动

判断ab的类型 一样就输出0 反之1 因为如果不能直接零花费到b的话 就花1花费走到一个和b类型相同的点 然后零花费移动

B 给出一个串的增长规律 问经过n-1次操作后 k位是多少

规律是这样的 一开始只有1 进行一次操作 就把当前串复制一遍粘在后面 然后在这两个相同串之间插入一个当前没有使用过的最小数字

1 -> 121 -> 1213121 -> 121312141213121 这样

这个串是很对称的 如果k处于当前串的中间 我们可以很容易的确定他是多少

如果处于当前中点的右边 即k处在复制粘贴来的串上 就减去一个东西 让他平移到原串上

如果处于当前中点的左边 就不做修改

k最后一定会在当前串的中间的

持续让一个很长的串进行长度减半 直到k处在当前串中点

C 给出一个n 求出abc 使 2/n = 1/a + 1/b + 1/c 且 a != b a !=c b != c

样例很明确...其实就是a = n b = n+1 c = a*b 可以证明满足一切

唯独满足不了n = 1 因为在没有相同数字的前提下 1/1 + 1/2 + 1/3 无法达到2 别的一定小于它

于是特判n = 1

D 给出一棵树 找两个点 获得他们的子树权值和 并且这两个点的子树没有交集 点有点权 以1为根

树形dp

如果从一个点的所有子树中 选出来两个最大的 一定是合法(不相交)的

答案就是根的子树的最大值和次大值的加和

维护的办法是 维护每个点的 最大子树值 和 选两个子树的加和的最大值

这个点的最大子树值很好求 不断递归就好了

两个子树的加和的最大值 可以直接从每个子树的加和最大值继承来

也可能是 这个点每个儿子节点的最大子树 选出来最大值与次大值相加

最后如果根节点的最大值+次大值不存在 那就是没法选出来两个不相交子树

虽然写的代码是爆int的..

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<vector>
#include<queue>
#include<malloc.h>
using namespace std;
#define L long long
vector<int >q[200050];
int n ;
L a[200050];
L b[200050];
L dfs1(int fa ,int u){
b[u] = a[u];
for(int i = 0;i<q[u].size();i++){
int v = q[u][i];
if(v == fa)continue;
b[u] += dfs1(u,v);
}
return b[u];
}
L dp[200050][3];
void dfs(int fa,int u){
dp[u][0] = b[u];
dp[u][1] = -9999999999;
dp[u][2] = b[u];
L maxx = -9999999999;
L maxx2 = -9999999999;
for(int i=0;i<q[u].size();i++){
int v = q[u][i];
if(v == fa)continue;
dfs(u,v);
dp[u][2] = max(dp[u][2],dp[v][2]);
if(dp[v][2]!= -9999999999){
if(maxx == -9999999999){
maxx = dp[v][2];
}
else {
if(dp[v][2] > maxx){
maxx2 = maxx;
maxx = dp[v][2];
}
else {
if(maxx2 == -9999999999 || dp[v][2] > maxx2){
maxx2 = dp[v][2];
}
}
} }
}
if(maxx2!= -9999999999){
dp[u][1] = maxx2 + maxx;
}
for(int i =0;i<q[u].size();i++){
int v = q[u][i];
if(v == fa)continue;
dp[u][1] = max(dp[u][1] , dp[v][1]);
} }
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
q[i].clear();
}
for(int i=1;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
q[u].push_back(v);
q[v].push_back(u);
}
dfs1(-1,1);
dfs(-1,1);
if(dp[1][1]!= -9999999999)printf("%lld\n",dp[1][1]);
else printf("Impossible\n");
}

  

Codeforces Round #384 (Div. 2) ABCD的更多相关文章

  1. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  4. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #384 (Div. 2) E. Vladik and cards 状压dp

    E. Vladik and cards 题目链接 http://codeforces.com/contest/743/problem/E 题面 Vladik was bored on his way ...

  6. Codeforces Round #384 (Div. 2)D - Chloe and pleasant prizes 树形dp

    D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of ...

  7. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  8. Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学

    B. Chloe and the sequence 题目链接 http://codeforces.com/contest/743/problem/B 题面 Chloe, the same as Vla ...

  9. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

随机推荐

  1. jquery.print.js 打印插件

    <script language="javascript" src="jquery-1.4.4.min.js"></script> &l ...

  2. sdcms标签

    模板防盗:<%if not in_sdcms then response.write("template load fail"):response.end() end if% ...

  3. 关于Ajax工作原理

    1.ajax技术的背景 不可否认,ajax技术的流行得益于google的大力推广,正是由于google earth.google suggest以及gmail等对ajax技术的广泛应用,催生了ajax ...

  4. 响应式字体(js控制)

    window.onload=function(x){if ('addEventListener' in document) {document.addEventListener('DOMContent ...

  5. 监测程序运行的时间,stopWatch

    ArrayList arrInt = new ArrayList(); //用stopwatch来计时 运行的时间 Stopwatch watch = new Stopwatch(); watch.S ...

  6. 【转载】PyQt QSetting保存设置

    转载地址: http://blog.sina.com.cn/s/blog_4b5039210100h3zb.html 用户对应用程序经常有这样的要求:要求它能记住它的settings,比如窗口大小,位 ...

  7. 工欲善其事-Maven介绍与使用

    Maven是什么? Maven是一个项目管理和综合工具.Maven提供了开发人员构建一个完整的生命周期框架.开发团队可以自动完成项目的基础工具建设,Maven使用标准的目录结构和默认构建生命周期. 在 ...

  8. linux下将不同线程绑定到不同core和cpu上——pthread_setaffinity_np

    =============================================================== linux下的单进程多线程的程序,要实现每个线程平均分配到多核cpu,主 ...

  9. IBatis.Net使用总结(一)-- IBatis解决SQL注入(#与$的区别)

    IBatis解决SQL注入(#与$的区别) 在IBatis中,我们使用SqlMap进行Sql查询时,需要引用参数,在参数引用中可以使用两种占位符#和$.这两种占位符有什么区别呢? (1):#***#, ...

  10. C# 的EF框架怎么连接Oracle数据库

    安装odp.net ODP.NET你不需要安装Oracle,不需要配置oracle.key文件,不需要配置TnsNames.Ora文件 不需要配置环境变量:完全的傻瓜式的在没有安装oracle数据库或 ...