Codeforces Round #563 (Div. 2)A
A. Ehab Fails to Be Thanos
题目链接:http://codeforces.com/contest/1174/problem/A
题目
You’re given an array a of length 2n. Is it possible to reorder it in such way so that the sum of the first n elements isn’t equal to the sum of the last n elements?
Input
The first line contains an integer n(1≤n≤1000), where 2n is the number of elements in the array a.
The second line contains 2n space-separated integers a1, a2, …, a2n (1≤ai≤106) — the elements of the array a
Output
If there’s no solution, print “-1” (without quotes). Otherwise, print a single line containing 2n
space-separated integers. They must form a reordering of a. You are allowed to not change the order
Example
input3
1 2 2 1 3 1
output
2 1 3 1 1 2
题意
给你一个长度为2n的数组a,对其重新排序,使得前n和后n元素的总和不想等,若无法排序输出-1,可以则输出重新排序过的长度为2n的数组a。
思路
先判断a数组中的数是否一样,若一样则无法排序使其前n个数之和不为后n个数之和,输出-1;
否则,求出前n与后n个数的和,判断他们是否相等,如果相等,将a排序再顺序输出即可,不想等则直接将原来a数组反向输出即可。
//
// Created by hjy on 19-6-4.
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+;
int main()
{
int n;
while(cin>>n)
{
int a[maxn];
int x;
cin>>x;
a[]=x;
int flag=a[];
int num=;
for(int i=;i<*n;i++)
{
cin>>a[i];
if(a[i]==flag)
num++;
}
if(num==*n)
cout<<"-1"<<endl;
else
{
int l=accumulate(a,a+n,);
cerr<<"l="<<l<<endl;//cerr对提交无影响 int r=accumulate(a+n,a+*n,);
cerr<<"r="<<r<<endl;
if(l!=r) {
for(int i=;i<*n;i++)
{
cout<<a[i]<<' ';
}
cout<<endl;
} else
{
sort(a,a+*n);
for(int i=;i<*n;i++)
cout<<a[i]<<' ';
cout<<endl;
} } }
return ;
}
Codeforces Round #563 (Div. 2)A的更多相关文章
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem
链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...
- Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...
- Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...
- Codeforces Round #563 (Div. 2)C
C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...
- Codeforces Round #563 (Div. 2)B
B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...
- Codeforces Round 563 (Div. 2) 题解
自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- 仿真算法数据结构与算法 C++实现
模拟算法:仿真的全过程,通过改变数学模型参数,进一步观察状态更改这些参数发生变化正当程序. 算法思路:利用随机函数来模拟不可预测发生在自然界.(srand() 和 rand()函数生成一个随机数) 模 ...
- 使用HANDLE_MSG宏简化Win32应用的开发
http://blog.csdn.net/daiyutage/article/details/17241161 Win32应用中的回调函数WndProc用于接收Windows向应用程序直接发送的消息, ...
- [转载]Delphi常用类型及定义单元
原文地址:Delphi常用类型及定义单元作者:沧海一声笑 Delphi常用类型及定义单元-总结 sndplaysound mmsystem Type Unit Date ...
- DataSet 互相转换 List
/// <summary> /// List <-> DataSet /// </summary> public class IListDataSet { /// ...
- MEF 插件式开发 - WPF 初体验
原文:MEF 插件式开发 - WPF 初体验 目录 MEF 在 WPF 中的简单应用 加载插件 获取元数据 依赖注入 总结 MEF 在 WPF 中的简单应用 MEF 的开发模式主要适用于插件化的业务场 ...
- wpf 深度复制控件,打印控件
原文:wpf 深度复制控件,打印控件 <Window x:Class="WpfApp2.MainWindow" xmlns="http://schemas.micr ...
- GAC的一种非官方实现方式
1.GAC简介 全局程序集缓存(Global Assembly Cache, GAC)计算机范围内的代码缓存,它存储专门安装的程序集,这些程序集由计算机上的许多应用程序共享.在全局程序集缓存中部署的应 ...
- mariadb 允许远程访问
进入MariaDB服务器,将mysql.user的host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%. 1 MariaDB [(none)]> ...
- WPF 鼠标在图片Image上悬停时切换更改设置图片源Source
// 无效的写法,图片不会被切换 <Image Margin="0,0,0,0" Width="50" Height="50" Sou ...
- Visual Studio 2017报表RDLC设计器与工具箱中Report Viewer问题
原文:VS2017入门 RDLC入门之01 本系列所有内容为网络收集转载,版权为原作者所有. VS2017初始安装后和VS2015一样,都没有ReportDesigner/ReportViewer R ...