AIM Tech Round 3 (Div. 1) (构造,树形dp,费用流,概率dp)
B. Recover the String
大意: 求构造01字符串使得子序列00,01,10,11的个数恰好为$a_{00},a_{01},a_{10},a_{11}$
挺简单的构造, 注意到可以通过$a_{00}$和$a_{11}$求出0和1的个数, 假设求出分别为$x,y$, 然后再调整a01与a10, 可以注意到a01的范围是在[0,xy], 并且最小值的状态为11...1100...00, 每次将右侧的1前移一位恰好增加1, 所以这样不断调整即可. 忘了判0, WA了4发..
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 1e6+10;
int x, y, a[4];
char s[N];
int chk(int x) {
int l=0, r=x+10, ans;
while (l<=r) {
if ((ll)mid*(mid-1)/2>=x) ans=mid,r=mid-1;
else l=mid+1;
}
return ans;
} int main() {
REP(i,0,3) scanf("%d", a+i);
x = chk(a[0]), y = chk(a[3]);
if ((ll)x*(x-1)/2!=a[0]||(ll)y*(y-1)/2!=a[3]) return puts("Impossible"),0;
if (x==0&&y==0) {
if (a[1]+a[2]>1) return puts("Impossible"),0;
if (a[1]) puts("01");
else if (a[2]) puts("10");
else puts("0");
return 0;
}
if (!a[1]&&!a[2]) {
if (x==0) {REP(i,1,y) putchar('1');return hr,0;}
if (y==0) {REP(i,1,x) putchar('0');return hr,0;}
return puts("Impossible"),0;
}
x = max(x, 1), y = max(y, 1);
ll sum = 0;
REP(i,0,3) sum+=a[i];
if (sum!=(ll)(x+y)*(x+y-1)/2) return puts("Impossible"),0;
if (a[1]>(ll)x*y) return puts("Impossible"),0;
int k = a[1]/x, len = x+y;
REP(i,1,len) s[i]='0';
REP(i,1,y-k) s[i]='1';
REP(i,len-k+1,len) s[i]='1';
int res = a[1]-k*x;
s[y-k]='0', s[y-k+res]='1';
puts(s+1);
}
C. Centroids
大意: 给定树, 对于每个点判断移动一条边后是否能成为重心.
考虑每个点为根的情形, 只需要将最大子树选出尽量大的一块连到根上即可, 具体实现用树形dp, 维护最大转移与次大转移, 走最大子树时用次大, 其余用最大转移即可.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 1e6+10;
int n;
vector<int> g[N];
int mx[N], m1[N], m2[N], sz[N], ans[N];
void dfs(int x, int fa) {
sz[x] = 1;
int &t1=m1[x], &t2=m2[x];
for (int y:g[x]) if (y!=fa) {
dfs(y,x), sz[x]+=sz[y];
if (mx[y]>mx[t1]) t1=y;
}
for (int y:g[x]) if (y!=fa&&y!=t1) {
if (mx[y]>mx[t2]) t2=y;
}
mx[x] = mx[t1];
if (sz[x]<=n/2) mx[x] = sz[x];
}
void dfs2(int x, int fa, int pre) {
ans[x] = 1;
if (n-sz[x]-pre>n/2) ans[x]=0;
int &t1=m1[x], &t2=m2[x];
for (int y:g[x]) if (y!=fa) {
if (sz[y]-mx[y]>n/2) ans[x]=0;
if (n-sz[y]<=n/2) dfs2(y,x,n-sz[y]);
else dfs2(y,x,y==t1?max(pre,mx[t2]):max(pre,mx[t1]));
}
} int main() {
scanf("%d", &n);
REP(i,2,n) {
int u, v;
scanf("%d%d", &u, &v);
g[u].pb(v),g[v].pb(u);
}
dfs(1,0),dfs2(1,0,0);
REP(i,1,n) printf("%d ",ans[i]);hr;
}
AIM Tech Round 3 (Div. 1) (构造,树形dp,费用流,概率dp)的更多相关文章
- codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...
- AIM Tech Round 4 (Div. 1) C - Upgrading Tree 构造 + 树的重心
C - Upgrading Tree 我发现我构造题好弱啊啊啊. 很明显能想到先找到重心, 然后我们的目标就是把所有点接到重心的儿子上,让重心的儿子子树变成菊花图, 这个先把重心到儿子的边连到 i , ...
- AIM Tech Round 3 (Div. 1) B. Recover the String 构造
B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each str ...
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...
- AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)
D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...
- AIM Tech Round 3 (Div. 2)
#include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...
- AIM Tech Round 3 (Div. 2) A B C D
虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...
- AIM Tech Round 3 (Div. 2) B
Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...
- AIM Tech Round 3 (Div. 2) A
Description Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Ko ...
随机推荐
- linux常用命令:tar 命令
通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...
- 安装rocketmq-console
一.alibaba版本 使用rocketmq命令查看集群状态,查看topic信息时比较麻烦,而且不直观,这个时候可以使用一些web页面来管理rocketmq. 以前曾使用过一个老版本的工具,适用于al ...
- MySQL数据库----存储过程
存储过程 存储过程包含了一系列可执行的sql语句,存储过程存放于MySQL中,通过调用它的名字可以执行其内部的一堆sql -- 存储过程的优点: -- 1.程序与数据实现解耦 -- 2.减少网络传输的 ...
- nginx服务器的rewrite功能
nginx编译的时候默认是把rewrite功能编辑进去的,但是因为rewrite需要使用正则表达式,因此需要安装pcre依赖包. yum install -y pcre pcre-install re ...
- P1771 方程的解_NOI导刊2010提高(01)
P1771 方程的解_NOI导刊2010提高(01) 按题意用快速幂把$g(x)$求出来 发现这不就是个组合数入门题吗! $k$个人分$g(x)$个苹果,每人最少分$1$个,有几种方法? 根据插板法, ...
- P2455 [SDOI2006]线性方程组(real gauss)
P2455 [SDOI2006]线性方程组 (upd 2018.11.08: 这才是真正的高斯消元模板) 找到所消未知数(设为x)系数最大的式子,把它提上来 把这个式子的 x 系数约成1 把这个式子用 ...
- Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在
Tomcat8.5 升级tomcat版本导致出现异常,Base64不存在 原因分析: 由于tomcat由7升级到8.5导致Base64的引用路径错误,默认引用为8.5中的jar, 解决方案: 修改引用 ...
- linux django 知识点 安装mysql数据库 和 pycharm
django 命令及相关知识点 1. 启动 pycharm 命令:sh pycharm.sh 2. 创建 django 项目 : django-admin.py startproject Hello ...
- 20145122 《Java程序设计》第十周学习总结
学习内容总结 网络编程 (1)网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. (2)程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的数据,这个就是狭义的网络编程范畴. (3 ...
- 20145334赵文豪 WEB基础实践
实验问题回答 1.什么是表单 表单在网页中主要负责数据采集功能 一个表单有三个基本组成部分: 表单标签 表单域:包含了文本框.密码框.隐藏域.多行文本框.复选框.单选框.下拉选择框和文件上传框等 表单 ...