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

  1. 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 ...

  2. AIM Tech Round 4 (Div. 1) C - Upgrading Tree 构造 + 树的重心

    C - Upgrading Tree 我发现我构造题好弱啊啊啊. 很明显能想到先找到重心, 然后我们的目标就是把所有点接到重心的儿子上,让重心的儿子子树变成菊花图, 这个先把重心到儿子的边连到 i , ...

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

  4. 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 ...

  5. 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 ...

  6. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  7. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  8. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...

  9. 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 ...

随机推荐

  1. Linux服务器---配置apache支持php

    apache支持php php是最好用的服务器语言了,Apache对php有很强大的支持 1.检测是否安装php,如果什么信息也没有,那么你就要自己安装php了 [root@localhost ~]# ...

  2. .NET,ASP.NET,ASP.NET MVC 之间的区别

    https://www.cnblogs.com/wwym/p/5555772.html

  3. Low-level Native Plugin Interface

    http://docs.manew.com/Manual/index.htm https://docs.unity3d.com/Manual/NativePluginInterface.html ht ...

  4. python_实现发送邮件功能

    #!/usr/bin/env python #-*- coding:utf-8 -*- from email import encoders from email.header import Head ...

  5. 海量数据处理-BitMap算法

    一.概述 本文将讲述Bit-Map算法的相关原理,Bit-Map算法的一些利用场景,例如BitMap解决海量数据寻找重复.判断个别元素是否在海量数据当中等问题.最后说说BitMap的特点已经在各个场景 ...

  6. 【第十九章】 springboot + hystrix(1)

    hystrix是微服务中用于做熔断.降级的工具. 作用:防止因为一个服务的调用失败.调用延时导致多个请求的阻塞以及多个请求的调用失败. 1.pom.xml(引入hystrix-core包) 1 < ...

  7. 51nod 1242 斐波那契数列的第N项

    之前一直没敢做矩阵一类的题目 其实还好吧 推荐看一下 : http://www.cnblogs.com/SYCstudio/p/7211050.html 但是后面的斐波那契 推导不是很懂  前面讲的挺 ...

  8. java 监控工具 jconsole

    如图

  9. 论文笔记——Rethinking the Inception Architecture for Computer Vision

    1. 论文思想 factorized convolutions and aggressive regularization. 本文给出了一些网络设计的技巧. 2. 结果 用5G的计算量和25M的参数. ...

  10. requirejs概念