Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心
1 second
256 megabytes
standard input
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.
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).
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 ofb, then print the only value "-1" (quotes for clarity).
2 5 4 0 4
3
4 5 9 2 1
-1
In the first sample the following sequence of operations is possible:
- One coin is passed from the fourth player to the second player;
- One coin is passed from the fourth player to the fifth player;
- One coin is passed from the first player to the third player;
- One coin is passed from the fourth player to the second player.
题意:求整数平均数,并且平均数>0;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
const ll INF=1e18+;
int main()
{
int sum=;
for(int i=;i<=;i++)
{
int x;scanf("%d",&x),sum+=x;
}
if(sum%||sum==)
printf("-1\n");
else
printf("%d\n",sum/);
return ;
}
1 second
256 megabytes
standard input
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.
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.
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.
5 1
10 10
3 2
1 1
6 3
3 6
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 2people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
题意:n个人,m支队,将n个人分到m支队,每个队最少一个人,每个队内的人相互认识,但是不认识别的队的人,求分配认识对数,最小和最大;
思路:最小显然平均分配,最大显然是将(m-1)支队分到一个人,另外一只分n-m+1个人;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
const ll INF=1e18+;
ll getans(ll x)
{
return x*(x-)/;
}
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
ll minn=getans(n/m+(n%m?:))*(n%m?n%m:m)+getans(n/m)*((m-(n%m))%m);
ll maxx=getans(n-m+);
printf("%lld %lld\n",minn,maxx);
return ;
}
1 second
256 megabytes
standard input
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.
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.
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
5 4 3
4
1 1 1
1
2 3 3
2
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.
题意:有r个红气球,g个绿气球,b个蓝气球,每张桌子的三个气球不能同色,问r,g,b最多能装多少张桌子;
思路:贪心,判断是否有极端,否则相加除3;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
const ll INF=1e18+;
ll a[];
int main()
{
scanf("%lld%lld%lld",&a[],&a[],&a[]);
sort(a,a+);
if(a[]>*a[]+*a[])
printf("%lld\n",a[]+a[]);
else
printf("%lld\n",(a[]+a[]+a[])/);
return ;
}
Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心的更多相关文章
- Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心
A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心
A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #308 (Div. 2) A B C 水 数学
A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心
A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
随机推荐
- proguard-project.txt和project.properties混淆代码
[转]利用android proguard混淆代码 防止反编译,优化代码 网上虽然有很多相关博客,不过貌似都不是最新版的..于是百度+谷歌+github上的开源demo,终于成功的配置了androi ...
- form表单提交中文乱码(前台中文到JAVA后台乱码)问题及解决
form表单提交中文乱码(前台中文到JAVA后台乱码)问题及解决 一.问题: 页面输入框中的中文内容,在后台乱码,导致搜索功能失效:(详细可以见后面的重现) 二.原因: 浏览器对于数据的默认编码格式为 ...
- FZU 2099 魔法阵(计算几何)
Problem 2099 魔法阵 Accept: 120 Submit: 289 Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- fecha的使用
项目中时间的处理是无法避免的,时间的处理方式有很多,这里介绍一下fecha的使用 fecha是一个日期格式化和解析的js库,它提供了强大的日期处理功能,功能强大且只有2k大小.安装方式简单,只需要 n ...
- ThinkPHP的create方法的一系列操作
1.数据操作状态 create方法的第二个参数可以指定数据的操作状态,默认是自动判断的(写入[Model:MODEL_INSERT或者1].更新[Model:MODEL_UPDATE或者2].也可以自 ...
- Android系统移植与调试之------->如何修改Android设备存储盘符名称与Android设备的型号
一.修改Android设备存储盘符名称 (注:TBDG1073为我的项目名称) 1.修改device/other/TBDG1073/system.prop 文件 2.修改ro.media.patiti ...
- github的代码上传成功但是不显示绿格子(一直拖....心痛的教训.....)
损失了我特么的很多格子啊啊啊啊,必死强迫症啊!!!! 究其原因就是客户端绑定邮箱错误 本地 :git config user.email 显示邮箱是否和github中设定的一样? git config ...
- php mysqli扩展库之预处理操作
分享下php使用mysqli扩展库进行预处理操作的二个例子,有意研究mysqli用法的朋友,可以参考学习下,一定会有所帮助的. 例1.使用mysqli扩展库的预处理技术 mysqli stmt 向数据 ...
- asp.net 利用Response.Filter 获取输出内容, 变更输出内容
重写 Response.Filter 就可以获取或更新输出到浏览器的内容 资料: https://weblog.west-wind.com/posts/2009/Nov/13/Captur ...
- Hibernate_HelloWord
Hibernate操作步骤 1.新建项目 2.加jar包 3.写XML配置文件hibernate.cfg.xml 4.写log4j.properties日志文件 5.在MySql数据库中建studen ...