训练赛20180219

A - Automatic Judge

HDU - 6023

Welcome to HDU to take part in the second CCPC girls’ competition!

A new automatic judge system is used for this competition. During the five-hour contest time, you can submit your code to the system, then the judge will reply you. Here is a list of the judge's replies and their meaning:

1. Accepted(AC): Yes, your program is correct. You did a good job!

2. PresentationError(PE) : Your program's output format is not exactly the same as required by the problem, although the output is correct. This usually means the existence of omitted or extra blank characters (white spaces, tab characters and/or new line characters) between any two non-blank characters, and/or blank lines (a line consisting of only blank characters) between any two non-blank lines. Trailing blank characters at the end of each line and trailing blank lines at the of output are not considered format errors. Check the output for spaces, blank lines, etc. against the problem's output specification.

3. WrongAnswer(WA) : Correct solution not reached for the inputs. The inputs and outputs that we use to test the programs are not public (it is recomendable to get accustomed to a true contest dynamic :-)

4. RuntimeError(RE) : Your program failed during the execution and you will receive the hints for the reasons.

5. TimeLimitExceeded(TLE) : Your program tried to run during too much time.

6. MemoryLimitExceeded(MLE): Your program tried to use more memory than the judge default settings.

7. OutputLimitExceeded(OLE): Your program tried to write too much information. This usually occurs if it goes into a infinite loop.

8. CompilationError(CE)
: The compiler fails to compile your program. Warning messages are not considered errors. Click on the judge's reply to see the warning and error messages produced by the compiler.

For each submission, if it is the first time that the judge returns ``AC'' on this problem, then it means you have passed this problem, and the current time will be added to the penalty of your team. In addition, every time you pass a problem, each unsuccessful try for that problem before is counted as 20 minutes penalty, it should also be added to the penalty of your team.
Now given the number of problems in the contest and the submission records of a team. Please write a program to calculate the number of problems the team passed and their penalty.
Input The first line of the input contains an integer T(1T20), denoting the number of test cases.
In each test case, there are two integers n(1n13) and m(1m100) in the first line, denoting the number of problems and the number of submissions of a team. Problems are labeled by 1001, 1002, ..., 1000+n.
In the following m lines, each line contains an integer x(1001x1000+n) and two strings t(00:00t05:00) and s, denoting the team submits problem x at time t, and the result is s. t is in the format of HH:MM, while s is in the set \{AC, PE, WA, RE, TLE, MLE, OLE\}. The team is so cautious that they never submit a CE code. It is guaranteed that all the t in the input is in ascending order and every t is unique.
Output For each test case, print a single line containing two integers A and B, denoting the number of problems the team passed and the penalty.
Sample Input
1
3 5
1002 00:02 AC
1003 00:05 WA
1003 00:06 WA
1003 00:07 AC
1002 04:59 AC
Sample Output
2 49
#include
using namespace std;
bool vis[25];
int cot[25];
int main()
{
    int t,n,m;
    cin>>t;
    while(t--&&cin>>n>>m)
    {
        memset(vis,0,sizeof(vis));
        memset(cot,0,sizeof(cot));
        int tol = 0,ans=0;
        while(m--)
        {
            int a,b,c;
            string s;
            scanf("%d %02d:%02d",&a,&b,&c);
            cin>>s;
            a-=1000;
            if(vis[a]) continue;
            if(s=="AC")
            {
                tol++;
                vis[a] = 1;
                ans += cot[a]*20 + b*60 + c;
            }
            else cot[a]++;
        }
        cout<

B - Coprime Sequence

HDU - 6025

Do you know what is called ``Coprime Sequence''? That is a sequence consists of n

positive integers, and the GCD (Greatest Common Divisor) of them is equal to 1. ``Coprime Sequence'' is easy to find because of its restriction. But we can try to maximize the GCD of these integers by removing exactly one integer. Now given a sequence, please maximize the GCD of its elements.
Input The first line of the input contains an integer T(1T10), denoting the number of test cases. In each test case, there is an integer n(3n100000) in the first line, denoting the number of integers in the sequence. Then the following line consists of n integers a1,a2,...,an(1ai109), denoting the elements in the sequence. Output For each test case, print a single line containing a single integer, denoting the maximum GCD. Sample Input
3
3
1 1 1
5
2 2 2 3 2
4
1 2 4 8
Sample Output
1
2
2
#include
using namespace std;
#define N 100005
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
long long a[N],l[N],r[N];
int main()
{
    long long t,n;
    cin>>t;
    while(t--&&cin>>n)
    {
        for (int i=0; i>a[i];
        l[0]=a[0];
        r[n-1]=a[n-1];
        for(int i=1; i=0; i--)
            r[i]=gcd(r[i+1],a[i]);
        int ans=max(l[n-2],r[1]);
        for(int i=1; i


C - Graph Theory

HDU - 6029

Little Q loves playing with different kinds of graphs very much. One day he thought about an interesting category of graphs called ``Cool Graph'', which are generated in the following way:
Let the set of vertices be {1, 2, 3, ..., n}. You have to consider every vertice from left to right (i.e. from vertice 2 to n). At vertice i, you must make one of the following two decisions:
(1) Add edges between this vertex and all the previous vertices (i.e. from vertex 1 to i1

).
(2) Not add any edge between this vertex and any of the previous vertices.
In the mathematical discipline of graph theory, a matching in a graph is a set of edges without common vertices. A perfect matching is a matching that each vertice is covered by an edge in the set.
Now Little Q is interested in checking whether a ''Cool Graph'' has perfect matching. Please write a program to help him.
Input The first line of the input contains an integer T(1T50), denoting the number of test cases.
In each test case, there is an integer n(2n100000) in the first line, denoting the number of vertices of the graph.
The following line contains n1 integers a2,a3,...,an(1ai2), denoting the decision on each vertice. Output For each test case, output a string in the first line. If the graph has perfect matching, output ''Yes'', otherwise output ''No''.
Sample Input
3
2
1
2
2
4
1 1 2
Sample Output
Yes
No
No
#include
using namespace std;
int main()
{
    int t,n,ans,x;
    cin>>t;
    while(t--&&cin>>n)
    {
        int cnt=1;
        for(int i=0; i>x;
            if(cnt==0) cnt++;
            else
            {
                if(x==1) cnt--;
                else cnt++;
            }
        }
        if(n%2)       //奇数个点
            printf("No\n");
        else
            printf("%s\n",cnt!=0?"No":"Yes");
    }
}


D - Easy Summation

HDU - 6027
You are encountered with a traditional problem concerning the sums of powers.
Given two integers n and k. Let f(i)=ik, please evaluate the sum f(1)+f(2)+...+f(n). The problem is simple as it looks, apart from the value of n in this question is quite large.
Can you figure the answer out? Since the answer may be too large, please output the answer modulo 109+7
.
Input The first line of the input contains an integer T(1T20), denoting the number of test cases.
Each of the following T lines contains two integers n(1n10000) and k(0k5).
Output For each test case, print a single line containing an integer modulo 109+7. Sample Input
3
2 5
4 2
4 1
Sample Output
33
30
10
#include
using namespace std;
#define N 1000000007
int main()
{
    long long t,n,m,ans,k;
    cin>>t;
    while(cin>>n>>m)
    {
        ans=0;
        for(long long i=1; i<=n; i++)
        {
             k=1;
            for(int j=0; jN)
                    k=k%N;
            }
             ans+=k;
        }
        cout<


E - 小羽涂色

UESTC - 1826

平面上有无限个格子,排成一行。小羽将格子由1

开始从左到右依次编号。

小羽将所有编号为奇数的格子涂为红色,编号为偶数的格子涂为绿色。

试问你是否存在一个区间[L,R]

(1<=L<=R),使得该区间内红色格子的数量为 r,绿色格子的数量为 g

.

Input

一行两个整数r,g(0<=r,g<=100)

,分别代表红色格子和绿色格子的数量。

Output

如果存在一个区间[L,R]

满足红色格子的数量为 r且绿色格子的数量为 g,请输出“ YES”;否则,请输出“ NO

”.

Sample Input
2 33 1
Sample Output
YESNO
Hint

样例1

,取 L=2R=6,区间 [2,6]35号格子为红色, 246号格子为绿色。满足红色格子数量为 2,绿色格子数量为 3的条件,故输出“ YES

”.

样例2

,不存在一段区间使得红色格子数量为 3,绿色格子数量为 1,故输出“ NO”.
#include
using namespace std;
int main()
{
    int r,g;
    while(cin>>r>>g)
    {
        if(abs(r-g)>=2||(r==0&&g==0))
              cout<<"NO\n";
        else
            cout<<"YES\n";
    }
}

F - 座位分配

UESTC - 1827

如图所示,电子科大食堂的桌子均为四人桌。有N

对异性情侣, P名单身男性, Q名单身女性需要在食堂里就餐,每个人需要占据一个座位。一对情侣必须坐在同一张桌上,且不能容忍同一桌自己对象旁边的座位或对面的座位出现其他异性。单身男性和单身女性则没有这个要求,问至少需要多少张桌子来满足这 2N+P+Q

人的就餐要求。

Input

一行,三个整数N,P,Q(0<=N<=1000,0<=P<=10000,0<=Q<=100)

,分别代表异性情侣、单身男性和单身女性的数量。

Output

一行,输出能够满足所有人就餐要求的最少桌子数。

Sample Input
1 1 12 3 2
Sample Output
13
Hint

样例1

1

张桌子可以满足所有人的就餐需求。左图为一种合法的安排方式,右图的安排方式则不合法。

样例2

,一共有 22+3+2=9人需要用餐, 2张桌子显然无法满足所有人的就餐需求, 3

张桌子则可以,下图为一种合法的安排方式。

#include
using namespace std;
int main()
{
    int n,p,q,ans;
    while(cin>>n>>p>>q)
    {
        ans=0;
        int temp=q+p;
        if(temp%4)
        {
            if(temp%4>2)            
            {
                ans+=temp/4;      
                ans++;              //单身人士桌子数
                ans+=n/2;
                if(n%2)             
                    ans++;          //情侣桌子数
            }
            else
            {
                ans+=temp/4;
                ans++;               //单身人士桌子数
                ans+=n/2;
                if(temp%4==2&&(p==0||q==0)&&n%2)
                    ans++;           //情侣桌子数
            }
        }
        else
        {
            ans+=temp/4;
            ans+=n/2;
            if(n%2)
                ans++;
        }
        cout<

G - 马里奥饼店

UESTC - 1828

你需要到马里奥饼店购买N

个价值为 K

元的面包。

你有一张9

折卡,只需要支付面包价钱的 90

%即可得到该面包。

但是,马里奥的9

折算法只精确到元,如果出现了小数,则采取四舍五入的方式进行收费。

比如说你买3

5元的面包,共计 15元,打 9折后应收费 13.5元,四舍五入收取 14

元。

如果你买2

3元的面包,共计 6元,打 9折后应收费 5.4元,四舍五入收取 5

元。

你可以分多次去购买你所需要的N

个面包,使你的总花费最小。

请问这个最小花费是多少?

Input

一行两个整数N,K(1<=N,K<=10)

.

Output

一行,代表使用9

折卡购买 N个价值为 K

元的面包的最小花费。

Sample Input
1 12 6
Sample Output
110
Hint

样例1

,你只有 1种购买方式,买下这个面包, 1元打 9折后应收费 0.9元,四舍五入收取 1

元。

样例2

,你有2种购买方式:’第一种是一次性买两个面包,共计12元,打9折后应收费10.8元,四舍五入收取11元。第二种是分两次购买,每一次买1个面包,一次6元打9折后应收费5.4元,四舍五入收取5元。两次共花费52=10元。所以最小花费为10元。

#include
using namespace std;
int main()
{
    int n,k;
    while(cin>>n>>k)
    {
        int ans=0,res=0;
        for(int i=0;i5)
            {
                int temp1=res*9;
                ans+=temp1/10;
                res=0;
            }
        }
        int temp1=res*9;
        int temp2=temp1/10;
        {
            if(temp1%10>=5)
                temp2++;
        }
        ans+=temp2;
        cout<

H - 秦队长猜想

UESTC - 1830

秦队长猜想:“任何一个大于等于6

的整数都能写成三个质数的和。“

现给你一个N

,请你构造三个质数 x,y,z.使得 x+y+z=N

.

Input

一行,仅一个整数N(6<=N<=109)

.

Output

一行,三个质数x,y,z

,以空格隔开。

如果有多组解,你只用需输出任意一组解即可。

Sample Input
855
Sample Output
2 3 35 19 31
#include
using namespace std;
int zs(long long n)
{
    for(long long i=2; i*i<=n; i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}
int main()
{
    long long n;
    while(cin>>n)
    {
        long long a,b,c;
        if(n%2==0)
        {
            n-=2;
            long long i,j;
            for(i=n-2,j=2; i>=n/2&&j<=n/2; i--,j++)
            {
                if(zs(i)&&zs(j))
                {
                    cout<<2<<' '<=n/2&&j<=n/2; i--,j++)
            {
                if(zs(i)&&zs(j))
                {
                    cout<<3<<' '<





你可能感兴趣的:(训练赛20180219)