Codeforces 1189B Number Circle
题目链接:http://codeforces.com/problemset/problem/1189/B
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int a[maxn];
int b[maxn];
int c[maxn];
bool check(int i)
{
if(a[i] < a[i-]+a[i+]) return true;
else return false;
}
int main()
{
int n;
cin >> n;
for(int i = ;i < n;i++)
{
cin >> a[i];
}
sort(a,a+n);
int b1 = ,c1 = ;
for(int i = ;i < n;i++)
{
if(i% == ) c[c1++] = a[i];
else b[b1++] = a[i];
}
for(int i = ;i < c1;i++)
{
a[i] = c[i];
}
for(int i = c1;i < n;i++)
{
a[i] = b[--b1];
}
bool flag = true;
for(int i = ;i < n-;i++)
{
if(!check(i)) flag = false;
}
if(!flag || a[n-] >= a[] + a[n-] || a[] >= a[n-] + a[]) cout << "NO";
else
{
cout << "YES" << endl;
for(int i = ;i < n;i++)
{
cout << a[i] << " ";
}
}
return ;
}
Codeforces 1189B Number Circle的更多相关文章
- Codeforces - 1189B - Number Circle - 贪心
https://codeforc.es/contest/1189/problem/B 优先考虑最大的元素怎么构造.拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了. a数组还开错 ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- Codeforces 27E. Number With The Given Amount Of Divisors (暴力)
题目链接:http://codeforces.com/problemset/problem/27/E 暴力 //#pragma comment(linker, "/STACK:1024000 ...
- Codeforces 235E Number Challenge
http://codeforces.com/contest/235/problem/E 远距离orz......rng_58 证明可以见这里(可能要FQ才能看到) 还是copy一下证明吧: 记 $$f ...
- CodeForces 1151E Number of Components
题目链接:http://codeforces.com/problemset/problem/1151/E 题目大意: n个人排成一个序列,标号为 1~n,第 i 个人的学习成绩为 ai,现在要选出学习 ...
- Codeforces 251C Number Transformation
Number Transformation 我们能发现这个东西是以2 - k的lcm作为一个循环节, 然后bfs就好啦. #include<bits/stdc++.h> #define L ...
- Codeforces 40E Number Table - 组合数学
题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...
- Codeforces 235E. Number Challenge DP
dp(a,b,c,p) = sigma ( dp(a/p^i,b/p^j,c/p^k) * ( 1+i+j+k) ) 表示用小于等于p的素数去分解的结果有多少个 E. Number Challenge ...
随机推荐
- C++笔试题之宏定义相关
1. #define CALC(X) X*X int i; i=CALC(+)/(+); cout<<i<<endl; 输出:31 宏定义在替换处展开为:i = 5+5*5+5 ...
- 人物-IT-胡玮炜:百科
ylbtech-人物-IT-胡玮炜:百科 胡玮炜,女,汉族,1982年出生于浙江东阳,毕业于浙江大学城市学院新闻系,摩拜单车创始人 . 2004年胡玮炜从浙江大学城市学院新闻系毕业后进入<每日经 ...
- Linux下JDK1.6升级1.8版本
先不管是否已安装JDK1.6还是JDK1.7,先下载 jdk-8u45-linux-x64.rpm 然后上传到 /usr/local/src 去.当然其他目录也可以.这里是默认位置 给所有用户 ...
- __init__ 和__new__的区别
__init__和__new__的区别 __init__是当实例对象创建完成后被调用的,然后设置对象属性的一些初始值. __new__是在实例创建之前被调用的,因为它的任务就是创建实例然后返回该实例, ...
- 嵌套循环结合修改IFS环境变量遍历文件数据中IFS的修改一致性
以下这个脚本使用了两个不同的IFS值来解析数据.第一个IFS值解析出/etc/passwd文件中的单独的行.内部for循环接着将IFS值改为冒号,云溪你从/etc/passwd的行中解析出单独的值. ...
- C# FTP操作代码实现
C# FTP 实现方式,废话不多说,直接上代码 public class FtpClient { #region 构造函数 /// <summary> /// 创建FTP工具 /// & ...
- 自定义servlet重写doGet或者doPost方法时,405 method not allowed
自定义servlet public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServlet ...
- 【Luogu】【关卡2-2】交叉模拟(2017年10月)
任务说明:这里也是模拟,但是会混有些别的部分.思维难度不大,但是编写起来会有些难度.
- 对malloc与free函数的浅识
本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: .函数原型及说明: void *mal ...
- java中文乱码转换
String str=URLDecoder.decode(String, "UTF-8")