Network Synchronization Competition of the 2nd Space Cup Programming Competition of Nanchang University (Retrospective Supplement)

Keywords: iOS

4/9 of this contest, which was not filled in time, is now added

A ID and password

simulation

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
    string s1;
    while(cin>>s1)
    {
        for(int i=0;i<s1.size();i++)
        {
            if(s1[i]>='A'&&s1[i]<='Z')
                s1[i]+=32,cout<<s1[i];
            else
            {
                if(s1[i]>='a'&&s1[i]<='z')
                    s1[i]-=32,cout<<s1[i];
                else
                    cout<<s1[i];
            }
        }
        cout<<endl;
    }
    return 0;
}

B Take stones

Seemingly game theory, you can actually use recursion to find all the winners and losers, and then mark the query.

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
bool vis[300];
void init()
{
    int sum1=2,sum2=4,sum3=6,sum4=10,sum5=12,sum6=18;
    vis[1]=vis[3]=vis[5]=vis[7]=vis[9]=true;
    for(int i=10;i<=200;i++)
    {
        bool flag=false;
        int sum=0,j=i;
        if(j>sum1)
        {
            j-=sum1;
            if(vis[j])
                sum++;     
        }
        j=i;
        if(j>sum2)
        {
            j-=sum2;
            if(vis[j])
                sum++;     
        }
        j=i;
        if(j>sum3)
        {
            j-=sum3;
            if(vis[j])
                sum++;     
        }
        j=i;
        if(j>sum4)
        {
            j-=sum4;
            if(vis[j])
                sum++;     
        }
        j=i;
        if(j>sum5)
        {
            j-=sum5;
            if(vis[j])
                sum++;     
        }
        j=i;
        if(j>sum6)
        {
            j-=sum6;
            if(vis[j])
                sum++;     
        }
        if(sum)
            vis[i]=true;
        else
            vis[i]=false;
    }
}
int main()
{
    int n1,n2;
    init();
    while(cin>>n1>>n2)
    {
        int sum1=n1+n2;
        if(vis[sum1])
            cout<<"win\n";
        else
            cout<<"lose\n";
         
    }
    return 0;
}

C Water topic

Find the law, then how can I not think of it, unfortunately

#include<bits/stdc++.h>
using namespace std; 
int num[1011];
int main() {
    int n;
    while(~scanf("%d",&n)) {
        num[1]=0;
        num[2]=1;
        num[3]=2;
        num[4]=4;
        for(int i=5;i<1006;i++)
            num[i]=num[i-1]+i/2;
        cout<<num[n]<<endl;
    }
    return 0;
}

Notepad for D Small C

At that time when the game was crazy write hang, now use STL, AC once.STL is delicious.Use a string to represent the previous operation, a string record to indicate the completion of the operation now, and the output is sufficient.

#include<bits/stdc++.h>
using namespace std;
stack<string> p;
int main() {
    ios::sync_with_stdio(false);
    int q;
    while(cin>>q) {
        string now1;
        while(q--) {
            int t;
            cin>>t;
            if(t==1) {
                string temp;
                cin>>temp;
                p.push(now1);
                now1=now1+temp;
            }
            if(t==2) {
                int k;
                cin>>k;
                p.push(now1);
                int len1=now1.size();
                now1=now1.substr(0,len1-k);
            }
            if(t==3) {
                int k;
                cin>>k;
                cout<<now1[k-1]<<endl;
            }
            if(t==4) {
                now1=p.top();
                p.pop();
            }
        }
        while(!p.empty())
            p.pop();
    }
    return 0;
}

Confusion of F A Tang

Large number modulus, simulation is sufficient

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string N;
        long long M,sum=0,S=0;
        cin>>N>>M;
        for(int i=0;i<N.size();i++)
        {
            sum=S*10+N[i]-'0';
            S=sum%M;
        }
        long long sum1=0;
        for(int i=2;i<=sqrt(S);i++)
        {
            if(S%i==0)
            {
                while(S%i==0)
                    S/=i;
                sum1++;
            }
        }
        if(S!=1)
            sum1++;
        cout<<sum1<<endl;
    }
    return 0;
}

Array of G'a Tang

This, I think it's a backpack, but the number of elements in both arrays is any number, just need to satisfy the same average number, then DFS, timeout.Look at the AC code is GCD in general, I hope that a big guy can explain it.

#include<bits/stdc++.h>
using namespace std;
const int MAXN=40;
int num[MAXN];
int n;
int sum1=0;
int main() {
    int t;
    while(~scanf("%d",&t)) {
        while(t--) {
            sum1=0;
            scanf("%d",&n);
            for(int i=0;i<n;i++)
                scanf("%d",&num[i]),sum1+=num[i];
            if(__gcd(sum1,n)!=1)
                puts("yes");
            else
                puts("no");
        }
    }
    return 0;
}

Array of H small q

At first thought it was a recursive formula, similar to Fibonacci, but it was actually a circular sequence of numbers, the first occurrence of which was related to binary numbers.Its value is the number of 1 in the binary representation, and the first number of items that occur is

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

Clock for I q

There's nothing to say about simulation, paste code

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
    long long begin1,end1;
    while(cin>>begin1>>end1)
    {
        long long hh=0,mm=0,ss=0;
        long long time1=end1-begin1;
        hh=time1/3600;
        mm=(time1-hh*3600)/60;
        ss=(time1-hh*3600-mm*60);
        if(hh>=10)
            cout<<hh<<":";
        else
            cout<<"0"<<hh<<":";
        if(mm>=10)
            cout<<mm<<":";
        else
            cout<<"0"<<mm<<":";
        if(ss>=10)
            cout<<ss;
        else
            cout<<"0"<<ss;
        cout<<endl;
    }
    return 0;
}

 

50 original articles published. 1. Visits 6842
Private letter follow

Posted by drucifer on Tue, 21 Jan 2020 20:38:23 -0800