UESTC 2014 summer training #10 div.2

Source: Internet
Author: User

B. Race to 1 ultraviolet A 11762

The first contact with probability DP, I did not expect it to be DP...

First, you need to know the total expectation = the expectation of each thing × the probability of each thing happening

Then we can write a recursive formula based on this, which is also DP?

Assume that there are m prime numbers not less than X, and N qualitative factors of X (more accurate), then when X is expected, we can consider that X, X/pi p is the prime factor of X.

Therefore, it is not difficult to conclude that E (x) = 1 + (m-N)/ME (x) + 1/msigmae (x/PI) will add 1, because X is transferred to the back end, there is one more step.

// Updated: every case is run out, and the F array does not need memset... it will be 10 times faster! In the case

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int maxn = 1000000+50;const double eps = 1e-10;int T, N, tot;int prime[maxn];double f[maxn];bool flag[maxn], done[maxn];void getPrime(){    for(int i = 2; i < maxn; i++) {        if(!flag[i])    prime[tot++] = i;        for(int j = 0; j < tot && prime[j]*i < maxn; j++) {            flag[i*prime[j]] = true;            if(i % prime[j] == 0)    break;        }    }}double dp(int x){    if(done[x])    return f[x];    done[x] = true;    int n, m;    n = m = 0;    for(int i = 0; i < tot && prime[i] <= x; i++) {        n++;        if(x % prime[i] == 0) {            m++;            f[x] += dp(x/prime[i]);        }    }//    if(x == N)    cout << n << ‘ ‘ << m << endl;    return f[x] = (f[x]+n)/m;}int main(){#ifdef LOCAL    freopen("B.in", "r", stdin);#endif    getPrime();    scanf("%d", &T);    for(int t = 1; t <= T; t++) {        scanf("%d", &N);        memset(done, 0, sizeof(done));        memset(f, 0, sizeof(f));        f[1] = 0.0;    done[1] = true;        dp(N);        printf("Case %d: %.10lf\n", t, f[N]);    }    return 0;}

 

D. Jumping Mario ultraviolet (a) 11764

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int T, n, now, high, low;int main(){    cin >> T;    for(int t = 1; t <= T; t++) {        high = 0;        low = 0;        cin >> n;        for(int i = 0; i < n; i++) {            int x;            cin >> x;            if(i == 0) {                now = x;                continue;            }            if(x > now)    high++;            else if(x < now)    low++;            now = x;        }        cout << "Case " << t << ": " << high << ‘ ‘ << low << endl;    }    return 0;}

 

J. Lighting away ultraviolet A 11770

The first reaction is indeed a strongly connected component... contraction point... but I am not familiar with... so I went to the yydfs method, but I was not enough IQ... I didn't debug it.

The positive solution is to reduce the point dyeing to determine the new graph entry into the 0 point.

Debugging for a long time... all kinds of small errors have been found, and finally fell out of the stack and forgot to increase the brackets...

 

#include <iostream>#include <cstdio>#include <cstdlib>#include <stack>#include <cstring>using namespace std;const int maxn = 100000+50;int T, n, m, idx, tot, cnt;int head[maxn], next[maxn], edge[maxn], dfn[maxn], low[maxn], in[maxn], type[maxn];bool instack[maxn], visit[maxn];stack<int> st;void add(int u, int v){    edge[tot] = v;    next[tot] = head[u];    head[u] = tot++;}void tarjan(int u){    dfn[u] = low[u] = ++idx;    st.push(u);    instack[u] = true;    visit[u] = true;    for(int e = head[u]; e != -1; e = next[e]) {        int v = edge[e];        if(!visit[v]) {            tarjan(v);            low[u] = min(low[u], low[v]);        }                else if(instack[v])            low[u] = min(low[u], dfn[v]);    }    if(dfn[u] == low[u]) {        cnt++;        while(!st.empty())        {            int now=st.top();    st.pop();            instack[now]=0;            type[now]=cnt;            if(now == u) break;        }    }}int main(){#ifdef LOCAL    freopen("J.in", "r", stdin);#endif    scanf("%d", &T);    for(int t = 1; t <= T; t++) {        scanf("%d%d", &n, &m);        memset(next, -1, sizeof(next));        memset(head, -1, sizeof(head));        memset(in, 0, sizeof(in));        memset(instack, 0, sizeof(instack));        memset(visit, 0, sizeof(visit));        tot = 0;    idx = 0;    cnt = 0;        for(int i = 0; i < m; i++) {            int u, v;            scanf("%d%d", &u, &v);            add(u, v);        }//        for(int i = 1; i <= n; i++)//            if(!visit[i] && in[i] == 0)    tarjan(i);        for(int i = 1; i <= n; i++)             if(!visit[i])    tarjan(i);        int ans = 0;        for(int i = 1; i <= n; i++)            for(int e = head[i]; e != -1; e = next[e]) {                if (type[i] != type[edge[e]]) in[type[edge[e]]]++;            }        for (int i = 1;i <= cnt;i++)            if (in[i] == 0) ans++;//        for(int i = 1; i <= n; i++)//            if(in[i] == 0)    cnt++;        printf("Case %d: %d\n", t, ans);    }    return 0;}

 

During the competition, I only got a question... then J and B are really not strong enough... J is a bit confused. Now I understand it.

 

UESTC 2014 summer training #10 div.2

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.