C. Almost Equal
n个数字全排成一个圈,满足任意相邻n个之和之间最大最小值之差不超过1
n为偶数时
不存在
n为奇数,构造
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
ll A[];
ll N;
ll B[];
bool check()
{
ll a,b,c,t;
c=A[*N]+A[]+A[]; t=A[*N-]+A[*N]+A[];
a=min(c,t);
b=max(c,t); for(int i=; i<=*N-; i++)
{
t=A[i]+A[i+]+A[i+];
a=min(a,t);
b=max(b,t);
}
// cout<<a<<b<<endl;
return (b-a<=); }
int main()
{
sc(N);
ll k=;
if(N%==){
puts("NO");
return ;
} for(int i=; i<=N; i++)
{
if(i&){
A[i]=k;
k++;
A[i+N]=k;
k++;
}else {
A[i+N]=k;
k++;
A[i]=k;
k++;
}
} // if(check())
{
puts("YES"); for(int i=; i<=*N; i++)
{
cout<<A[i]<<' ';
}
}
// cout<<ans<<'\n';
}
C. Almost Equal的更多相关文章
- [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二
Given a non-empty integer array, find the minimum number of moves required to make all array element ...
- [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- Equal Sides Of An Array
参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...
- Int,Long比较重使用equal替换==
首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...
- 无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS"
无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS" 之间 2011-0 ...
- LeetCode Minimum Moves to Equal Array Elements II
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...
- LeetCode Minimum Moves to Equal Array Elements
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...
- conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation
在SQL SERVICE做关联查询的时候遇到了"conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI ...
- why happen "WaitHandles must be less than or equal to 64"
一.背景: 在一个项目中碰到大数据插入的问题,一次性插入20万条数据(SQL Server),并用200个线程去执行,计算需要花费多少时间,因此需要等200个线程处理完成后,记录花费的时间,需要考虑的 ...
随机推荐
- Go语言入门篇-复合数据类型
复合数据类型 主要讨论四种类型——数组.slice.map和结构体 数组和结构体聚合类型 --数组和结构体都是有固定内存大小的数据结构 --数组:由同构的元素组成——每个数组元素都是完全相同的类型 ...
- selenium:css_selector定位详解(css selector和xpath的比较)
selenium使用css selector和xpath的比较 selenium提供的定位方式(常用) ID NAME CLASS CSS SELECTOR XPATH 推荐的定位方式的优先级 优 ...
- centos6.9 安装mysql8
centos6.9 安装 mysql8 # 安装mysql8 1.下载https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-2.el6.x86 ...
- 你知道 Java 类是如何被加载的吗?
前言 最近给一个非 Java 方向的朋友讲了下双亲委派模型,朋友让我写篇文章深度研究下JVM 的 ClassLoader,我确实也好久没写 JVM 相关的文章了,有点手痒痒,涂了皮炎平也抑制不住的那种 ...
- Servlet,HttpServletRequest 和 HttpServletResponse
今天是周六,老子加班,还可吧, 哈哈哈哈哈哈哈哈哈哈哈哈哈 此次更新的内容是HttpServletRequest 和 HttpServletResponse 昨天复习了一部分内容,今天又把剩下的看完. ...
- Hibernate-Criteria学习笔记
hibernate_jpa注解 目前最新版的hibernate,5.2,底层整合了jpa,用idea的hibernate工具生成实体时,实体包含了注解的配置文件,缺一不可 如,用户类实体,生成之后是这 ...
- 基于bs4库的HTML查找方法
基于bs4库的HTML查找方法 find_all方法 <>.find_all(name,attrs,recursive,string,**kwargs) 返回一个列表类型,内部存储查找的结 ...
- W10: Warning: Changing a readonly file 解决办法
在linux上编辑文件的时候,明明是使用的root登录的,可是这种至高无上的权限在按下i的时候被那串红色错误亵渎了W10: Warning: Changing a readonly file. 困扰两 ...
- shell脚本又是什么?
操作系统命令的组合称为Shell脚本: 一个Shell脚本主要由原本需要在命令行输入的命令组成,或在一个文本编辑器中,用户可以使用脚本来把一些常用的操作组合成一组串行.主要用来书写这种脚本的语言叫做脚 ...
- CSP-S全国模拟赛第二场 【nan】
A.count 本场比赛最难的题... 隔板法组合数容斥 xjb 搞搞就好了 //by Judge #include<cstdio> #include<iostream> #d ...