2018CCPC吉林赛区(重现赛)- 感谢北华大学 部分题解

A The Fool

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1346 Accepted Submission(s): 535

Problem Description
The Fool is numbered 0 – the number of unlimited potential –and therefore does not have a specific place in the sequence of the Tarot cards. The Fool can be placed either at the beginning of the Major Arcana or at the end. The Major Arcana is often considered as the Fool’s journey through life and as such, he is
ever present and therefore needs no number.

Given n ∈ N+, print the parity of
∑i=1N [ni],

where [x] = max a (a∈Z,a≤x)

Input
The first line of the input contains one integer T ≤ 100, denoting the number of testcases. Then T testcases follow.
In each of the T testcases, there is a positive number n ≤ 109.

Output
For each testcase, print a single line starting with “Case i : ”(i indicates the case number) and then “even” or “odd”, separated with a single space.

Sample Input

3
1
10000
100000000

Sample Output

Case 1: odd
Case 2: even
Case 3: even

直接走暴力不能通过,
找一下规律发现1 2 3都是 odd 4 -8 都是even 9-15都是odd,所以根号后取余2即可。
Code:

#include 
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    int cas=1;
    while(t--)
    {
        int n,sum=0;
        scanf("%d",&n);
        sum=sqrt(n);
        if(sum%2==1)printf("Case %d: odd\n",cas++);
        else printf("Case %d: even\n",cas++);
    }
    return 0;
}

B The World

Problem Description
The World can indicate world travel, particularly on a large scale. You may be lucky enough to be embarking on a six-month overseas trip, or are working, studying or living overseas for an extended period of time. Similarly, this card reinforces Universal understanding and global awareness, and you will have a new appreciation for people and cultures from across the world.

Across the world there are various time zones, leading to time differences. Here you are informed of several famous capitals and their corresponding time zones.

Beijing - China - UTC + 8 (China Standard Time)

Washington - United States - UTC - 5 (Eastern Standard Time)

London - United Kingdom - UTC (Greenwich Mean Time)

Moscow - Russia - UTC + 3 (Moscow Time)

Given the local time of a city, you are expected to calculate the date and local time of another specific city among the above capitals.

Input
The first line of input contains a single integer T ≤ 1000 indicating the number of testcases.
Each testcase consists of three lines. The first line is in the form of “hour:minute AM/PM” (1 ≤ hour ≤ 12, 00 ≤ minute ≤ 59) indicating the local time. Next two lines contain two strings s1, s2. s1 is the name of city corresponding to the given time, while s2 indicates the city you are expected to calculate the local time.

Output
For each testcase, begin with “Case i:”, where i indicate the case number, and then output a single line in the following format“Yesterday/Today/Tomorrow hour:minute AM/PM”, separated by spaces. The first word describes the corresponding date.

Sample Input

2
12:00 AM
London
Moscow
4:00 PM
London
Beijing

Sample Output

Case 1: Today 3:00 AM
Case 2: Tomorrow 12:00 AM

一道时差题,减去开始位子的时差,加上后来位子的时差即可
Code:

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;

int main()
{
    int t,s,f,cas=1;
    string m;
    string s1,s2;
    cin>>t;
    while(t--)
    {
        scanf("%d:%d",&s,&f);
        cin>>m>>s1>>s2;
        if(m[0]=='A'&&s==12)
            s=0;
        else if(m[0]=='P'&&s!=12)
            s+=12;
        if(s1=="Moscow")
            s-=3;
        else if(s1=="Beijing")
            s-=8;
        else if(s1=="Washington")
            s+=5;
        if(s2=="Moscow")
            s+=3;
        else if(s2=="Beijing")
            s+=8;
        else if(s2=="Washington")
            s-=5;
        printf("Case %d: ",cas++);
        if(s<0)
        {
            printf("Yesterday ");
            s+=24;
        }
        else if(s>=24)
        {
            printf("Tomorrow ");
            s-=24;
        }
        else
            printf("Today ");
        if(s==0)
            printf("12:%02d AM\n",f);
        else if(s>=1&&s<12)
            printf("%d:%02d AM\n",s,f);
        else if(s==12)
            printf("12:%02d PM\n",f);
        else
            printf("%d:%02d PM\n",s-12,f);
    }
    return 0;
}

C Justice

Problem Description
Put simply, the Justice card represents justice, fairness, truth and the law. You are being called to account for your actions and will be judged accordingly. If you have acted in a way that is in alignment with your Higher Self and for the greater good of others, you have nothing to worry about. However, if you have
acted in a way that is out of alignment, you will be called out and required to own up to your actions. If this has you shaking in your boots, know that the Justice card isn’t as black and white as you may think.

On the table there are n weights. On the body of the i-th weight carved a positive integer ki , indicating that its weight is 12ki gram. Is it possible to divide the n weights into two groups and make sure that the sum of the weights in each group is greater or equal to 12 gram? That’s on your call. And please tell us how if possible.

Input
In the first line of the input there is a positive integer T (1 ≤ T ≤ 2000), indicating there are T testcases.
In the first line of each of the T testcases, there is a positive integer n (1 ≤ n ≤ 105, ∑n ≤ 7 × 105), indicating there are n weights on the table.
In the next line, there are n integers ki (1 ≤ ki ≤ 109), indicating the number carved on each weight.

Output
For each testcase, first print Case i: ANSWER in one line, i indicating the case number starting from 1 and ANSWER should be either YES or NO, indicating whether or not it is possible to divide the weights. Pay attention to the space between : and ANSWER.
If it’s possible, you should continue to output the dividing solution by print a 0/1 string of length n in the next line. The i-th character in the string indicating whether you choose to put the i-th weight in group 0 or group 1.

Sample Input

3
3
2 2 2
3
2 2 1
2
1 1

Sample Output

Case 1: NO
Case 2: YES
001
Case 3: YES
10

题意就是要和等于1/2,然后符合条件的最小数用二进制输出 001就代表用第三个数字。
那也就是说如果是1 一个就够了 2要两个 3要四个,4要八个。统计个数即可。
Code:

#include
using namespace std;
int vis[100010];
struct node
{
    int id;
    int x;
} a[100010];
bool cmp(node xx,node yy)
{
    return xx.xn-i+1)
            {
                flag=0;
                break;
            }
            if(num1)
            {
                num1--;
                vis[a[i].id]=1;
            }
            else
            {
                num2--;
            }
            if(!num1 && !num2)
                break;
        }
        if(!flag|| num1 || num2)
            printf("NO\n");
        else
        {
            printf("YES\n");
            for(int i=0; i

Strength

Problem Description
Strength gives you the confidence within yourself to overcome any fears, challenges or doubts. Feel the fear and do it anyway! If you have been going through a rough time and feel burnt out or stressed, the Strength card encourages you to find the strength within yourself and keep going. You have got what it takes to see this situation through to its eventual end. You might also feel compelled to hold space for someone else who is going through a difficult period and needs your strength and support.

Alice and Bob are playing “Yu-Gi-Oh!”, a famous turn-based trading card game, in which two players perform their turns alternatively. After several turns, Alice and Bob have many monsters respectively.
Alice has n and Bob has m monsters under their own control. Each monster’s strength is measured by a non-negative integer si . To be specific, the larger si is, the more power the monster has.
During each turn, for every single monster under control, the player can give a command to it at most once, driving it to battle with an enemy monster (given that opposite player has no monsters as a shield, the monster can directly attack him).
Additionally, the process of the battle is also quite simple. When two monsters battle with each other, the stronger one (i.e. the one with larger si) will overwhelm the other and destroy it and the winner’s strength will remain unchanged. Meanwhile, the difference of their strength will produce equivalent damage to the player who loses the battle. If the player is directly attacked by a monster, he will suffer from the damage equal to the monster’s strength. Notice that when two monsters have the same strength, both of them will vanish and no damage will be dealt.
Right now it is Alice’s turn to play, having known the strength of all monsters, she wants to calculate the maximal damage she can deal towards Bob in one turn. Unfortunately, Bob has great foresight and is well-prepared for the upcoming attack. Bob has converted several of his monsters into defense position,
in which even if the monster is destroyed, he wouldn’t get any damage.
Now you are informed of the strength of all the monsters and whether it is in defense position for each Bob’s monster, you are expected to figure out the maximal damage that could be dealt in this turn.

Input
The first line contains a single integer T ≤ 20 indicating the number of test cases.
For each test case, the first line includes two integer 0 ≤ n, m ≤ 100000, representing the number of monsters owned by Alice and Bob.
In next three lines, the first two lines include n and m integers 0 ≤ si ≤ 109 indicating the strength of the i-th monster, separated by spaces. The last line contains m integers 0 or 1 indicating the position of Bob’s i-th monsters.In other words, 0 represents the normal position and 1 represents the defense position.

Output
For the ith test, output a single line in beginning of “Case i:”, followed by an integer indicating the answer, separated by a single space.

Sample Input

2
4 2
10 10 10 20
5 15
0 1
4 2
10 10 10 20
5 25
0 1

Sample Output

Case 1: 25
Case 2: 15

题意
游戏王的机制,打攻击形态的怪兽如果超出攻击直接对人造成伤害,防御形态不会对人造成伤害,场上没有怪兽了可以直接对人造成伤害,求造成伤害的最大值。
一个贪心算法,算出直接最大攻击的怪兽攻击最低攻击的怪兽,还有用最大攻击击杀防御怪兽之后直接打脸两种情况。
Code:

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int T,cas=1;
    int a[100005],b[100005],gon[100005],fan[100005],f;
    int vis[100005];
    scanf("%d",&T);
    while(T--)
    {
        memset(vis,0,sizeof(vis));
        int xg=0,xf=0;
        int n,m;
        scanf("%d %d",&n,&m);
        for(int i=0; i>a[i];
        for(int i=0; i>b[i];
        for(int i=0; i>f;
            if(f)
                fan[xf++]=b[i];
            else
                gon[xg++]=b[i];
        }
        sort(a,a+n,cmp);
        sort(gon,gon+xg);
        sort(fan,fan+xf,cmp);
        int ans=-1,agon,bfan,bgon,sum;
        agon=n-1;
        bfan=xf-1;
        while(agon>=0&&bfan>=0)
        {
            if(a[agon]>=fan[bfan])
            {
                vis[agon]=1;
                agon--;
                bfan--;
            }
            else
            {
                agon--;
            }
        }
        if(bfan==-1)
        {
            agon=0;
            bgon=xg-1;
            sum=0;
            while(agon=0)
            {
                if(vis[agon])
                {
                    agon++;
                    continue;
                }
                if(a[agon]>=gon[bgon])
                {
                    sum+=a[agon]-gon[bgon];
                    agon++;
                    bgon--;
                }
                else
                    break;
            }
            if(bgon==-1)
            {
                while(agon= gon[bgon])
            {
                sum+=a[agon]-gon[bgon];
                agon++;
                bgon++;
            }
            else
                break;
        }
        int abs=0;
        if(bgon != xg)
        {
            ans = max(ans, sum);
        }
        else
        {
            int i=n-1;
            while(i>=agon&&bfan>=0)
            {
                if(a[i]>=fan[bfan])
                {
                    i--;
                    bfan--;
                }
                else
                {
                    abs+=a[i];
                    i--;
                }
            }
            if(bfan==-1)
            {
                sum+=abs;
                if(i!=agon)
                {
                    while(i>=agon)
                    {
                        sum+=a[i];
                        i--;
                    }
                }
            }
            ans = max(ans,sum);
        }
        //printf("Case %d: %d\n",cas++,ans);

        printf("Case %d: %d\n",cas++,ans);
    }
    return 0;
}

你可能感兴趣的:(暑假训练)