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

ZMST發表於2018-12-08

A——StarCraft

題目連結:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
using namespace std;
int main()
{
    int year=2018-20;
    int n;
    while (~scanf("%d",&n))
    {
        printf("%d\n",year+n);
    }
    return 0;
}

B——Fibonacci and Counting

題目連結:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
using namespace std;
#define ll long long
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll x;
        scanf("%lld",&x);
        printf("%lld\n",x+1);
    }
    return 0;
}

I——Race Sorting(結構體排序)

題目連結:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include<vector>
#include<algorithm>
using namespace std;
#define maxn 10010
struct node{
    int num;
    char str[10];
    int k;
    int px;
}Node[maxn];
bool cmp(node a,node b)
{
    if(a.k!=b.k)
        return a.k<b.k;
    else
        return a.px<b.px;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            Node[i].k=0;
            Node[i].num=0;
            Node[i].px=0;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d is %s",&Node[i].num,Node[i].str);
            Node[i].px=i;
        }
        char s1[100];
        scanf(" %s",s1);
        int flag=0;
        char A=s1[0];
        char B,C;
        for(int i=0;i<strlen(s1);i++)//這裡種類排序一開始一直有問題,因為是三個陣列輸入的,空格可能會有影響,所以應該一個字串判斷
        {
            if(s1[i]==','&&flag==0)
            {
                B=s1[i+1];
                flag=1;
            }
            if(s1[i]==','&&flag==1)
            {
                C=s1[i+1];
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(Node[i].str[0]==A)
                Node[i].k=1;
            else if(Node[i].str[0]==B)
                Node[i].k=2;
            else
                Node[i].k=3;
        }
        sort(Node+1, Node+n+1, cmp);
        for(int i=1;i<=n;i++)
        {
            if(i==1)
                printf("%d",Node[i].num);
            else
                printf(" %d",Node[i].num);
        }
        printf("\n");
    }
    return 0;
}



J——Carrier

題目連結:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
using namespace std;
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");
        }
        else if(b<250)
        {
            printf("You require more vespene gas.\n");
        }
        else
        {
            if((6+x)>y)
            {
                printf("You must construct additional pylons.\n");
            }
            else
            {
                printf("Carrier has arrived.\n");
            }
        }
    }
    return 0;
}


K——Technology Tree

題目連結:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
using namespace std;
#define maxn 20010
struct node{
    int a,b;
}Node[maxn];
int pre[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",&Node[i].a,&Node[i].b);
        }
        for(int i=1;i<=n-1;i++)
        {
            scanf("%d",&pre[i+1]);
            Node[i+1].a+=Node[pre[i+1]].a;
            Node[i+1].b+=Node[pre[i+1]].b;
        }
        while (q--)
        {
            int x;
            scanf("%d",&x);
            int suma=Node[x].a;
            int sumb=Node[x].b;
            /*while (x!=pre[x])
            {
                suma+=Node[pre[x]].a;
                sumb+=Node[pre[x]].b;
                x=pre[x];
            }*/
            printf("%d %d\n",suma,sumb);
        }
    }
    return 0;
}


 

相關文章