Luogu 1087 FBI tree
#include <cstdio>
#include <cstring>
char s[4100];
int n;
char fbi(int l, int r) {
bool f0=false, f1=0;
for (int k=l; k<r; k++){
if (s[k]=='0') f0=true; else f1=true;
if (f0 && f1) return 'F';
}
if (f0) return 'B'; return 'I';
}
void dfs(int l, int r) {
if (r-l>1){
int p=l+(r-l)/2;
dfs(l, p), dfs(p, r);
}
putchar(fbi(l,r));
}
int main() {
scanf("%d", &n); scanf("%s", s);
dfs(0, strlen(s));
return 0;
}
Bzoj 1635 [Usaco2007 JAN] Tallest Cow
#include <cstdio>
#include <cstring>
#define max(A, B) ((A)>(B)?(A):(B))
#define min(A, B) ((A)<(B)?(A):(B))
int n, I, H, R, t;
int f[10005];
bool v[10005][10005];
int main() {
scanf("%d%d%d%d", &n, &I, &H, &R);
for (int i=1; i<=n; ++i) f[i]=H;
while (R--) {
register int a, b;
scanf("%d%d", &a, &b);
register int x=min(a, b), y=max(a, b);
if (v[x][y]) continue; v[x][y]=true;
for (int i=x+1; i<y; ++i) --f[i];
}
for (int i=1; i<=n; ++i) printf("%d
", f[i]);
return 0;
}
Bzoj 1621 [Usaco2008 Open] Roads Around The Farm
#include <cstdio>
int cnt, n, k;
void dfs(int x) {
if (x<=k || (x-k)&1) ++cnt; else dfs(x-k>>1), dfs(x+k>>1);
}
int main() {
scanf("%d%d", &n, &k);
dfs(n);
printf("%d
", cnt);
return 0;
}
Bzoj 1088 [SCOI2005] Mine
#include <cstdio>
#include <cstring>
int n, d[10005], p[10005], ans;
inline bool chk() {
for (int i=2; i<=n; ++i) p[i+1]=d[i]-p[i-1]-p[i];
return !p[n+1];
}
int main() {
scanf("%d", &n);
memset(p, -1, sizeof p);
for (int i=1; i<=n; ++i) scanf("%d", &d[i]);
for (int i=0; i<=d[1]; ++i) {
memset(p, 0, sizeof p);
p[1]=i, p[2]=d[1]-i;
if (chk()) ++ans;
}
printf("%d
", ans);
return 0;
}