Codefoces 1133ABCDE部分题解

本文提供了Codeforces 1133 A-D四道题目的详细解析,包括题意、思路和代码实现。A题求解比赛中场时间,B题涉及糖果分组,C题构建平衡团队,D题最大化零数量。文章适合ACM竞赛爱好者和算法学习者。
摘要由CSDN通过智能技术生成

Codefoces 1133 A-D题解

A - Middle of the Contest CodeForces - 1133A

Polycarp is going to participate in the contest. It starts at h1:m1 and ends at h2:m2. It is guaranteed that the contest lasts an even number of minutes (i.e. m1%2=m2%2, where x%y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.

Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.

input

The first line of the input contains two integers h1 and m1 in the format hh:mm.

The second line of the input contains two integers h2 and m2 in the same format (hh:mm).

It is guaranteed that 0≤h1,h2≤23 and 0≤m1,m2≤59.

It is guaranteed that the contest lasts an even number of minutes (i.e. m1%2=m2%2, where x%y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.

output

Print two integers h3 and m3 (0≤h3≤23,0≤m3≤59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ‘:’.
在这里插入图片描述

题目大意:

给出两个时间,然后输出中间时间

具体做法:

以第一个时间的小时数整点为起始点,然后加上第一个时间的分钟数加上第二个时间的分钟数加上两个小时数的差*60得到一个数,然后用这个数除于2,然后对60取余就是最后的分钟数;除于60 加上第一个时间的小时数就是最后时间的小时数。
需要注意的一点就是格式02%d,其他应该没有难点。

代码如下
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d:%d",&a,&b);
    scanf("%d:%d",&c,&d);
    int sum=(c-a)*60+b+d;
    sum/=2;
    printf("%02d:",a+sum/60);
    printf("%02d",sum%60);
    return 0;
}

B - Preparation for International Women’s Day CodeForces - 1133B

International Women’s Day is coming soon! Polycarp is preparing for the holiday.

There are n candy boxes in the shop for sale. The i-th box contains di candies.

Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i≠j) can be combined as a gift if di+dj is divisible by k.

How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes “partially” or redistribute candies between them.

Input

The first line of the input contains two integers n and k (1≤n≤2⋅105,1≤k≤100) — the number the boxes and the number the girls.

The second line of the input contains n integers d1,d2,…,dn (1≤di≤109), where di is the number of candies in the i-th box.

Output

Print one integer — the maximum number of the boxes Polycarp can give as gifts.
在这里插入图片描述

题目大意:

给你一个n序列和一个k,然后判断有几个数字能组合在一起整除k,不能重复,也就是一个只能和一个组团干k。

思路:

把n个数每一个都去对k取余,然后统计余数为0、1、2…k的分别有多少个,然后选择累加min(i,(k-i)),要把0和2*k=n的做特殊处理
最后输出总和的2倍
暴力不仅卡时间而且还会很麻烦。

代码如下
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int k;
    cin>>n>>k;
    int s[n+1];
    int counts[k]={0};
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        counts[s[i]%k]++;
    }
    int sum=0;
    for(int i=0;2*i<=k;i++)
    {
        if(i==0||2*i==k)
            sum+=counts[i]/2;
        else
        {
            sum+=min(counts[i],counts[k-i]);
        }
        
    }
    cout<<sum*2<<endl;
    return 0;
}

C - Balanced Team CodeForces - 1133C

You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is ai.

You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.

Your task is to report the maximum possible number of students in a balanced team.

Input

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值