A:签到题,注意情况都考虑全了判断即可
B:hash树高,统计即可,要加读入挂(略坑)
C:离线操作,把询问和树高都从大到小排序,然后砍树变成加树,每次把超过当前询问的树都加进去,每次加树就和左右边判断下,记录下块变换的情况,然后把答案存到相应询问中
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char str[105];
bool judge() {
    int n = strlen(str);
    if (n % 3) return false;
    int a = n / 3;
    for (int i = 0; i < 3; i++) {
        for (int j = i * a + 1; j < (i + 1) * a; j++) {
            if (str[j] != str[j - 1]) return false;
        }
    }
    if (str[a] == str[0] || str[2 * a] == str[a] || str[0] == str[2 * a]) return false;
    return true;
}
int main() {
    while (gets(str) != NULL) {
        int n = strlen(str);
        if (judge()) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
inline void scanf_(int &num)//ÎÞ¸ºÊý
{
    char in;
    while((in=getchar()) > '9' || in<'0') ;
    num=in-'0';
    while(in=getchar(),in>='0'&&in<='9')
        num*=10,num+=in-'0';
}
const int N = 1000005;
int n, m, h[N], has[N], hn, cnt[N];
int get(int x) {
    int v = lower_bound(has, has + hn, x) - has;
    if (has[v] == x) return v;
    return -1;
}
int main() {
    while (~scanf("%d%d", &n, &m)) {
        for (int i = 0; i < n; i++) {
            scanf_(h[i]);
            cnt[i] = 0;
            has[i] = h[i];
        }
        hn = n;
        sort(has, has + hn);
        hn = unique(has, has + hn) - has;
        for (int i = 0; i < n; i++)
            cnt[get(h[i])]++;
        int q;
        while (m--) {
            scanf_(q);
            int ca = get(q);
            if (ca == -1) printf("0\n");
            else {
                printf("%d\n", cnt[ca]);
                cnt[ca] = 0;
            }
        }
    }
    return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 50005;
struct Query {
    int v, id;
    void read(int id) {
        scanf("%d", &v);
        this->id = id;
    }
} query[N];
struct Tree {
    int h, id;
    void read(int id) {
        scanf("%d", &h);
        this->id = id;
    }
} tree[N];
bool cmpq(Query a, Query b) {
    return a.v > b.v;
}
bool cmpt(Tree a, Tree b) {
    return a.h > b.h;
}
int parent[N];
int find(int x) {
    if (x == parent[x]) return x;
    return parent[x] = find(parent[x]);
}
int n, q, vis[N], tot;
int ans[N];
void uni(int u, int v) {
    int pu = find(u);
    int pv = find(v);
    if (pu != pv) {
        parent[pu] = pv;
        tot--;
    }
}
int main() {
    while (~scanf("%d%d", &n, &q)) {
        memset(vis, 0, sizeof(vis));
        for (int i = 0; i < n; i++) parent[i] = i;
        for (int i = 0; i < n; i++) tree[i].read(i);
        for (int i = 0; i < q; i++) query[i].read(i);
        int sum = n;
        sort(query, query + q, cmpq);
        sort(tree, tree + n, cmpt);
        int u = 0;
        tot = 0;
        for (int i = 0; i < q; i++) {
            while (u < n && tree[u].h > query[i].v) {
                vis[tree[u].id] = 1;
                tot++;
                if (tree[u].id != 0 && vis[tree[u].id - 1]) {
                    uni(tree[u].id, tree[u].id - 1);
                }
                if (tree[u].id != n - 1 && vis[tree[u].id + 1]) {
                    uni(tree[u].id, tree[u].id + 1);
                }
                u++;
            }
            ans[query[i].id] = tot;
        }
        for (int i = 0; i < q; i++)
            printf("%d\n", ans[i]);
    }
    return 0;
}
原文:http://blog.csdn.net/accelerator_/article/details/44890495