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 ...
随机推荐
- Nuske vs Phantom Thnook
Nuske vs Phantom Thnook Time limit : 4sec / Memory limit : 256MB Score : 700 points Problem Statemen ...
- Introduction to Mathematical Thinking - Week 7
Q: Why did nineteenth century mathematicians devote time to the proof of self-evident results? Selec ...
- Python3.6全栈开发实例[015]
15.电影投票:程序先给出几个目前正在上映的电影列表. 由用户给每个电影投票.最终将该用户投票信息公布出来 lst = ['北京遇上西雅图', '解救吴先生', '美国往事', '西西里的美丽传说'] ...
- 我的Android进阶之旅------>百度地图学习:BDLocation.getLocType ( )值分析
BDLocation类,封装了定位SDK的定位结果,在BDLocationListener的onReceive方法中获取.通过该类用户可以获取error code,位置的坐标,精度半径等信息.具体方法 ...
- ZFIR_001 ole下载
*&---------------------------------------------------------------------** Report ZFIR_001* Appli ...
- corethink功能模块探索开发(五)开启这个模块的配置
上图: 主要就是两点. 1.在opencmf.php中填写好配置页面的按钮还是文本域 Equip/opencmf.php只需要注意主要的配置数组的内容 <?php // 模块信息配置 retur ...
- 4.2 使用STM32控制MC20发送短信
需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...
- windows下客户端开发hdf--环境搭建
1.引入依赖 <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop- ...
- Django 之基础续
1.路由系统之动态路由 前言:还记得之前的分页效果,这个如何实现呢?答案就是动态路由. url(r'^detail/(\d+)/$', views.detail), url(r'^detail2/(\ ...
- iOS 9 的新功能 universal links
什么是 universal links: (通用链接) 一种能够方便的通过传统 HTTP 链接来启动 APP, 使用相同的网址打开web page和 APP的方式. 第一点,链接打开网址 顾名思义 第 ...