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 ...
随机推荐
- IOS 版本控制判断
// 版本判断#define SYSTEM_VERSION(ver) [[[UIDevice currentDevice] systemVersion] compare:ver] != NSOrder ...
- 【NOI2012】迷失游乐园
题目链接:迷失游乐园(BZOJ) 迷失游乐园(Luogu) 独立完成的题,写一发题解纪念一波~ 模拟完样例大概可以知道是道树形DP了. 观察数据范围,发现是基环树,至少会有一个环. 先从树的部分开始 ...
- 导出war包
1. 使用Eclipse 导出 右键web工程 -> export -> war file 将导出的war文件放到tomcat安装目录的webapps下,然后启动tomcat,就会发现在该 ...
- 基于Vue的省市区三级联动插件
官网地址:https://distpicker.uine.org/ 安装: npm install v-distpicker --save 局部注册: import VDistpicker from ...
- 微信小程序实战
为了积攒粉丝,公司决定做一个一分钱姓名测算的小程序引导大家关注公众号. 实现的需求就是 1 首页 用户编辑姓名和性别进行提交 2 测算结果页 实现分享和支付功能 3 测算历史页面 看到用户曾经测算记 ...
- Luogu P1462 通往奥格瑞玛的道路 二分答案+最短路
先二分答案,再跑最短路,跑的时候遇到 过路费超过二分的答案的 就不拿他更新最短路 #include<cstdio> #include<iostream> #include< ...
- 长春理工大学第十四届程序设计竞赛(重现赛)F.Successione di Fixoracci
链接:https://ac.nowcoder.com/acm/contest/912/F 题意: 动态规划(Dynamic programming,简称dp)是一种通过把原问题分解为相对简单的子问题的 ...
- net core 2.0 web api + Identity Server 4 + angular 5
net core 2.0 web api + Identity Server 4 + angular 5前台使用angular 5, 后台是asp.net core 2.0 web api + ide ...
- Jenkins+Gitlab+Ansible自动化部署(一)
首先准备实验环境 虚拟机 主机名 IP地址 服务 系统版本 内核版本 Vmware Workstation 14 gitlab.example.com 192.168.244.130 gitlab ...
- Java字节码分析
目录 Java字节码分析 查看字节码详细内容 javap 实例分析 Java字节码分析 对于源码的效率,但从源码来看有时无法分析出准确的结果,因为不同的编译器版本可能会将相同的源码编译成不同的字节码, ...