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 ...
随机推荐
- IBM WebSphere MQ
相关链接: http://kakajw.iteye.com/category/269774 http://www.ibm.com/support/knowledgecenter/zh/SSFKSJ_7 ...
- Codeforces Round #529 -C- Powers Of Two(二进制拆分)
A positive integer xx is called a power of two if it can be represented as x=2yx=2y, where yy is a n ...
- [NWPU2016][寒假作业][正常版第三组]I
素数环,简单的dfs,但这道题我有个小地方写错了半天发现不了..就是flag数组的位置.一定要放在if里面,刚开始没注意,一不小心写到外面了. #include <iostream> #i ...
- 线程池(4)Executors.newScheduledThreadPool-只执行1次
例子1:延迟3秒后,只执行1次 ScheduledExecutorService es = Executors.newScheduledThreadPool(5); log.info("开始 ...
- java颜色代码对照表
LightPink 浅粉色 #FFB6C1 255,182,193 Pink 粉红 #FFC0CB 255,192,203 Crimson 猩红 #DC143C 220,20,60 LavenderB ...
- ORA-06502 when awr report produce
最近在生成一套系统的AWR报告时出现了如下报错:ORA-06502: PL/SQL: numeric or value error: character string buffer too small ...
- 数据绑定以及Container.DataItem几种方式与用法分析
灵活的运用数据绑定操作 绑定到简单属性:<%#UserName%> 绑定到集合:<asp:ListBox id="ListBox1" ...
- GDI绘制图形的使用_验证码
//创建GDI对象 Graphics g = this.CreateGraphics();// new Graphics(); //创建画笔对象 Pen pen = new Pen(Brushes.R ...
- text-transform字母大小写属性设置
text-transform: none: 默认 不设置,全是小写 capitalize: 每个单词以大写字母开头 uppercase: 全部是大写字母 lowercase: 全部是小写字母 in ...
- Java分页下载
需求.提供公共的可以按照一定条件查询出结果,并提供将查询结果全部下载功能(Excel.CSV.TXT),由于一次性查出结果放到内存会占用大量内存.需要支持分页模式查询出所有数据. 实现思路 1.在公共 ...