2019 interesting program design competition for freshmen of Xiangtan University (recurrence competition) (review and supplement)

Posted by Spartan 117 on Tue, 21 Jan 2020 14:24:27 +0100

A 15 and 20

Portal

Simulation direct up

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        int a1,b1,c1;
        scanf("%d%d%d",&a1,&b1,&c1);
        int a2,b2,c2;
        scanf("%d%d%d",&a2,&b2,&c2);
        int sum=b1+c1+b2+c2;
        if(sum==a1) {
            if(sum==a2)
                puts("continue");
            else
                puts("alice");
        } else {
            if(sum==a2)
                puts("bob");
            else
                puts("continue");
        }
    }
    return 0;
}

B display

Portal

Direct simulation, pay attention to details

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        int c,r,n;
        scanf("%d%d%d",&c,&r,&n);
        while(n--) {
            int a,b;
            scanf("%d%d",&a,&b);
            int c1=c/a,c2=r/b;
            int sum1=c1*a,sum2=c1*b;
            int sum3=c2*a,sum4=c2*b;
            if(sum1<=c&&sum2<=r) {
                if(sum3<=c&&sum4<=r) {
                    if(sum1*sum2>=sum3*sum4)
                        printf("%d %d\n",sum1,sum2);
                    else
                        printf("%d %d\n",sum3,sum4);
                } else
                    printf("%d %d\n",sum1,sum2);
            } else {
                if(sum3<=c&&sum4<=r)
                    printf("%d %d\n",sum3,sum4);
                else
                    printf("%d %d\n",0,0);
            }
        }
        if(t!=0)
            printf("\n");
    }
    return 0;
}

C Sequence

Portal

The recurrence formula isTake three as cycle section

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        long long a1,a2,k;
        scanf("%lld%lld%lld",&a1,&a2,&k);
        long long a3=a2-a1;
        if(k<=3) {
            if(k==1) {
                printf("%lld\n",a1);
            }
            if(k==2) {
                printf("%lld\n",a2);
            }
            if(k==3) {
                printf("%lld\n",a3);
            }
        } else {
            long long z2=k%3;
            if(z2==1) {
                long long z1=(k-1)/3;
                if(z1%2==0)
                    printf("%lld\n",a1);
                else
                    printf("%lld\n",-a1);
            }
            if(z2==2) {
                long long z1=(k-2)/3;
                if(z1%2==0)
                    printf("%lld\n",a2);
                else
                    printf("%lld\n",-a2);
            }
            if(z2==0) {
                long long z1=(k-3)/3;
                if(z1%2==0)
                    printf("%lld\n",a3);
                else
                    printf("%lld\n",-a3);
            }
        }
    }
    return 0;
}

D Carrot

Portal

Judge the case of n==2, and then judge the parity of n

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        long long n;
        scanf("%lld",&n);
        if(n==2)
            puts("2");
        else {
            if(n%2==0)
                puts("0");
            else
                puts("1");
        }
    }
    return 0;
}

E Cuboid

Portal

Enumeration of violence

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        long long sum1=(b+c)*(b+c)+a*a;
        long long sum2=(a+c)*(a+c)+b*b;
        long long sum3=(a+b)*(a+b)+c*c;
        printf("%lld\n",min(sum1,min(sum2,sum3)));
    }
    return 0;
}

F Order

Portal

In consideration of greed, when m pieces are produced every day until they are less than m at last, the answer can be obtained by adding simulation results. It's too late for the first two posts. It's a pity

#include<bits/stdc++.h>
using namespace std;
vector<int> p;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        p.clear();
        int n,m;
        scanf("%d%d",&n,&m);
        p.resize(n);
        for(int i=0;i<n;i++)
            scanf("%d",&p[i]);
        int start=1,sum=0;
        for(int i=0;i<n;){
            int temp=m; 
            while(i<n&&temp>=p[i]) {
                temp-=p[i];
                i++;
                sum+=start;
            }
            start++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

G Ball

Portal

The game didn't write out. After the game, the question was found to be the conclusion. There was no one left. It was a pity that I kept pushing for the last half hour

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        long long n,m;
        scanf("%lld%lld",&n,&m);
        long long d=__gcd(n,m);
        n/=d,m/=d;
        if(abs(n-m)%2==1)
            puts("-1");
        else
            printf("%lld\n",n+m-2);
    }
    return 0;
}

H strange palindrome substring

Portal

It will not be repaired.

I Line

Portal

If the rectangle is divided into two parts, then this point must go back to the midpoint on x and y of the rectangle. This point was unexpected at the time of the game, but it's a pity. So we know P point and another point, which we temporarily call the midpoint. Two points determine a straight line, judge whether there is a straight line and simplify it.

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        long long x1,y1,x2,y2,x3,y3;
        cin>>x1>>y1>>x2>>y2>>x3>>y3;
        long long x4=(x1+x2),y4=y1+y2;
        x3*=2,y3*=2;
        long long a=y3-y4;
        long long b=x4-x3;
        long long c=-(a*x3+b*y3);
        c/=2;
        if(a==0){
            long long k=__gcd(b,c);
            b/=k,c/=k;
            if(b<0)b/=-1,c/=-1;
            cout<<a<<' '<<b<<' '<<c<<endl;
            continue;
        }
        long long k=__gcd(a,__gcd(b,c));
        a/=k,b/=k,c/=k;
        if(a<0)
            a/=-1,b/=-1,c/=-1;
        printf("%lld %lld %lld\n",a,b,c);
    }
    return 0;
}

J Pythagorean theorem

Portal

Thanks to Google and Baidu search engine, we successfully found the construction method of Pythagorean number in the competition, which can be divided into odd number and even number

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        long long a;
        scanf("%lld",&a);
        if(a%2==1) {
            long long z=(a-1)/2;
            printf("%lld %lld\n",2*z*z+2*z,2*z*z+2*z+1);
        } else {
            if(a==4)
                printf("3 5\n");
            else
                printf("%lld %lld\n",(a/2)*(a/2)-1,(a/2)*(a/2)+1);
        }
    }
    return 0;
}

K BAD String

Portal

It will not be repaired.

Published 43 original articles, won praise 1, visited 6707
Private letter follow

Topics: less Google