Bestcoder Round #36

Source: Internet
Author: User

A: Registration questions, attention to the situation are considered all the judgment can be

B:hash tree height, statistics can be added to read into the hang (slightly pits)

C: Offline operation, the query and tree height from the big to the small sort, and then cut the tree into a tree, each time more than the current inquiry of the tree are added, each time the tree and left and right to judge, record the situation of the block transformation, and then save the answer to the corresponding query

Code:

#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]) retu RN 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, have + 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, have + HN);        HN = Unique (has, have + 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[tre                E[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;}


Bestcoder Round #36

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.