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 ...
随机推荐
- 2013各大IT公司薪资标准
以此鼓励自己 :http://jinhua.19lou.com/forum-874-thread-115901362964023509-1-1.html 以下三个是老大级别的公司 [微软] 研 ...
- python学习笔记:第七天(函数)
Python3 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率. 与C一样,Python提供了许多内建函数,比如print().同 ...
- DenseNet算法详解——思路就是highway,DneseNet在训练时十分消耗内存
论文笔记:Densely Connected Convolutional Networks(DenseNet模型详解) 2017年09月28日 11:58:49 阅读数:1814 [ 转载自http: ...
- 微软面试题:鸡蛋从第N层及以上的楼层落下会摔破
from:https://blog.csdn.net/qq_18425655/article/details/52326709 题目: 有一栋楼共100层,一个鸡蛋从第N层及以上的楼层落下来会摔破 ...
- mvn使用记录
1. mvn dependency:copy-dependencies 会导出到targed/dependency 下面 2. mvn dependency:copy-dependencies -Do ...
- python-函数用法
Python 一.lower() 方法转换字符串中所有大写字符为小写. lower()方法语法: str.lower() 参数 无. 返回值 返回将字符串中所有大写字符转换为小写后生成的字符串. 练习 ...
- hdu-5858 Hard problem(数学)
题目链接: Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Spring 配置 详细
一.连接池概述 数据库连接池概述: 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指 ...
- 「NOIP2013」「LuoguP1967」货车运输(最大生成树 倍增 LCA
题目描述 AA国有nn座城市,编号从 11到nn,城市之间有 mm 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 qq 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重的情况下,最 ...
- Jasper:SAOP API 函数
ylbtech-Jasper:SAOP API 函数 1.设备API返回顶部 1. 设备 设备 API 可以访问详细的设备(SIM 卡)信息,包括当前会话.您也可以更改属性值. API 调用 描述 A ...