Codeforces Round #227 (Div. 2)

A. George and Sleep
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.

Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).

Input

The first line contains current time s as a string in the format "hh:mm". The second line contains time t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 2300 ≤ mm ≤ 59.

Output

In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.

Sample test(s)
input
05:50
05:44
output
00:06
input
00:00
01:00
output
23:00
input
00:01
00:00
output
00:01

题意:第一个睡醒的时间,第二个开始睡的时间,问睡了多久,可能过了一天

题解:直接化成多少分钟,+1440然后模1440,再换成小时分钟就可以了

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
    int x1,x2,y1,y2,res;
    char ch;

    while(scanf("%d%c%d",&x1,&ch,&y1)>0)
    {
        scanf("%d%c%d",&x2,&ch,&y2);
        res=(x1*60+y1-x2*60-y2+1440)%1440;
        printf("%02d:%02d\n",res/60,res%60);
    }

    return 0;
}



B. George and Round
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers1 through m. George estimates the i-th problem's complexity by integer bi.

To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.

George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.

However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a goodround. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
3 5
1 2 3
1 2 2 3 3
output
0
input
3 5
1 2 3
1 1 1 1 1
output
2
input
3 1
2 3 4
1
output
3

题意:给n个要求的数,给m个有的数,大于要求的数可以当要求的数用

题解:2个数组都升序排序,2个数组都从最后贪心取上去,可以取就取并标记,就可以得到结果了

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int a[3008],b[3008],mark[3008];
int cmp(const void *a,const void *b)
{
    return *(int *)a<*(int *)b?-1:1;
}
int main()
{
    int i,j,n,m,ans;

    while(scanf("%d%d",&n,&m)>0)
    {
        memset(mark,0,sizeof(mark));
        for(i=0;i<n;i++) scanf("%d",a+i);
        for(i=0;i<m;i++) scanf("%d",b+i);
        qsort(a,n,sizeof(a[0]),cmp);
        qsort(b,m,sizeof(a[0]),cmp);
        for(j=m-1,i=n-1;i>=0;i--)
        {
            if(j>=0&&b[j]>=a[i]){ j--; mark[i]=1; }
        }
        for(ans=i=0;i<n;i++) if(!mark[i]) ans++;
        printf("%d\n",ans);
    }

    return 0;
}


C. George and Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b1, b2, ..., b|b| (record |b| denotes the current length of the array). Then one change is a sequence of actions:

  • Choose two distinct indexes i and j (1 ≤ i, j ≤ |b|; i ≠ j), such that bi ≥ bj.
  • Get number v = concat(bi, bj), where concat(x, y) is a number obtained by adding number y to the end of the decimal record of number x. For example, concat(500, 10) = 50010concat(2, 2) = 22.
  • Add number v to the end of the array. The length of the array will increase by one.
  • Remove from the array numbers with indexes i and j. The length of the array will decrease by two, and elements of the array will become re-numbered from 1 to current length of the array.

George played for a long time with his array b and received from array b an array consisting of exactly one number p. Now George wants to know: what is the maximum number of elements array b could contain originally? Help him find this number. Note that originally the array could contain only positive integers.

Input

The first line of the input contains a single integer p (1 ≤ p < 10100000). It is guaranteed that number p doesn't contain any leading zeroes.

Output

Print an integer — the maximum number of elements array b could contain originally.

Sample test(s)
input
9555
output
4
input
10000000005
output
2
input
800101
output
3
input
45
output
1
input
1000000000000001223300003342220044555
output
17
input
19992000
output
1
input
310200
output
2

题意:一个数组,每次将2个数合并,并且大的排在前面,给出合并完的数,问最多是又多少个数组成的

题解:从一开始贪心,若当前数比下一个数大,则答案加一,否则初始化答案为一,最后就是结果(一个位当一个数,若后面有零,则要带上全部后缀零)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char s[1000008],now[1000008],temp[1000008];
int i,j,len,ans,ls;
int main()
{
    while(scanf("%s",s)>0)
    {
        ls=strlen(s);
        now[0]=s[0];
        for(i=1;s[i]=='0';i++) now[i]=s[i];
        now[len=i]='\0';
        for(ans=1;i<ls;)
        {
            temp[j=0]=s[i++];
            for(j++;i<ls&&s[i]=='0';j++,i++) temp[j]=s[i];
            temp[j]='\0';
            if(len>j) ans++;
            else if(len==j&&strcmp(now,temp)>=0) ans++;
            else ans=1;
            len=len+j;
            strcat(now,temp);
        }
        printf("%d\n",ans);
    }

    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值