Codeforces - 1189B - Number Circle - 贪心
https://codeforc.es/contest/1189/problem/B
优先考虑最大的元素怎么构造。拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了。
a数组还开错了。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[100005];
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
while(~scanf("%d", &n)) {
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
sort(a+1,a+1+n);
swap(a[n],a[n-1]);
bool fail=false;
for(int i=2;i<=n-1;++i){
if(a[i]>=a[i-1]+a[i+1])
fail=true;
}
if(a[1]>=a[n]+a[2])
fail=true;
if(a[n]>=a[n-1]+a[1])
fail=true;
if(fail)
puts("NO");
else{
puts("YES");
for(int i=1;i<=n;++i){
printf("%d%c",a[i]," \n"[i==n]);
}
}
}
}
Codeforces - 1189B - Number Circle - 贪心的更多相关文章
- Codeforces 1189B Number Circle
题目链接:http://codeforces.com/problemset/problem/1189/B AC代码: #include<bits/stdc++.h> using names ...
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
- CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...
- Codeforces C. Split a Number(贪心大数运算)
题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...
- Codeforces 980E The Number Games 贪心 倍增表
原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...
- Codeforces 980E The Number Games - 贪心 - 树状数组
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一颗有$n$个点的树,$i$号点的权值是$2^{i}$要求删去$k$个点,使得剩下的点仍然连通,并且总权值和最大,问删去的所有点的编号. ...
- Codeforces 346C Number Transformation II 贪心(复杂度计算)
题意及思路:https://www.cnblogs.com/liuzhanshan/p/6560499.html 这个做法的复杂度看似是O(n ^ 2),实际上均摊是O(n)的.我们考虑两种极端数据: ...
- CodeForces 176A Trading Business 贪心
Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
随机推荐
- Centos安装ifstat统计网络流量
原文地址: http://www.winvps.org/post/504.html 下载 ifstat , http://gael.roualland.free.fr/ifstat/ifstat-1 ...
- C# 获得系统环境
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- EwoMail 邮件服务器安装
ewomail 安装及使用 主页:http://www.ewomail.com/ 开源版主页:http://www.ewomail.com/list-9.html 开源版文档:http://doc.e ...
- c++函数参数或返回值为函数指针
C++中函数指针的形式为:返回值类型 + 参数类型,函数没有值类型,但是却可以声明函数的指针,因为函数是可寻址的,存放在内存中的代码段,可以从指针访问. 函数指针可以声明为: void (*pF)(v ...
- Rust(一)介绍 安装
目录 Rust安装 Rust介绍: Windows 安装步骤: Helle world 创建项目文件夹: 写并执行程序: Rust安装 安装过程简单快捷,直接参照官网即可,Rust安装 Rust介绍: ...
- robot framework 自动化框架环境搭建
win10 64位系统 1.安装python2.7.15 在官网https://www.python.org/downloads/下载对应版本 在同一台电脑上同时安装Python2和Python3参考 ...
- 英语单词debug
来源——docker官网首页https://www.docker.com/ 翻译 vt. 调试,排除故障,除错,改正有毛病部分 过去式 debugged 过去分词 debugged 现在分词 debu ...
- Python3解leetcode Min Cost Climbing Stairs
问题描述: On a staircase, the i-th step has some non-negative cost cost[i]assigned (0 indexed). Once you ...
- Win10真正好用之处
第一步. 关闭无用服务 刚装好Win10的时候,整部电脑响应很慢,有时什么都不做,硬盘灯也能狂闪半天.很明显,这是微软爸爸默认开启的服务未被及时关闭所致. 网上有很多文章指导新手如何关闭系统服务,但 ...
- ubuntu 16.4下hadoop配置伪分布式时出现的坑
在ubuntu16.4下spark的单机/伪分布式配置我在此就不在一一赘述,详情请点击如下连接: Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04 我出现问题是 ...