1. 程式人生 > >第十五屆浙江大學寧波理工學院程式設計大賽

第十五屆浙江大學寧波理工學院程式設計大賽

題目連結

A題:簽到題 1998+n

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
const int maxn =100+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int main()
{
	int n;scanf("%d",&n);
	printf("%d\n",1998+n);
    return 0;
}

B題:

n+1

證明略

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
const int maxn =100+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		int n;scanf("%d",&n);
		printf("%d\n",n+1);
	}
    return 0;
}

D

二進位制列舉答案,然後維護一個可行的l,r,當可行的l,r包含了輸入的個數的時候,就是滿足條件的,然後從所有答案中選出最大的就行。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =20010;
const int maxm=10000;
const int mod =998244353;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int l[10],r[10];
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        int n,ans=0;
        scanf("%d",&n);
        for(int i=0;i<7;i++) scanf("%d%d",&l[i],&r[i]);
        for(int j=0;j<(1<<7);j++)
        {
            long long mi=0,mx=0;int tot=0;
            for(int i=0;i<7;i++)
            {
                if((j>>i)&1) mi+=l[i],mx+=r[i],++tot;
            }
            if(n>=mi&&n<=mx) ans=std::max(ans,tot);
        }
        printf("%d\n",ans);
    }
}

 

H

快速冪

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =20010;
const int maxm=10000;
const int mod =998244353;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
ll fpow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        ll ans=1;
        int n;scanf("%d",&n);
        while(n--)
        {
            ll a,b;scanf("%lld%lld",&a,&b);
            ans*=(fpow(2,a)-1+fpow(2,b)-1)%mod;
            ans%=mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

I

模擬就行了

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =20010;
const int maxm=10000;
const int mod =998244353;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
 
int main(){
    char f[1005];
    int T,t[1005];
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            char race[30];
            scanf("%d is %s",&t[i],race);
            f[i]=race[0];
        }
        char s[30];
        scanf("%s",s);
        int len=strlen(s);
        for(int i=0;i<len;i++)
        {
            if(s[i]=='T'||s[i]=='Z'||s[i]=='P')
            {
                for(int j=0;j<n;j++)
                {
                    if(f[j]==s[i]) printf("%d ",t[j]);
                }
            }
        }
        printf("\n");
    }
    return 0;
}

J

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =1e5+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
 
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        int a,b,x,y;scanf("%d%d%d%d",&a,&b,&x,&y);
        if(a<350)
        {
            printf("You have not enough minerals.\n");
            continue;
        }
        if(b<250)
        {
            printf("You require more vespene gas.\n");
            continue;
        }
        if(x+6>y)
        {
            printf("You must construct additional pylons.\n");
            continue;
        }
        printf("Carrier has arrived.\n");
    }
    return 0;
}

K

模擬

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =20010;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int a[maxn];
int b[maxn];
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        int n,q;scanf("%d%d",&n,&q);
        for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
        for(int i=2;i<=n;i++)
        {
            int f;scanf("%d",&f);
            a[i]+=a[f];
            b[i]+=b[f];
        }
        while(q--)
        {
            int x;scanf("%d",&x);
            printf("%d %d\n",a[x],b[x]);
        }
    }
    return 0;
}