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 ...
随机推荐
- POJ 2497 Strategies
题意:有三个人,Bill, Steve and Linus,他们参加竞赛,给出竞赛的题目和比赛时间,然后给出每道题需要的时间(他们解同一道题花的时间相同),然后他们有不同的策略来做题.每道题的得分为当 ...
- 使用jedisPool管理jedis,使用jedis操作redis
ps:jedis是redis在java中的客户端操作工具 package com.test; 2 3 import java.util.HashMap; 4 import java.util.Iter ...
- EmbarassedBirds全体开发人员落泪
Github (李昆乘,赖展飞) 现阶段还在开发后期,API调试过程中. 本周无法上线. 全体开发人员留下眼泪. 贴上几个功能图, 给大家尝尝鲜吧! 现阶段仍在API调试 因为队员李昆乘经常出去玩没有 ...
- 《java编程思想》:异常丢失
finally子句的不恰当使用,会造成异常的丢失,此处列举两种典型的错误使用示例.编程中要避免这种情况 示例一: try{ throw new ExceptionA(); }finally{ thro ...
- VirtualBox文件系统已满--磁盘扩容
第1步:为virtualbox虚拟电脑扩容 进入命令行,以Windows系统为例 (特别注意空格和中文) 1.启动CMD命令行,进入VirtualBox的安装目录.如 运行:cmd C:\Users\ ...
- BLE Mesh网络协议综述
0 引言 自2012年蓝牙4.0规范推出之后,全新的蓝牙低功耗(BLE)技术由于其极低的运行和待机功耗.低成本和跨厂商互操作性,3 ms低延迟.AES-128加密等诸多特色,可以用于计步器.心律监视器 ...
- Windows C/C++调试
windows兼容dirent.h error c4996: 'fopen': This function or variable may be unsafe This file requires _ ...
- Oracle查询24小时制的时间格式
select to_date('2016-11-11 13:42:27', 'yyyy/mm/dd hh24:mi:ss') from dual.
- jvm虚拟机androidy移植-编译篇
有这个必要吗?都过时的东西了,android上的Dalvik效率不够高吗,不够逼格吗? 是的但有总东西是不是我们这些码农能决定的,领导和项目需求才是你要关心的,毕竟工作要向领导汇报,项目要去挣钱钱,但 ...
- [codeforces274b]Zero Tree(树形dp)
题意:给出一棵树,每个点有权值,每次操作可以对一个联通子集中的点全部加1,或者全部减1,且每次操作必须包含点1,问最少通过多少次操作可以让整棵树每个点的权值变为0. 解题关键:自底向上dp,记录up, ...