ZOJ Monthly, August 2012

Source: Internet
Author: User
Tags getbase cmath

A:

Topic Link: Click to open the link

Alice ' s present

#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <map> #include <queue> #include <set> #include <algorithm>using namespace std;int N, m;int a[501000];map< int, int> Mp;int main () {while (scanf ("%d", &n)! = EOF) {for (int i = 1; I <= n; i++) scanf ("%d", &a[i]); scan F ("%d", &m); int L, r;for (int j = 1; j <= M; j + +) {scanf ("%d%d", &l, &r); int i;mp.clear (); for (i = r; I ; = l; i--) {mp[a[i]]++;if (mp[a[i]]>1) {printf ("%d\n", A[i]); if (I < L) printf ("ok\n");} printf ("\ n");}}
B:

Topic Link: Click to open the link

Bounty Hunter

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace Std;const int n=1e5+9;double a[n],b[n];d ouble dp[n],_dp[n];int Main () {    int i,j,k,n,m,t;    Double x, y;    while (~SCANF ("%d%lf%lf", &n,&x,&y)) {for        (i=1;i<=n;i++)            scanf ("%lf%lf", a+i,b+i);        Dp[n+1]=1;        _dp[n+1]=0;        for (i=n;i>=1;i--) {            _dp[i]=_dp[i+1]+b[i]*dp[i+1];            Dp[i]=max (Dp[i+1],_dp[i]/a[i]);        }        printf ("%.2lf\n", dp[1]*x+_dp[1]*y);    }    return 0;}
C:

Topic Link: Click to open the link

Cinema in Akiba

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int max_n = 100007;    int n, M;int bit[max_n], a[max_n];int sum (int i) {int s = 0;        while (i > 0) {s + = bit[i];    I-= i &-i; } return s;}        void Add (int i, int x) {while (I <= N) {Bit[i] + = x;    i + = i &-i;        }}int Main () {while (1 = = scanf ("%d", &n)) {memset (bit, 0, sizeof bit);        for (int i = 1; I <= n; ++i) Add (i, 1);            for (int i = 1; I <= n; ++i) {int V;            scanf ("%d", &v);            int L = 0, r = N;                while (L + 1 < r) {int mid = (L + r) >> 1;                if (sum (mid) < V) L = mid;            else R = Mid;            } A[i] = R;        Add (R,-1);        } scanf ("%d", &m);            for (int i = 0; i < m; ++i) {int V;            scanf ("%d", &v); if (i = = 0) printf ("%D ", A[v]);        else printf ("%d", a[v]);    } puts (""); } return 0;} /*64 1 3 3 1 161 2 3 4 5 6*/

D:

Topic Link: Click to open the link

Decode

#include <cstdio> #include <cstring> #include <vector>using namespace Std;int N, K, m;vector<int    > Base;char s[50];void getbase () {vector<int> V; for (int i = n-1; I >= 0; i.) for (int j = 0; J < base.size (); ++j) if (Base[j] & (1 <<                i)) {int x=base[j];                V.push_back (x);                for (int k=0;k<base.size (); k++) if (base[k]& (1<<i)) base[k]^=x;            Break } Base=v;} void out (int. x) {for (int i=n-1;i>=0;i--) Putchar (((1<<i) &x), 49:48);p UTS ("");    BOOL Jud (int x) {int j=0; for (int i=n-1;i>=0&&x;i--) {if ((1<<i) &x) {while (J<base.size () && (!) ( (1<<i) &base[j]) | |            Base[j]>= (1<<i+1)) J + +;            if (J==base.size ()) return 0;        else x^=base[j++]; }} return 1;} int main () {while (scanf ("%d%d%d", &n,&k,&m)!=eof) {base.clear ();            for (int i=0; i<k; i++) {scanf ("%s", s);            int x=0; for (int j=0; j<n; j + +) x= (x<<1) |            (s[j]-48);        Base.push_back (x);        } getbase ();            for (int i=0;i<m;i++) {scanf ("%s", s);            int ans=0x7fffffff,diff=100;            int x=0; for (int j=0;j<n;j++) x= (x<<1) |            (s[j]-48);                        for (int i=0;i<=n;i++) for (int j=i;j<=n;j++) for (int k=j;k<=n;k++) {                        int dif= (i!=n) + (j!=n) + (k!=n);                        int tmp= (x^ (1<<i) ^ (1<<j) ^ (1<<k)) & ((1<<n)-1); if (dif<diff| | (Dif==diff&&tmp<ans))                    &&jud (TMP)) diff=dif,ans=tmp;            } if (ANS==0X7FFFFFFF) puts ("NA");        Else out (ans); }} return 0;}
E:

Topic Link: Click to open the link
Education Manage System

#include <cstdio> #include <cstring> #include <string> #include <vector> #include <algorithm                   >using namespace Std;const int max_n = 200007;const int max_t = 60 * 400;const int day[] = {0, 31,, 91, 121,    182, 213, 244, 274, 305, 335, 366};struct Node {int L, R;    Double V;    Node () {} node (int _l, int _r, double _v) {L = _l, r = _r, V = _v;    }};int n;double dp[max_t];vector<node> a[max_t];int Month (string s) {if (s = = "Jan") return 1;    if (s = = "Feb") return 2;    if (s = = "Mar") return 3;    if (s = = "APR") return 4;    if (s = = "May") return 5;    if (s = = "June") return 6;    if (s = = "Jul") return 7;    if (s = = "") return 8;    if (s = = "Sep") return 9;    if (s = = "Oct") return 10;    if (s = = "Nov") return 11; if (s = = "Dec") return 12;}    int input () {char str[10], str2[10];    scanf ("%s", str);    int d, h, M;    scanf ("%d%*s", &d);    scanf ("%d:%d", &h, &m); scanf ("%S ", str2);    if (str2[0] = = ' P ') H + = 12; return m + H * + (d + day[month (str)-1]) * 24 * 60;}       int main () {while (1 = = scanf ("%d", &n)) {memset (DP, 0, sizeof DP);       int ma = 0;      for (int i = 0; i < max_t; ++i) a[i].clear ();            for (int i = 0; i < n; ++i) {int L, R;            Double V;            L = input ();            R = input ();            MA = max (R, MA);         scanf ("%lf", &v);            printf ("%d%d%f\n", L, R, v);      A[r + 5].push_back (Node (L, R + 5, v));        } for (int i = 1; i < max_t; ++i) {dp[i] = dp[i-1];        for (int j = 0; J < a[i].size (); ++j) {Dp[i] = max (Dp[i], DP[A[I][J].L] + a[i][j].v);    }} printf ("%.1f\n", dp[max_t-1]); } return 0;}
F:

Topic Link: Click to open the link
Fruit Ninja

#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include < cmath> #include <cstring> #include <set> #include <vector> #include <map>using namespace std; const int INF = 0x3f3f3f3f;const int MAXN = 1100; const int mod = 100000007;map<string,int> low, high; int n, M; Char S1[MAXN], S2[MAXN], STR[MAXN]; char OP[MAXN], S[MAXN];vector<int> l; int xx = 0,x=0; long long result = 0;    int fact[10000050];int power (int x,int y) {int res=1;        while (y) {if (y&1) res= (long Long) res*x%mod;        x= (long Long) x*x%mod;    y>>=1; } return res; int inv (int x) {return power (x,mod-2);}    int C (int x, int y) {if (x>10000020) while (1); Return (long Long) fact[x] * INV (fact[x-y])% mod * INV (fact[y])% MoD;}        void Dfs (int pos, int now, BOOL flag) {if (pos = = x) {if (now > m) return;        if (flag) Result-= C (n + m-now-1, n-1); else result + = C (n + m-now-1, n-1);        Result%= MoD;    return;    } DFS (pos + 1, now + l[pos], flag ^ 1); DFS (POS + 1, now, flag);}    int main () {fact[0] = 1;    for (int i = 1; I <= 10000030; i++) fact[i] = (long long) fact[i-1] * I% mod;        while (~SCANF ("%d", &n) && n>0) {scanf ("%d", &m);        Gets (str);        x=0;        xx=0;        BOOL Flag =true;        L.clear ();            while (1) {if (!gets (str)) is break;            if (strlen (str) < 2) break;            int X;            SSCANF (str, "%s%s%s%d", s1,s1,s2,&x); if (*s1 = = ' L ') {l.push_back (X); X++;if (!            X) Flag=false;}            else {m-=x+1;}        xx++;            } if (!flag) {printf ("0\n");        Continue;        } if (M < 0) printf ("0\n");            else {result = 0;            DFS (0,0,0);        printf ("%lld\n", (result% mod + MoD)% mod); }} return 0;}

H:

Topic Link: Click to open the link

Help Me Escape

Calculate the maximum number of doors, in fact, growth is a two times, so the search can be

#include <cstdio> #include <cmath> #include <cstring> #include <algorithm>using namespace std; const int N = 105;const double P = sqrt (5.0); int a[n], n;double dp[20005];d ouble dfs (int f) {if (Dp[f] > 0) return dp[f]  ;DP [F] = 0;for (int i = 0; i < n; i + +) {if (F > a[i]) {int num = (int) ((p+1)/2.0*a[i]*a[i]);DP [f] + = (double) num/n;} else {Dp[f] + = (1+dfs (f+a[i))/n;}} return dp[f];} int main () {int F;    while (~SCANF ("%d%d", &n, &f)) {    memset (DP, 0, sizeof DP), for (int i = 0; i < n; i + +) {scanf ("%d", &a[i ]);} printf ("%.3f\n", DFS (f));    }    return 0;}
I:

Topic Link: Click to open the link
Information sharing

#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <map> #include <queue> #include <set> #include <algorithm>template <class t>inline BOOL Rd (T &ret) {char c; int sgn;if (c = GetChar (), c = = EOF) return 0;while (c! = '-' && (c< ' 0 ' | | c> ' 9 ')) C = GetChar (); SG n = (c = = '-')? -1:1;ret = (c = = '-')? 0: (C-' 0 '); while (c = GetChar (), C >= ' 0 ' &&c <= ' 9 ') ret = ret * + (C-' 0 '); ret *= Sgn;return 1;} Template <class t>inline void pt (T x) {if (x <0) {Putchar ('-'); x = x;} if (x>9) pt (X/10);p Utchar (x% 10 + ' 0 ');} using namespace Std;const int inf = 1e9;const int N = 100010;const int M = -1;int n;map<string, Int>mp;set<int&gt ; St[n], Tmp;set<int>::iterator it;int f[n], top;int find (int x) {if (x = = F[x]) return x;int y = Find (f[x]); for (it = St[x].begin (); It! = St[x].end (); it++) St[y].insert (*it); St[x].clear (); return f[x] = y;} void Union (int x, int y{int FX = find (x), FY = Find (y), if (FX = = FY) return;if (FX > FY) Swap (FX, FY); for (it = St[fx].begin (); it = St[fx].en D (); it++) St[fy].insert (*it); St[fx].clear (); f[fx] = fy;} Char op[20];string s, t;int num, u;void Add () {cin >> s;f[top] = top;st[top].clear (); Rd (num); while (num--) {rd (U); St [Top].insert (U); }mp[s] = top++;} void Check () {cin >> s;int x = Find (Mp[s]);p t ((int) st[x].size ()); Putchar (' \ n ');} int main () {while (~SCANF ("%d", &n)} {mp.clear (); top = 0;int out = False;while (n--) {scanf ("%s", op); if (op[0] = = ' a ') {Add ();} else if (op[0] = = ' s ') {cin >> S; Cin >> T; Union (Mp[s], mp[t]);} Else{check (); out = True;}}} return 0;}  /*99arr a 3 1 2 3arr B 1 4arr c 1 5arr d 1 6chec Asha a BCHEC bchec Asha a dchec achec D99arr a 0arr b 0arr C 1 1c AC CSHA b cc Bsha a BC a3311 Dig the Wells4085 Peach Blossom Spring1970 Ticket to ridezoj-3613poj 3123 */
J:
Topic Link: Click to open the link
Just Another information sharing problem

Obviously everyone's nether is useless, because it can be eliminated by a number of unrelated to the target, and there must be such a loop = =, so the maximum flow can be directly run, the target point of information due to unrestricted, so directly from the source point to build edge to the meeting point is good.



#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <map> #include <queue> #include <set> #include <algorithm>template <class t>inline BOOL Rd (T &ret) {char c; int sgn;if (c = GetChar (), c = = EOF) return 0;while (c! = '-' && (c< ' 0 ' | | c> ' 9 ')) C = GetChar (); SG n = (c = = '-')? -1:1;ret = (c = = '-')? 0: (C-' 0 '); while (c = GetChar (), C >= ' 0 ' &&c <= ' 9 ') ret = ret * + (C-' 0 '); ret *= Sgn;return 1;} Template <class t>inline void pt (T x) {if (x <0) {Putchar ('-'); x = x;} if (x>9) pt (X/10);p Utchar (x% 10 + ' 0 ');} using namespace Std;const int inf = 1e9;const int N = 5000;const int M = 500010;const int inf = ~0u >> 2;template&lt ; class t>struct Max_flow {int n;int q[n], Sign;int head[n], level[n], cur[n], Pre[n];int nxt[m], pnt[m], E; T cap[m];void Init (int n) {this->n = n + 1; E = 0;std::fill (head, head + this->n,-1);} Have to RW = 0void Add (int from, int To, T C, t RW) {pnt[e] = to;cap[e] = c;nxt[e] = Head[from];head[from] = e++;p nt[e] = from;cap[e] = rw;nxt[e] = head[to];h Ead[to] = e++;}  BOOL Bfs (int s, int t) {sign = T;std::fill (level, Level + N,-1); int *front = Q, *tail = q;*tail++ = t; level[t] = 0;while (Front < tail && Level[s] = =-1) {int u = *front++;for (int e = Head[u]; E! =-1; e = Nxt[e]) {if (cap[e ^ 1] > 0 && level[pnt[e]] < 0) {Leve L[pnt[e]] = Level[u] + 1;*tail++ = Pnt[e];}}} return Level[s]! =-1;} void Push (int t, T &flow) {t mi = inf;int p = pre[t];for (int p = pre[t]; p! =-1; p = pre[pnt[p ^ 1]]) {mi = std::min (MI, cap[p]);} for (int p = pre[t]; p! =-1; p = pre[pnt[p ^ 1]]) {cap[p]-= Mi;if (!cap[p]) {sign = pnt[p ^ 1];} Cap[p ^ 1] + = mi;} Flow + = mi;} void Dfs (int u, int t, T &flow) {if (U = = t) {Push (t, flow); return;}  for (int &e = Cur[u]; e =-1; e = Nxt[e]) {if (Cap[e] > 0 && level[u]-1 = level[pnt[e]]) {Pre[pnt[e]] = E;dfs (Pnt[e], T, flow); if (Level[sign] > LevEl[u]) {return;} sign = t;}}} T Dinic (int s, int t) {Pre[s] =-1; T flow = 0;while (Bfs (S, t)) {std::copy (head, head + N, cur);D FS (S, t, flow);} return flow;}}; Max_flow <int>f;int N, M, l[211], r[210];set<int>st[205], Tmp;set<int>::iterator it;vector<int >g;void input () {g.clear (); for (int i = 1, num, u; I <= n; i++) {rd (num); Rd (L[i]); Rd (R[i]); St[i].clear (); while (num-- ) {rd (U); St[i].insert (U); G.push_back (U); }}sort (G.begin (), G.end ());  G.erase (Unique (G.begin (), G.end ()), G.end ()); Rd (M); for (int i = 1; I <= n; i++) {tmp.clear (); for (it = St[i].begin (); it ! = St[i].end (); it++) Tmp.insert (Lower_bound (G.begin (), G.end (), *it)-G.begin () + 1); St[i] = tmp;}} int main () {while (~SCANF ("%d", &n)} {input (); int from = 0, to = n + g.size () + 1; F.init (to + ten); for (int i = 1; I <= n; i++) {F.add (from, I, R[i], 0); for (it = St[i].begin (); it = St[i].end (); it++) { F.add (i, n + (*it), 1, 0);}} F.add (from, M, St[m].size (), 0), for (int i = 0; i < g.size (); i++) F.add (n + 1 + i, to, 1, 0);p rintf ("%d\n", F.dinic (from, to));} return 0;}

K:

Topic Link: Click to open the link

Keep Deleting

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;char a[257], b[512005]; int main () {    while (~scanf ("%s", a)) {        int l = strlen (a);        scanf ("%s", b);        int len = strlen (b), size = l-1, cnt = 0;        for (int i = l-1; i < Len; i + +) {b[size++] = B[i];        if (size >= l) {        int ok = 1;        for (int j = 0; J < L; j + +) {if (a[j]! = B[size-l+j]) {ok = 0;break;}} if (OK) {cnt ++;size-= l;}}        }        printf ("%d\n", CNT);    }    return 0;}


ZOJ Monthly, August 2012

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.