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 ...
随机推荐
- 实现kylin定时跑当天的任务
说明: 每天自动构建cube,动态在superset里面查看每天曲线变化图 #! /bin/bash ##cubeName cube的名称 ##endTime 执行build cube的结束时间 (命 ...
- 数据仓库基础(十)Informatica 组件1
本文转载自:http://www.cnblogs.com/evencao/p/informatica.html Informatica主要的组件: Source Qualifier 从数据源读取数据 ...
- LLVM/Clang编译相关研究
https://blog.csdn.net/guojin08/article/details/54310858 https://juejin.im/entry/5c64da44518825620b45 ...
- thinkphp标签实现bootsrtap轮播carousel实例
thinkphp标签实现bootsrtap轮播carousel实例由于轮播carousel第一个div需要设置active样式才能正常显示,上面的圆点也同样需要数字,使用volist标签在循环的同时可 ...
- linux服务器文件索引inodes满了
inode节点中,记录了文件的类型.大小.权限.所有者.文件连接的数目.创建时间与更新时间等重要的信息,还有一个比较重要的内容就是指向数据块的指针.一般情况不需要特殊配置,如果存放文件很多,需要配置. ...
- 在 Linux 中使用超级用户权限
在你想要使用超级权限临时运行一条命令时,sudo 命令非常方便,但是当它不能如你期望的工作时,你也会遇到一些麻烦.比如说你想在某些日志文件结尾添加一些重要的信息,你可能会尝试这样做: $ echo & ...
- Django框架介绍之一
这片博文就是对django有个大概的了解,通俗的说,就是先让django跑起来. django安装 在linux上安装如下: 源码安装: tar -zxvf Django-1.9.13.tar.gz ...
- linux查看内存free
free 加参数-b/k//m/g,以b.k.m.g的大小显示结果,默认以k显示 [root@oldboy ~]# free total used free shared buffers cached ...
- P2158/bzoj2190 [SDOI2008]仪仗队
P2158 [SDOI2008]仪仗队 欧拉函数 计算下三角的点数再*2+1 观察斜率,自行体会 #include<iostream> #include<cstdio> #in ...
- 把一个activity作为弹窗
1.可以在这个activity的xml中设置其高度为某个固定高度 2.在java中:getWindow().setGravity(Gravity.BOTTOM);//设置在底部出现 getWindo ...