The 12th Zhejiang University Programming Contest

Source: Internet
Author: User

The 12th Zhejiang University Programming Contest 12th Zhejiang University competition question: 3591-3599

This set of questions can be said to be difficult. I really want to do seven !!! However, unfortunately, this set of questions is really difficult! Even if I looked at the collective report, I did not have 7 questions, and there were several people who did not understand how to prove it. ......

Similarly, give a problem report URL: http://blog.sina.com.cn/s/blog_5123df350100zk1d.html


Zoj 3591 Nim: This is the deformation of Nim. It lists the given a array. B [I] is the exclusive or value of the previous I number, let's see the number of pairs in B [I] that are not the same as the two numbers. Of course, we need to add a single non-zero number.

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int a[100010], b[100010];void deal(int N ,int S,int W){    int g = S;    for (int i=0; i<N; i++) {        a[i] = g;        if( a[i] == 0 ) { a[i] = g = W; }        if( g%2 == 0 ) { g = (g>>1); }        else           { g = (g>>1) ^ W; }        if(i != 0) a[i] = a[i]^a[i-1];    }}int main(){    int t;    cin >> t;    int n,s,w;    while(t--)    {        cin >> n >> s >> w;        deal(n,s,w);        memset(b,0,sizeof(0));        sort(a,a+n);        int kk = 1;        b[0] = 1;        for(int i = 1;i < n;i++)        {            if(a[i] != a[i-1])            {                b[kk] = 1;a[kk++] = a[i];            }            else b[kk-1]++;        }        long long re = 0;        //for(int i = 0;i < kk;i++) cout << a[i] << " " << b[i] << "\n";        for(int i = 0;i < kk;i++)            re += (long long)(n - b[i]) * b[i];        re = re/2;        re += n;        if(a[0] == 0) re -= b[0];        cout << re << "\n";    }    return 0;}

Zoj 3592 flipping the board!

Zoj 3593 one person game mathematical questions
In this case, A and B are too big to be search or something. They can only be mathematics. Of course, they are GCD, Extended Euclidean, and so on. It is easy to find a general solution, it is not easy to give accurate results. The most worrying part of this type of questions is the result,

Obtain the general expression FX. After fy, when FX and FY are different, Re = ABS (FX) + ABS (FY) when there are two identical numbers, Re = min (ABS (FX), ABS (FY ));

In fact, the general solution is FX = x0 + b0t; FY = y0-a0t; here t value is very exquisite, you can determine either FX = 0, FY = 0, or FX = FY.

This is what I want to understand after reading other people's questions.

#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<iostream>using namespace std;typedef long long ll;ll gcd(ll a,ll b){    if(b==0)return a;    else return gcd(b,a%b);}ll ext_gcd(ll a,ll b,ll& x,ll& y){    ll t,ret;    if (!b)    {        x=1,y=0;        return a;    }    ret=ext_gcd(b,a%b,x,y);    t=x,x=y,y=t-a/b*y;    return ret;}ll get(ll &re,ll xx,ll yy){    if(xx*yy>=0)re=min(re,max(abs(xx),abs(yy)));    else re=min(re,abs(xx)+abs(yy));    return re;}ll deal(ll &re,ll x,ll y,ll addx,ll addy){    get(re,x,y);    get(re,x+addx,y-addy);    get(re,x-addx,y+addy);    return re;}ll get_step(ll x,ll y,ll addx,ll addy){    ll r = (long long)0x7fffffff*10000000,k,kx,ky;    k=(y-x)/(addx+addy);    deal(r,x+k*addx,y-k*addy,addx,addy);    kx=x/addx;    ky=y/addy;    deal(r,x+kx*addx,y-kx*addy,addx,addy);    deal(r,x+ky*addx,y-ky*addy,addx,addy);    return r;}int main(){    ll A,B,a,b,t,d,x,y;    cin>>t;    while(t--)    {        cin>>A>>B>>a>>b;        A=B-A;        if(!A)printf("0\n");        else        {            d=gcd(a,b);            if(A%d) printf("-1\n");            else            {                A/=d;                a/=d;                b/=d;                ext_gcd(a,b,x,y);                x=x*A;                y=y*A;                cout<<get_step(x,y,b,a)<<endl;            }        }    }    return 0;}

In zoj 3594, the number of years in the ad and the expression of a sub-account are given. The question is simple, but there is a pitfall. In the year of the AD, there is no direct saying in the 0-year period. After the 1-year BC, it is in the year of the ad !!!! Long knowledge!

Zoj 3595 two sequences (high numbers) question. I really fell down. I forgot everything I learned in my freshman year. What are infinite series, what are differential equations, and what are derivatives, there are also complicated formula transformations, such as begin. The result is very simple.

#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>using namespace std;double a0,x;int N;int main(){    while(scanf("%lf",&a0)!=EOF)    {        scanf("%d",&N);        double s=0.0;        for(int i=0;i<N;i++)        {            scanf("%lf",&x);            s+=x*x/2.0+x;        }s/=(double)N;        printf("%.8f\n",a0*exp(s));    }    return 0;}

Zoj 3596 digit number is also a rare question, but reading the solution report is a wide-searching and memory-based wide-searching. It's amazing !! I have understood the concept, but the idea is still vague. I can think of it all. It seems that my level has to be improved !!

Zoj 3597
Hit the target! Line Segment tree !!!

The line segment tree can be said to have done a lot, and it is really not difficult! It can be said that the model of this question is difficult to build! Now, I know how big is the gap between myself and the great gods. Is it possible for the great gods to kill in seconds ??

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define N 50010//Ï߶ÎÊ÷/////////////////////////int lazy[N*4],num[N*4];#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1void PushUp(int rt){    num[rt] = max(num[rt<<1],num[rt<<1|1]);}void PushDown(int rt,int m){    if(lazy[rt])    {        lazy[rt<<1] += lazy[rt];        lazy[rt<<1|1] += lazy[rt];        num[rt<<1] += lazy[rt];        num[rt<<1|1] += lazy[rt];        lazy[rt] = 0;    }}void init(int n){    for(int i = 0;i <= n*4+1;i++)    {        lazy[i] = 0;        num[i] = 0;    }}void update(int L,int R,int c,int l,int r,int rt){    if(R - L < 0) return;    if(L <= l && r <= R)    {        lazy[rt] += c;        num[rt] += c;        return;    }    PushDown(rt,r-l+1);    int m = (l+r)>>1;    if(L <= m) update(L,R,c,lson);    if(m < R) update(L,R,c,rson);    PushUp(rt);}//////////////////////////////////int shot[N];#define M 100010struct note{    int a,b;}data[M];bool cmp(const note a,const note b){    return a.a < b.a || (a.a == b.a && a.b < b.b);}int n,m,p,q,k;void deal(int i,int c){    if(shot[i])    {        int t = shot[i];        int pre = data[t].b-1;        do        {            update(max(pre+1,data[t].b),min(m,data[t].b+q-1),c,1,m,1);            pre = data[t].b+q-1;            t++;        }while(t <= k && data[t].a == data[t-1].a);    }}int main(){    int t;    cin >> t;    while(t--)    {        scanf("%d%d%d%d",&n,&m,&p,&q);        scanf("%d",&k);        memset(shot,0,sizeof(shot));        for(int i = 1;i <= k;i++) scanf("%d%d",&data[i].a,&data[i].b);        if(k == 0) {cout << "0.00\n";continue;}        sort(data+1,data+k+1,cmp);        shot[data[1].a] = 1;        for(int i = 2;i <= k;i++)            if(data[i].a != data[i-1].a) shot[data[i].a] = i;        init(m);//        for(int i = 1;i <= p;i++) deal(i,1);        int now = p;        double re = 0;        while(1)        {            re += num[1];            now++;if(now > n) break;            deal(now,1);            deal(now-p,-1);        }        printf("%.2f\n",re / (n-p+1));    }    return 0;}

Zoj 3598 spherical triangle calculates the ry. skip this step and you won't!

Zoj 3599 game, there are two games in this set !!! I really don't know what the problem is about.

However, the game against this question is really difficult !!!! Now I only know the conclusion, but I don't know why !! I gave an English website, but I really cannot understand it.

/* The zju game was killed by Gao and won't be able to find a good rule for half a day. This type of game problem can be solved in a few times. A gravel heap cannot be played by all the first hands. The number of stones taken each time is [1, F (the number of stones obtained before)], f (x)> = X; H (1) = 1, h (k + 1) = H (k) + H (M), M = min {J | f (H (j)> = H (k )}. This series shows all failures. I do not know why. */# Include <iostream> using namespace STD; long data [1000000]; Long Deal (int m, int N) {data [1] = 1; int pre = 1; for (int K = 2; k ++) {Int J; For (j = pre; j <K; j ++) if (data [J] * m> = data [k-1]) break; Pre = J; data [k] = data [k-1] + data [J]; cout <data [k] <"; // cout <n <" <k <"\ n "; if (data [k]> N) return n-k + 1;} return 0;} int main () {int t; CIN> T; while (t --) {int M, N; CIN> m> N; cout <deal (m, n) <"\ n";} return 0 ;}

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.