Codeforces Round #273 (Div. 2)

2024-03-20 14:58
文章标签 codeforces round div 273

本文主要是介绍Codeforces Round #273 (Div. 2),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

链接:http://codeforces.com/contest/478


A. Initial Bet
time limit per test
1 second
memory limit per test
256 megabytes

There are five people playing a game called "Generosity". Each person gives some non-zero number of coinsb as an initial bet. After all players make their bets ofb 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 sizeb of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coinsb in the initial bet.

Input

The input consists of a single line containing five integersc1, c2, c3, c4 andc5 — 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 integerb — 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).

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.

分析: 签到,注意0的时候特判-1


#include <cstdio>
int main()
{int a, b, c, d, e;scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);int sum = a + b + c + d + e;if(sum == 0)printf("-1\n");else if(sum % 5 == 0)printf("%d\n", sum / 5);elseprintf("-1\n");
}



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

n participants of the competition were split intom 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 integerskmin andkmax — 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 of2 people, maximum number can be achieved if participants were split on teams of1, 1 and 4 people.


分析: 贪心,最大值显然是n-m+1人为一组,最小值则是尽可能均分,均分的话将余数均分分别加到商上即可


#include <cstdio>
#define ll long longll cal(ll x)
{return x * (x - 1) / 2;
}int main()
{ll n, m;ll ma, mi;scanf("%I64d %I64d", &n, &m);ma = cal(n - m + 1);ll tmp = n % m;ll a = n / m;ll num = 0;if(tmp == 0)mi = m * cal(a);elsemi = tmp * cal(a + 1) + (m - tmp) * cal(a);printf("%I64d %I64d\n", mi, ma);
}



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

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 valuesr, g andb 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.


分析:大概写几个yy一下


#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;int main()
{ll a[3], ans = 0;scanf("%I64d %I64d %I64d", &a[0], &a[1], &a[2]);sort(a, a + 3);if((a[0] + a[1]) <= a[2] / 2)ans = a[0] + a[1];elseans = (a[0] + a[1] + a[2]) / 3;printf("%I64d\n",ans);
}




D. Red-Green Towers
time limit per test
2 seconds
memory limit per test
256 megabytes

There are r red andg green blocks for construction of the red-green tower. Red-green tower can be built following next rules:

  • Red-green tower is consisting of some number of levels;

  • Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level — of n - 1 blocks, the third one — ofn - 2 blocks, and so on — the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one;

  • Each level of the red-green tower should contain blocks of the same color.

Let h be the maximum possible number of levels of red-green tower, that can be built out ofr red and g green blocks meeting the rules above. The task is to determine how many different red-green towers havingh levels can be built out of the available blocks.

Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.

You are to write a program that will find the number of different red-green towers of heighth modulo 109 + 7.

Input

The only line of input contains two integers r and g, separated by a single space — the number of available red and green blocks respectively (0 ≤ r, g ≤ 2·105,r + g ≥ 1).

Output

Output the only integer — the number of different possible red-green towers of heighth modulo 109 + 7.

Sample test(s)
Input
4 6
Output
2
Input
9 7
Output
6
Input
1 1
Output
2
Note

The image in the problem statement shows all possible red-green towers for the first sample.


分析 :dp,算下高度,然后算出r的最小需要的个数,高度i,1-h枚举,红色j,r-0枚举dp[j] += dp[j - i];最后把满足条件的dp值加起来即可


#include <cstdio> 
#include <cstring>
#define ll long long   
int const MOD = 1e9 + 7;
int const MAX = 200000 + 5;
int dp[MAX];int main()
{int r, g, h, ans = 0, tmp = 0;scanf("%d %d", &r, &g);ll min_r;memset(dp, 0, sizeof(dp));dp[0] = 1;for(int i = 1; tmp <= (r + g) ;i++){tmp += i;if(tmp > (r + g)){h = i - 1;break;}}min_r = h * (h + 1) / 2 - g;for(int i = 1; i <= h; i++) {for(int j = r; j >= 0; j--)  {if(j - i >= 0)dp[j] = (dp[j] % MOD + dp[j - i] % MOD) % MOD;if(i == h && j >= min_r) ans = (ans % MOD + dp[j] % MOD) % MOD;}}printf("%d\n", ans);
}




这篇关于Codeforces Round #273 (Div. 2)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/829838

相关文章

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

CSS实现DIV三角形

本文内容收集来自网络 #triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;} #triangle-down {width: 0;height: 0;bor

创建一个大的DIV,里面的包含两个DIV是可以自由移动

创建一个大的DIV,里面的包含两个DIV是可以自由移动 <body>         <div style="position: relative; background:#DDF8CF;line-height: 50px"> <div style="text-align: center; width: 100%;padding-top: 0px;"><h3>定&nbsp;位&nbsp;

Codeforces Round 971 (Div. 4) (A~G1)

A、B题太简单,不做解释 C 对于 x y 两个方向,每一个方向至少需要 x / k 向上取整的步数,取最大值。 由于 x 方向先移动,假如 x 方向需要的步数多于 y 方向的步数,那么最后 y 方向的那一步就不需要了,答案减 1 代码 #include <iostream>#include <algorithm>#include <vector>#include <string>

CF#271 (Div. 2) D.(dp)

D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/474/problem/D We s

CF #278 (Div. 2) B.(暴力枚举+推导公式+数学构造)

B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/488/problem/B There