CF #552 div3
A - Restoring Three Numbers CodeForces - 1154A
Polycarp has guessed three positive integers aa, bb and cc. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+ba+b, a+ca+c, b+cb+c and a+b+ca+b+c.
You have to guess three numbers aa, bb and cc using given numbers. Print three guessed integers in any order.
Pay attention that some given numbers aa, bb and cc can be equal (it is also possible that a=b=ca=b=c).
Input
The only line of the input contains four positive integers x1,x2,x3,x4x1,x2,x3,x4 (2≤xi≤1092≤xi≤109) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number x1,x2,x3,x4x1,x2,x3,x4.
Output
Print such positive integers aa, bb and cc that four numbers written on a board are values a+ba+b, a+ca+c, b+cb+c and a+b+ca+b+c written in some order. Print aa, bb and cc in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.
Examples
3 6 5 4
2 1 3
40 40 40 60
20 20 20
201 101 101 200
1 100 100
题意:给你四个值,代表a+b,a+c,b+c,a+b+c的值,然后让你找到a,b,c的值。
解法:排完序之后,a+b+c肯定是最大的,那么减去前三个值也就是得到a,b,c的值了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=;
int x[maxn];
int a,b,c;
int main()
{
for(int i=;i<;i++)
scanf("%d",&x[i]);
sort(x,x+);
a=x[]-x[];
b=x[]-x[];
c=x[]-x[];
printf("%d %d %d\n",a,b,c);
return ;
}
B - Make Them Equal CodeForces - 1154B
You are given a sequence a1,a2,…,ana1,a2,…,an consisting of nn integers.
You can choose any non-negative integer DD (i.e. D≥0D≥0), and for each aiai you can:
- add DD (only once), i. e. perform ai:=ai+Dai:=ai+D, or
- subtract DD (only once), i. e. perform ai:=ai−Dai:=ai−D, or
- leave the value of aiai unchanged.
It is possible that after an operation the value aiai becomes negative.
Your goal is to choose such minimum non-negative integer DD and perform changes in such a way, that all aiai are equal (i.e. a1=a2=⋯=ana1=a2=⋯=an).
Print the required DD or, if it is impossible to choose such value DD, print -1.
For example, for array [2,8][2,8] the value D=3D=3 is minimum possible because you can obtain the array [5,5][5,5] if you will add DD to 22 and subtract DD from 88. And for array [1,4,7,7][1,4,7,7] the value D=3D=3 is also minimum possible. You can add it to 11 and subtract it from 77 and obtain the array [4,4,4,4][4,4,4,4].
Input
The first line of the input contains one integer nn (1≤n≤1001≤n≤100) — the number of elements in aa.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100) — the sequence aa.
Output
Print one integer — the minimum non-negative integer value DD such that if you add this value to some aiai, subtract this value from some aiai and leave some aiai without changes, all obtained values become equal.
If it is impossible to choose such value DD, print -1.
Examples
6
1 4 4 7 4 1
3
5
2 2 5 2 5
3
4
1 3 3 7
-1
2
2 8
3
题意:给你n个数,找到一个数D,对于这n个数的每一个有三种操作,ai+D,ai-D,ai。问最后能不能使得这n个数相等,可以的D中取最小值。
解法:数组排序去重之后,判断剩下的数不重复的值有几个,超过三个的话就肯定不存在这个D值了,如果是三个的话只有是等比数列的时候才可以;如果是两个的话,看这两个数相加起来是否为偶数,是偶数就能使得一个数+D,一个数-D
得到两个相等的数值,奇数的话只能把一个数变为另一个数;如果全相等的话就输出0即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=;
int n;
int a[maxn];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int len=unique(a,a+n)-a;
if(len==)
printf("0\n");
else if(len==)
{
if((a[]-a[])% == )
printf("%d\n",(a[]-a[])/);
else if((a[]-a[])% == )
printf("%d\n",a[]-a[]);
}
else if(len==&&a[]-a[]==a[]-a[])
printf("%d\n",a[]-a[]);
else
printf("-1\n");
return ;
}
C - Gourmet Cat CodeForces - 1154C
Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:
- on Mondays, Thursdays and Sundays he eats fish food;
- on Tuesdays and Saturdays he eats rabbit stew;
- on other days of week he eats chicken stake.
Polycarp plans to go on a trip and already packed his backpack. His backpack contains:
- aa daily rations of fish food;
- bb daily rations of rabbit stew;
- cc daily rations of chicken stakes.
Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.
Input
The first line of the input contains three positive integers aa, bb and cc (1≤a,b,c≤7⋅1081≤a,b,c≤7⋅108) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.
Output
Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.
Examples
2 1 1
4
3 2 2
7
1 100 1
3
30 20 10
39
思路:一星期a有3次,b有2次,c有2次,所以依次相除,在选取最小表示最多坚持完整的星期有几个,之后枚举判断一星期之内(不包含7)的最多坚持天数相加即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=;
int a,b,c;
int ans=;
int main()
{
scanf("%d %d %d",&a,&b,&c);
while()
{
if(a<=||b<=||c<=)
break;
a-=;
b-=;
c-=;
ans+=;
}
int temp=;
for(int i=;i<=;i++)
{
int t=i;
int maxx=;
int aa=a,bb=b,cc=c;
while(true)
{
if(aa<||bb<||cc<)
{
temp=max(temp,maxx);
break;
}
if(t%==||t%==||t%==)
aa--;
if(t%==||t%==)
bb--;
if(t%==||t%==)
cc--;
t++;
maxx++;
}
}
printf("%d\n",ans+temp-);
return ;
}
CF #552 div3的更多相关文章
- CF #552(div3)G 最小lcm
题目链接:http://codeforces.com/contest/1154/problem/G 题意:lcm是最小公倍数,本题就是给你一个数组(可能会重复),要求你判断出那两个数的最小公倍数最小, ...
- CF #552(div3)F 背包问题
题目链接:http://codeforces.com/contest/1154/problem/F 题意:一个商店有n个物品,每个物品只能买一次,同时有m种优惠,即一次买够x件后,这x件中最便宜的k件 ...
- CF #575 Div3
// 比赛链接:https://codeforces.com/contest/1196 // CF 2019.7.24 // 本想Div3手速场上分,结果卡在C题,掉了不少分. // 自闭了这么久,今 ...
- CF 552(div 3) E Two Teams 线段树,模拟链表
题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有 ...
- CF 552 Neko does Maths
给出两个数a,b 求k 使得 a+k b+k有最小公倍数 a,b同时加上一个非负整数k,使得,a+k,b+k的最小公倍数最小 因为最小公公倍数=x*y / gcd(x,y),所以肯定离不开最大 ...
- 2021-01-25 cf #697 Div3 C题(超时,换思路减少复杂度)
题目链接:https://codeforces.com/contest/1475/problem/C 题意要求:需组成的2对,男的序号不能重,女的序号不能重 比如这例 输入: 行1--测试个数 行1` ...
- 12.27 cf div3 解题报告
12.27 cf div3 解题报告 wxy.wxy,带上分拉,全场做了个无脑小白 比赛场地 A: T1,跟着模拟就好了 B: sort一遍之后 去除的数一定是a[1]或者a[n] 比较去除谁小就输出 ...
- CF contest 1216 Div3. F
题目链接:Click here Solution: 看起来是贪心,其实不然... 我们定义\(f[i]\)表示仅覆盖\(1\sim i\)所需要的最小代价,那么对\(i\)为0的点来说,易得\(f[i ...
- CF 552C 进制转换
http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...
随机推荐
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he we ...
- 命令行下载工具 wget
wget 是一个简单而强大的跨平台命令行下载工具,包括 Windows 也有对应的版本.全称 GNU Wget,属于 GNU 计划的一部分,自由软件.支持 HTTP.HTTPS 和 FTP 协议,可在 ...
- idea 卡顿问题
转载大神总结 https://jingyan.baidu.com/article/c275f6ba14207ee33c756752.html
- 日志AOP的实现
/// <summary> /// 日志AOP拦截 /// </summary> [AttributeUsage(AttributeTargets.Method, AllowM ...
- 用canvas裁剪图片
var selectObj = null; function ImageCrop(canvasId, imageSource, x, y, width, height) { var canvas = ...
- 【踩坑】List 的陷阱
今天测试iReview项目数据的反馈,发现有些语句总无法执行. 经过调试排查后,发现List<自定义类>返回了空集"[]",却无法进入if语句里面,即 if (List ...
- SpringBoot 封装返回类以及session 添加获取
1.创建返回类Result public class Result<T>{ /*错误码*/ private Integer code; /*提示信息 */ private String m ...
- ABAP EXCEPTION
CX_ROOT | |--CX_STATIC_CHECK | |--CX_DYNAMIC_CHECK | | | |--CX_SY_ARITHMETIC_ERROR //运算 '&OPERAT ...
- css样式优先级问题
官方表述的CSS样式优先级如下: 通用选择器(*) < 元素(类型)选择器 < 类选择器 < 属性选择器 < 伪类 < ID 选择器 < 内联样式 那么,我们来举个 ...
- 超图supermap sdx数据库用sql实现空间查询
在此介绍用sql对超图的空间数据库(sdx)进行空间查询,优点如下: 1.超图推荐的方式是用iobject,此方法要引入iobject 2.超图另一个推荐的方式是用iserver的REST接口,但we ...