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 ...
随机推荐
- Git 深度学习填坑之旅二(文件三种状态、打标签)
0x01 三种状态 Git 有三种状态,你的文件可能处于其中之一: 已提交(committed).已修改(modified)和已暂存(staged). 已提交表示数据已经安全的保存在本地数据库中. 已 ...
- Invalid YGDirection 'vertical'. should be one of: ( inherit, ltr, rtl )
react native 路由( react-native-router-flux )跳转页面一直都报错 本项目解决方法:不是路由的问题,是跳转的页面有有问题,删除下图标记的红色即可(解决方法是排除法 ...
- jsp内置对象作用域白话演示
内置对象就是JSP中不需要自己定义和声明的对象,可以在JSP中直接使用.JSP中有9大内置对象,它们有两个常用的方法:setAttribute("key","value& ...
- [Android]简略的Android消息机制源码分析
相关源码 framework/base/core/java/andorid/os/Handler.java framework/base/core/java/andorid/os/Looper.jav ...
- G.Longest Palindrome Substring
链接:https://ac.nowcoder.com/acm/contest/908/G 题意: A palindrome is a symmetrical string, that is, a st ...
- Uva10755
在题中的A*B*C的矩形中,当确定X1,X2,Y1,Y2时,1->z的子矩形的和为 sum[x2][y2][1] -(sum[x1-1][y2][1] + sum[x2][y1-1][1] -s ...
- 前端JavaScript(1) --Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- CSS3动画总结学习(一)
参考文章: CSS3 Transitions, Transforms和Animation使用简介与应用展示 CSS 参考手册 动画的分类 平移动画 transform: 就是变换, 变换, 变换 也就 ...
- DotNetAnywhere
DotNetAnywhere:可供选择的 .NET 运行时 原文 : DotNetAnywhere: An Alternative .NET Runtime作者 : Matt Warren译者 : ...
- .net C#实现 中文转Unicode、Unicode转中文 及与js对应关系
中文转Unicode:HttpUtility.UrlEncodeUnicode(string str); 转换后中文格式:"%uxxxx" 举例:"柳_abc123&q ...