Codeforces Round 56-C. Mishka and the Last Exam(思维+贪心)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left.
There were nn classes of that subject during the semester and on ii-th class professor mentioned some non-negative integer aiai to the students. It turned out, the exam was to tell the whole sequence back to the professor.
Sounds easy enough for those who attended every class, doesn't it?
Obviously Mishka didn't attend any classes. However, professor left some clues on the values of aa to help out students like Mishka:
- aa was sorted in non-decreasing order (a1≤a2≤⋯≤ana1≤a2≤⋯≤an);
- nn was even;
- the following sequence bb, consisting of n2n2 elements, was formed and given out to students: bi=ai+an−i+1bi=ai+an−i+1.
Professor also mentioned that any sequence aa, which produces sequence bb with the presented technique, will be acceptable.
Help Mishka to pass that last exam. Restore any sorted sequence aa of non-negative integers, which produces sequence bb with the presented technique. It is guaranteed that there exists at least one correct sequence aa, which produces the given sequence bb.
Input
The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of sequence aa. nn is always even.
The second line contains n2n2 integers b1,b2,…,bn2b1,b2,…,bn2 (0≤bi≤10180≤bi≤1018) — sequence bb, where bi=ai+an−i+1bi=ai+an−i+1.
It is guaranteed that there exists at least one correct sequence aa, which produces the given sequence bb.
Output
Print nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10180≤ai≤1018) in a single line.
a1≤a2≤⋯≤ana1≤a2≤⋯≤an should be satisfied.
bi=ai+an−i+1bi=ai+an−i+1 should be satisfied for all valid ii.
Examples
input
Copy
4
5 6
output
Copy
2 3 3 3
input
Copy
6
2 1 2
output
Copy
0 0 1 1 1 2
题解:
题目大意是说b[i]=a[i]+a[n-i]的值,并且要保证是递增的,我们可以想,让左边的尽可能小,并且比右边的小,我们就可以去他左边的和右边较小的最大值即可,需要注意的是数据范围是 long long int型的
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n;
cin>>n;
long long int k;
long long int a[200005];
for(int t=0;t<n/2;t++)
{
cin>>k;
if(t==0)
{
a[0]=0;
a[n-1]=k;
}
else
{
a[t]=max(a[t-1],min(a[n-t],k-a[n-t]));
a[n-1-t]=k-a[t];
}
}
for(int t=0;t<n;t++)
{
cout<<a[t]<<" ";
}
return 0;
}
Codeforces Round 56-C. Mishka and the Last Exam(思维+贪心)的更多相关文章
- Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找
The link to problem:Problem - D - Codeforces D. Range and Partition time limit per test: 2 second ...
- Educational Codeforces Round 56 (Rated for Div. 2) ABCD
题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...
- Educational Codeforces Round 56 (Rated for Div. 2)
涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...
- Educational Codeforces Round 56 Solution
A. Dice Rolling 签到. #include <bits/stdc++.h> using namespace std; int t, n; int main() { scanf ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))
题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...
- Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph 【规律 && DFS】
传送门:http://codeforces.com/contest/1093/problem/D D. Beautiful Graph time limit per test 2 seconds me ...
- Educational Codeforces Round 56 (Rated for Div. 2) D
给你一个无向图 以及点的个数和边 每个节点只能用1 2 3 三个数字 求相邻 两个节点和为奇数 能否构成以及有多少种构成方法 #include<bits/stdc++.h> usin ...
- Educational Codeforces Round 56 Div. 2 翻车记
A:签到. B:仅当只有一种字符时无法构成非回文串. #include<iostream> #include<cstdio> #include<cmath> #in ...
随机推荐
- html5基本格式
html5基本格式 学习要点: HTML5 文档的基本格式 2. 开发工具的基本操作 一. 文档基本格式 <!DOCTYPE html> 文档声明,告诉计算机这是一个HTML5文档. ...
- Zookeeper用来干什么?
在Zookeeper的官网上有这么一句话:ZooKeeper is a centralized service for maintaining configuration information, n ...
- 重新拾取:ASP.NET Core WebApi 使用Swagger支持授权认证
园子里已经有很多.NET Core 集成Swagger的文章,但对于使用授权的介绍蛮少的. public static class SwaggerServiceExtensions { public ...
- ActivityMq的使用(小例子)
一.ActivityMq的介绍: 1.什么是消息中间件?与传统的传输通讯有什么区别? 异步,无需等待,消息存放在队列里面. 2.为什么要使用消息中间件? 消息中间件可以解决高并发. 两种通讯方式:01 ...
- codevs 1531山峰
传送门 1531 山峰 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Rocky山脉有n个山峰,一字排开,从西向东 ...
- Java关键字以及一些基础解释
Java Se:Java Me 和Java Ee的基础,允许开发和部署在桌面,服务器,嵌入式环境和实时环境中使用的java程序,支持java web服务开发类 java ee:是目前java技术应用最 ...
- CF-811A
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 5、opencv中的绘图函数
1.目标 a.学习使用 OpenCV 绘制不同几何图形 b. 你将会学习到这些函数: cv2.line(), cv2.circle(), cv2.rectangle(),cv2.ellipse(),c ...
- Manacher's Algorithm 马拉车算法(最长回文串)
这个马拉车算法Manacher‘s Algorithm是用来查找一个字符串的最长回文子串的线性方法,由一个叫Manacher的人在1975年发明的,这个方法的最大贡献是在于将时间复杂度提升到了线性,这 ...
- ASP.NET自定义控件组件开发
ASP.NET的开发都是事件驱动的,现在我们就来为控件添加事件.在事件之前 对委托事件要要熟悉. 其实定义事件的步骤很简单: 1.声明一个委托. 2.定义一个携带事件信息的类. 3.定义事件 4.定义 ...