2017 CCPC final --- 题解

A - Dogs and Cages

题意:

Jerry likes dogs. He has NN dogs numbered 0,1,...,N−10,1,...,N−1. He also has NN cages numbered 0,1,...,N−10,1,...,N−1. Everyday he takes all his dogs out and walks them outside. When he is back home, as dogs can’t recognize the numbers, each dog just randomly selects a cage and enters it. Each cage can hold only one dog. 
One day, Jerry noticed that some dogs were in the cage with the same number of themselves while others were not. Jerry would like to know what’s the expected number of dogs that are NOT in the cage with the same number of themselves.

Input

The first line of the input gives the number of test cases, TT. TTtest cases follow. 
Each test case contains only one number NN, indicating the number of dogs and cages. 
1≤T≤1051≤T≤105 
1≤N≤1051≤N≤105

Output

For each test case, output one line containing “Case #x: y”, where xxis the test case number (starting from 1) and yy is the expected number of dogs that are NOT in the cage with the same number of itself. 
yy will be considered correct if it is within an absolute or relative error of 10−610−6 of the correct answer.

思路:写写公式,简单一推,,就是n-1。。可怕的是读题读的是NOT、但是写公式莫名其妙写的是yes的。。。。WA了一发,,,

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        printf("%d\n",n-1);
    }
}

C - Rich Game

 题意:

One day, God Sheep would like to play badminton but he can’t find an opponent. So he request Mr. Panda to play with him. He said: “Each time I win one point, I’ll pay you X dollars. For each time I lose one point, you should give me Y dollars back.”
God Sheep is going to play K sets of badminton games. For each set, anyone who wins at least 11 points and leads by at least 2 points will win this set. In other words, normally anyone who wins 11 points first will win the set. In case of deuce (E.g. 10 points to 10 points), it’s necessary to lead by 2 points to win the set.
Mr. Panda is really good at badminton so he could make each point win or lose at his will. But he has no money at the beginning. He need to earn money by losing points and using the money to win points.
Mr. Panda cannot owe God Sheep money as god never borrowed money. What’s the maximal number of sets can Mr. Panda win if he plays cleverly?

Input

The first line of the input gives the number of test cases, T. T test cases follow.
Each test case contains 3 numbers in one line, X, Y , K, the number of dollars earned by losing a point, the number of dollars paid by winning a point, the number of sets God Sheep is going to play.
1≤T≤105.
1≤X,Y,K≤1000.

Output

For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximal number of sets Mr. Panda could win.

思路:一个模拟。。但是当x>y的时候,第一局的时候就可以一输一赢,攒无穷多的钱了,既可以每局都赢了。。

代码:

#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int T,x,y,k,p,pp,ans,z,t;
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        ++t;
        scanf("%d%d%d",&x,&y,&k);
        p=11*x;
        pp=9*x-11*y;
        if(x>y)
        {
            printf("Case #%d: %d\n",t,k);
            continue;
        }
        pp=-pp;
        z=0;
        ans=0;
        for(int i=1;i<=k;i++)
        {
            if(ans>=pp) {ans-=pp;z++;}
            else ans+=p;
        }
        printf("Case #%d: %d\n",t,z);
    }
}

E - Evil Forest

 题意:

The Bear, king of the forest, loves painting very much. His masterpiece – “Back in time” is very famous around all over the forest. Recently he wants to hold a series painting competition to select those animals who are good at painting as well. So the Bear appoints his minister Tiger to help him prepare the painting competitions. 
Tiger owns a stationery factory which produces sketchpad, so he wants to let all the competitions use the sketchpads produced by his factory privately. The Bear plans to hold NN painting competitions, and informs Tiger of the number of competitors who are ready for each competition. One competitor needs only one sktechpad in one competition. For each competition, at least 10% extra sketchpads are required as backup just in case. 
The Tiger assigns you, his loyal subordinate to calculate the minimum number of sketchpads produced 
by his factory.

Input

The first line of the input gives the number of test cases, TT. TTtest cases follow. 
For each test case, the first line contains an integer NN, where NNis the number of competitions. The next line contains NN integers a1,a2,...,aNa1,a2,...,aN representing the number of competitors in each competition. 
1≤T≤1001≤T≤100 
1≤N≤10001≤N≤1000 
1≤ai≤1001≤ai≤100

Output

For each test case, output one line containing “Case #x: y”, where xxis the test case number (starting from 1) and yy is the minimum number of sketchpads that should be produced by Tiger’s factory.

思路:简单水题,加加,处理处理就行

代码:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int T;
    scanf("%d",&T);
    int cas=1;
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            ans+=x;
            double t=x*0.1;
            if(t!=x/10)
                ans+=x/10+1;
            else
                ans+=x/10;
        }
        printf("Case #%d: %d\n",cas++,ans);
    }
    return 0;
}

K - Knightmare

题意:

A knight jumps around an infinite chessboard. The chessboard is an unexplored territory. In the spirit of explorers, whoever stands on a square for the first time claims the ownership of this square. The knight initially owns the square he stands, and jumps NN times before he gets bored. 
Recall that a knight can jump in 8 directions. Each direction consists of two squares forward and then one squaure sidways. 


After NN jumps, how many squares can possibly be claimed as territory of the knight? As NN can be really large, this becomes a nightmare to the knight who is not very good at math. Can you help to answer this question?

Input

The first line of the input gives the number of test cases, TT. TTtest cases follow. 
Each test case contains only one number NN, indicating how many times the knight jumps. 
1≤T≤1051≤T≤105 
0≤N≤1090≤N≤109

Output

For each test case, output one line containing “Case #x: y”, where xxis the test case number (starting from 1) and yy is the number of squares that can possibly be claimed by the knight.

思路:打表,找规律。。发现后面的数的差的差都是28.。推公式,转java,或者用unsigned long long,long long 是不行的。。会爆。

代码:

#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int T,t;
unsigned long long x;
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        ++t;
        scanf("%I64u",&x);
        printf("Case #%d: ",t);
        if(x==0)
            printf("1\n");
        else if(x==1)
            printf("9\n");
            else if(x==2)
                printf("41\n");
            else if(x==3)
                printf("109\n");
            else if(x==4)
                printf("205\n");
            else if(x==5)
                printf("325\n");
            else if(x==6)
                printf("473\n");
            else
            {
                printf("%I64u\n",473+8*(x-6)+14*(x*x-x-30));
            }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值