codeforces round # 273 div2 A, B, C题题解

Table Decorations(思维题) **Table Decorations**Description You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn’ 阅读详情
A. Initial Bet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.

Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.

Input

The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).

Output

Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value of b, then print the only value "-1" (quotes for clarity).

Sample test(s)
Input
2 5 4 0 4
Output
3
Input
4 5 9 2 1
Output
-1
Note

In the first sample the following sequence of operations is possible:

  1. One coin is passed from the fourth player to the second player;
  2. One coin is passed from the fourth player to the fifth player;
  3. One coin is passed from the first player to the third player;
  4. One coin is passed from the fourth player to the second player.


水题,但是有个坑点,如果5个数都是0,要输出-1而不是0


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>


using namespace std;

int main()
{
    int a, b, c, d, e;
    while (~scanf("%d%d%d%d%d", &a, &b, &c, &d, &e))
    {
        int sum = a + b + c + d + e;
        if(sum % 5 != 0 || sum == 0)
        {
            printf("-1\n");
            continue;
        }
        printf("%d\n",  sum / 5);
    }
    return 0;
}

B. Random Teams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.

Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

Input

The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.

Output

The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

Sample test(s)
Input
5 1
Output
10 10
Input
3 2
Output
1 1
Input
6 3
Output
3 6
Note

In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.

In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.

In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.


最多的话,就是m-1组放1个人,最后那组放n - m + 1个人

最少的话,就是平摊


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>


using namespace std;

int main()
{
    __int64 n, m;
    while (~scanf("%I64d%I64d", &n, &m))
    {
        __int64 mins = 0;
        __int64 cnt = n / m;
        if(n % m == 0)
        {
            mins = m * (cnt - 1) * cnt / 2;
        }
        else
        {
            int lst = n % m;
            mins = lst * (cnt + 1) * cnt / 2 + ( m - lst) * (cnt - 1) * cnt / 2;
        }
        __int64 maxs = (n - m + 1) * ( n - m) / 2;
       printf("%I64d %I64d\n", mins, maxs);
    }
    return 0;
}


C. Table Decorations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?

Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.

Input

The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.

Output

Print a single integer t — the maximum number of tables that can be decorated in the required manner.

Sample test(s)
Input
5 4 3
Output
4
Input
1 1 1
Output
1
Input
2 3 3
Output
2
Note

In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.


贪心题,第二轮挂了,做法参照网上


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>


using namespace std;

int cmp(__int64 a, __int64 b)
{
    return a < b;
}

int main()
{
    __int64 a[3];
    while (~scanf("%I64d%I64d%I64d", &a[0], &a[1], &a[2]))
    {  
        sort(a, a + 3, cmp);
        __int64 x = a[0];
        __int64 y = a[1];
        __int64 z = a[2];
        if(x * 2 + y * 2 <= z)
        {
            printf("%I64d\n", x + y);
            continue;
        }
        printf("%I64d\n", (x + y + z) / 3);
    }
    return 0;
}



Codeforces 题解 (不断更新,一起上分) 目录 Educational Codeforces Round 45 (Rated for Div. 2) Educational Codeforces Round 45 (Rated for Div. 2) 题目:A. Commentary Boxes题解 题目:B Micro-World 题解 题目:C Bracket Sequences Concatenation Problem 题解 题目:D Graph And Its Complement 题解 题目:E Po... 阅读详情

相关推荐

Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

寒假每日训练2021/1/21 每日亿题 这套Div2 好简单呀,我写了不到两个小时就快AK了…

繁凡さん的博客 1922

#273.2 C. Table Decorations(贪心)

You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What max

Halo 733

Codeforces Round #684 (Div. 2) A - C2 题解

Codeforces Round #684 (Div. 2) A - C2 题解 A Buy the String 题意 给定一个长度为 nnn 的01串,你可以用 hhh 的代价把字符串中任意一个字符取反,最终你要把这个01串买下来,0的单价为c0c_0c0​,1的单价为 c1c_1c1​。现给你n,h,c0,c1n,h,c_0,c_1n,h,c0​,c1​以及一个01串,问你最少花多少可以买下这个串。输出最小总价。 思路 贪心,设c0<c1c_0 \lt c_1c0​<c1​,若c1−c0

avgstuBoboge的博客 1193

CF 273C Table Decorations

C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have r red, g green and b blue balloons. To

? 614

【CodeForces】CodeForces Round #477 (Div. 1 + Div. 2) 题解

【比赛链接】Div. 1Div. 2【题解链接】点击打开链接【Div.2 A】Mind the Gap【思路要点】从小到大枚举答案,检查合法性。时间复杂度\(O(Ans*N)\)。【代码】#include&lt;bits/stdc++.h&gt; using namespace std; const int MAXN = 100005; template &lt;typename T&gt; vo...

cz_xuyixuan的博客 1784

Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

Codeforces Round #712 Div.2(A~F) 题解 A. Déjà Vu Problem 给你一个字符串。问能否在该字符串里插入一个字母 a,使得它不是回文字符串。 Solution 显然不想让他变成回文字符串,那就破坏它成为回文字符串的条件,我们只能插入字符 a ,所以我们直接算一下该字符串前缀、后缀里各有有几个 a ,把我们能插入的 a 放到 a 多的地方即可。 Code // Problem: A. Déjà Vu // Contest: Codeforces - Codefor

繁凡さん的博客 1221

A. Initial Bet(Codeforces Round #273)

A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are five people playing a game called "

ACway的专栏 1539

Codeforces Round #786 (Div.3) 题解 (CF786) [A-G]

Codeforces Round #786 (Div.3) 题解 [A-G]

zeekliu的博客 985

Codeforces Round #273 (Div. 2)

codeforces div2 round 273解题报告

Tc的专栏 2785

Codeforces Round #686 (Div. 3) A-F题解

Codeforces Round #686 (Div. 3) A-F题解 A. Special Permutation 题意 给定 nnn ,输出一个长度为 nnn 的全排列,每个位置 iii 上的数不等于 iii。 思路 1−n1-n1−n全排列循环右移一位。 代码 #include <bits/stdc++.h> using namespace std; const int M = 110; int dp[M]; int main() { int T; cin >

avgstuBoboge的博客 1082

Codeforces Round #643 (Div. 2)题解

A Sequence with DigitsSequence\ with\ DigitsSequence with Digits

繁凡さん的博客 741

Codeforces Round #659 (Div. 2)A-D题解

Codeforces Round #659 (Div. 2)A-D题解 //打牛客多校去了,CD晚点施工 //写于rating值2032/2056 这一场cf是补的,题目分布并没有按照往常的难度梯度递增。 这场是同时有div1和div2,对于div2的人来说这场如果策略得到及时跟过题人数多的题去写C的话是个上分的好机会。 A题难度为一般div2场的B B1B2题难度为一般div2场的DE CD难度对应一般div2场的DE Codeforces Round #659 (Div. 2) A题难度系数1200 一

StandNotAlone的博客 1万+

endnote让参考文献整整齐齐

这篇文章主要是针对利用 endnote 插入参考文献时,参考文献第一行和后面的行对不齐的问题 下面是示意图 可以看到我们的参考文献对的整整齐齐的,比较好看。 下面介绍具体步骤 1、打开endnote。编辑我们使用的参考文献样式。我这儿是叫 ZZ_MODIFIED_GEEBINF 复制 2、找到布局,每个参考开头,将光标放在在参考开头后面,点插入字段,制表符 3、右下角悬挂式输出哪儿选择全部段...

雾隐雾现的至渝博客 5万+

Codeforces Round #687(Div2)A~D题题解

A. Prison Break 题目传送门: A. Prison Break 题目大意: 有一个n*m的监狱,每一个格子有一个犯人,坐标为( r , c )的格子有一条逃生通道,犯人每一秒可以向相邻的一个格子移动,问所有犯人到达逃生通道最久需要多少秒。 思路: 判断监狱四个角上的犯人到达逃生通道的时间即可 AC Code #include<bits/stdc++.h> using namespace std; int main() { int t; scanf("%d",&amp

稚始稚终的博客 2692

为什么大语言模型推理要分成 Prefill 和 Decode?深入理解这两个阶段的真正意义

Prefill 阶段是语言模型推理中的第一个步骤,它负责处理你输入的所有上下文内容(prompt),为后续生成打下基础。“请解释一下 Transformer 的原理。这句话会被 tokenizer 编码为一串 token,比如["请", "解释", "一下", "Trans", "##former", "的", "原理", "。"]。然后这些 token 会进入 Transformer 模型进行前向传播。重点来了 👇。

Harry的博客 1万+

空天大模型详解

空天大模型是指面向空天信息领域(如卫星遥感、导航、气象等)设计的多模态人工智能模型,能够处理海量遥感数据、多传感器信息及跨时空分析任务。多模态融合:整合可见光、雷达、热红外、多光谱等多源遥感数据,构建统一表征空间,例如“空天·灵眸”3.0版支持航空、卫星及无人机数据的自动化解译。轻量化与高效推理:针对星载计算场景,采用分层量化、跨模态蒸馏技术压缩模型参数(如JigonGPT从1.02B压缩至0.23B,性能仅牺牲5.2%)18,并通过热传导架构提升计算速度2.4倍。神经符号结合。

zxy98的专栏 1588

Codeforces Round #737 (Div. 2) 题解(A-C)

Codeforces Round #737 (Div. 2) 题解(A-C) A. Ezzat and Two Subsequences 题目大意: 给定nnn个整数,将这nnn个整数分成两组,使得两组整数的平均数之和最大,输出这个最大的平均数之和。 解题思路: 通过观察样例可以发现,只要将最大的整数单独作为一组就行了。 那么为什么这样是对的呢,可以考虑进行这样分组之和,从n−1n-1n−1个整数那组拿任意一个整数过来能否取得更优的解,列个式子推一推就能明白了,因为本人比较懒就不写详细的证明过程了。 代码:

qq_43657674的博客 1702

MuJoCo新手必看:5分钟搞定你的第一个机器人仿真(附Python代码)

本文为零基础新手提供了一份详尽的MuJoCo物理仿真引擎入门指南。从环境搭建、MJCF模型文件解析,到编写Python控制代码,手把手教你5分钟内创建并运行第一个机器人仿真。内容涵盖双摆模型控制与自定义四轮小车构建,帮助你快速掌握这一高性能开源工具,迈出机器人学与强化学习仿真的第一步。

weixin_29032489的博客 660

Codeforces Round #713 (Div. 3)-C. A-B Palindrome-题解

目录Codeforces Round #713 (Div. 3)-C. A-B PalindromeProblem DescriptionInputOutputSample InputSample Onput题目大意解题思路AC代码 Codeforces Round #713 (Div. 3)-C. A-B Palindrome 传送门 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description You are given a

<font color="Pink">Tisfy的博客</font> 1万+

Cadence Virtuoso IC618实战:手把手教你搭建OTA电路并完成AC仿真(附避坑指南)

本文详细介绍了在Cadence Virtuoso IC618环境下搭建OTA电路并完成AC仿真的全流程,包括环境准备、原理图绘制、仿真配置及常见报错解决方案。特别针对IC618版本特有的配置难题提供了避坑指南,帮助模拟集成电路设计工程师高效完成前仿真工作。

weixin_31902781的博客 283

Unity Animancer插件(一)基本使用

Animancer是什么?资源商店主页我们来通过Animancer实现一个最基本的动画播放效果。首先创建一个脚本,编写如下代码 很容易理解,就是在时播放一个指定的动画片段。接下来为角色添加、和刚刚编写的,并为字段赋值 接下来运行游戏就可以看到效果了 此时角色身上的组件可以看到当前动画的各项参数 下面我们来实现通过按键控制角色在于之间转换。新创建一个脚本。在代码中监听Y轴上的输入。然后根据监听到的数值判断角色状态,并播放相应的动画 给对应字段赋值后,启动游戏看下效果 下面来实现一个开枪效果。在默认状态下,角色

夜槿笙歌的博客 1万+

Codeforces Round #688 (Div. 2) A~D题题解

A.Cancel the Trains 题目传送门: A.Cancel the Trains 题目大意: 如图所示,竖向轨道的火车从最下面出发,横向轨道的火车从最左边出发,所有火车以相同的速度行驶,问你为了避免火车相撞,最少需要去除几辆火车。 思路: 因为速度都相同,所以题目数据中如果存在竖向火车的出发索引和横向火车的出发索引相同,那么必然会相撞,去除一辆。 AC Code #include<bits/stdc++.h> using namespace std; typedef long lo

稚始稚终的博客 1093

解决 NLPIR (中科院分词) License 过期问题

因为学习需要,使用到了中文分词技术,网上搜索一番,最终选择了名气比较大的中科院分词器(NLPIR/ICTCLAS)。 用了几个月之后突然报错: E:\code\URLClassifier\Data\NLPIR.user Not valid license or your license expired! Please feel free to contact pipy_zhan

勇敢向前冲 1万+

Codeforces Round #666(Div.2)A~D题题解

A .Juggling Letters 题目传送门 Juggling Letters 题目大意 给你n个字符串,字符串si中的任意一个字母可以插入到任意一个字符串(包括自己)的任意位置,问是否能构成n个完全相同的字符串。 思路 思路很清晰,只需每种字母的数量%n==0即可 AC Code B.Power Sequence 题目传送门 Power Sequence ...

稚始稚终的博客 1171

《UDS协议从入门到精通》系列——图解0x83:访问时间参数

详细介绍UDS协议0x83服务,目标ECU的时序参数设置有哪些注意点?

车载系统攻城狮 2143

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Codeforces Round #660 (Div. 2)A-D题解

Codeforces Round #660 (Div. 2)A-D题解 //写于rating值2184/2184 //上黄场,rating值+152。这一场没有什么算法,靠着一波快手速抢了一波不计div1选手的div2的第25名,记div1选手的第109名。很侥幸,但是上了黄名还是非常开心的。 比赛链接:https://codeforces.ml/contest/1388 A题 简单的构造。应该有很多的过题方法,这里我用的特判的方法,在稿纸上列了一波,6分钟过的题。 给定一个数字n,我们需要构造四个正整数a

StandNotAlone的博客 2231

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

上一篇: hdu4612——Warm up
下一篇: 关于01背包空间优化的理解
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值