BestCoder Round #36

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;
}
时间: 2024-10-11 17:54:15

BestCoder Round #36的相关文章

BestCoder Round #36 (hdu5200)Strange Class(离线)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Today CodeFamer is going to cut trees.There are N trees standing in a line. They

BestCoder Round #36 (hdu5199)Gunner(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Gunner Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very

BestCoder Round #36 (hdu5198)Strange Class(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Strange Class Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description In Vivid’s school, there is a strange class(SC). In SC, the students’ nam

BestCoder Round #36 [B] Gunner

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5199 先对树的高度排序,然后对每次射击高度二分查找即可,打过之后数目变为0. 1 #include<cstdio> 2 #include<iostream> 3 #include<string.h> 4 #include<algorithm> 5 #include<math.h> 6 #include<stdbool.h> 7 #incl

BestCoder Round #36(Strange Class-模拟)

Strange Class Accepts: 519 Submissions: 1749 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 在Vivid的学校里,有一个奇怪的班级(SC).在SC里,这些学生的名字非常奇怪.他们的名字形式是这样的a n b n c n   (a,b,c两两不相同.).例如,叫"abc","ddppqq"的学生是在S

BestCoder Round #36(Gunner-hash)

Gunner Accepts: 391 Submissions: 1397 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 很久很久以前,有一个叫Jack的枪手.他非常喜欢打猎.一天,他去了一个小树林.那儿有只鸟,还有n 棵树.第i 只鸟站在第i 棵树的顶端.这些树从左到右排成一条直线.每一棵树都有它的高度.Jack站在最左边那棵树的左边.当Jack在高度为H 的地方向右发

BestCoder Round #36(Trees-离线处理询问)

Trees Accepts: 156 Submissions: 533 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 今天CodeFamer去坎树.有N 棵树排成一排.他们被从1 到N 标号.第i 号树的高度为h i  .两棵未被坎掉的树编号分别为x,y  当且仅当他们满足如下条件中一条时,他们是属于同一个块的: 1) x+1=y 或 y+1=x; 2) 存在一个棵未被坎

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <

BestCoder Round #88

传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <ctime> 5 #include <cmath> 6 #include <iostream> 7 #include <algorithm> 8