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个线程处理完成后,记录花费的时间,需要考虑的 ...
随机推荐
- python+selenium切换窗口(获取句柄信息)
current_window_handle:获得当前窗口句柄: window_handles:返回所有窗口的句柄到当前会话: switch_to.window(suoyou[0]) ========= ...
- 不是我吹,Lambda这个坑你肯定不知道!
上周有小伙伴反馈zk连接很慢.整理出zk连接的关键逻辑如下: public class ClientZkAgent { //单例模式 private static final ClientZk ...
- SSM框架之AOP、动态代理、事务处理相关随笔
AOP: 原理:底层利用动态代理(两种动态代理技术都使用了) 两种实现方案: 第一种:JDK动态代理技术 实现的InvocationHandler接口,要想实现某个类的动态代理对象,必须有接口有实现类 ...
- glVertexAttribPointer 顶点数据解析方式
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); 第一个参数指定从索引0开始取数据,与顶点着色器中layout(location=0)对应. ...
- 如何在centos6和centos7上部署nfs共享服务器和客户端
nfs共享服务为中小型企业在存储上提供了有效的节省空间,许多大型的网站也在使用nfs,如百度和阿里等,下面结合自己所学的知识,阐述如何在centos6和centos7下配置nfs.注:除了必要的说明外 ...
- Java中HashSet和HashMap
Set中存储元素为什么不重复(即使hashCode相同)? HashSet中存放自定义类型元素时候,需要重写对象中的hashCode方法和equals方法, HashSet中存放自定义类型元素时候,需 ...
- Node.js+webSocket
// 引入WebSocket模块 var ws = require('nodejs-websocket') var PORT = 3030 var server = ws.createServer(f ...
- python学习笔记(14):可视化分析
一.Matplotlib 1.用于创建出版质量图表的绘图工具库 2.目的的为Python构建一个Matlab式的绘图接口 3.import matplotlib.pyplot as plt:pyplo ...
- CSS样式 换行
强制不换行 div{ white-space:nowrap; } 自动换行 div{ word-wrap: break-word; word-break: normal; } 强制英文单词断行 div ...
- css控制文本内容显示省略号
1,单行文字显示省略号 div{ width:200px; overflow:hideen; white-space:nowrap; text-overflow:ellipsis; } 2,多行文字显 ...