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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  4. Equal Sides Of An Array

    参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...

  5. Int,Long比较重使用equal替换==

    首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...

  6. 无法解决 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 ...

  7. LeetCode Minimum Moves to Equal Array Elements II

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...

  8. LeetCode Minimum Moves to Equal Array Elements

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...

  9. 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 ...

  10. why happen "WaitHandles must be less than or equal to 64"

    一.背景: 在一个项目中碰到大数据插入的问题,一次性插入20万条数据(SQL Server),并用200个线程去执行,计算需要花费多少时间,因此需要等200个线程处理完成后,记录花费的时间,需要考虑的 ...

随机推荐

  1. Java内存管理和回收

    转载自http://blog.csdn.net/cutesource/article/details/5906705 JVM内存组成结构 JVM栈由堆.栈.本地方法栈.方法区等部分组成,结构图如下所示 ...

  2. 解析xml的4种方法详解(转)

    http://blog.csdn.net/jzhf2012/article/details/8532873 1. 介绍 1)DOM(JAXP Crimson解析器)         DOM是用与平台和 ...

  3. 分享一个linux中测试网站是否正常的shell脚本

    #! /bin/bash #Author=Harry CheckUrl() { #<==定义函数,名字为CheckUrl timeout=5 #<==定义wget访问的超时时间,超时就退出 ...

  4. layui动态渲染select等组件并初始化赋值失败

    描诉:有一个用户信息form表单,其中有部门单选框,数据库中有一张dept(部门)表,要动态渲染出所有部门,并默认选中用户所在部门 关键代码: html页面 <div class="l ...

  5. [BZOJ 3771] Triple(FFT+容斥原理+生成函数)

    [BZOJ 3771] Triple(FFT+生成函数) 题面 给出 n个物品,价值为别为\(w_i\)且各不相同,现在可以取1个.2个或3个,问每种价值和有几种情况? 分析 这种计数问题容易想到生成 ...

  6. [LeetCode] 137. 只出现一次的数字 II

    题目链接 : https://leetcode-cn.com/problems/single-number-ii/ 题目描述: 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三 ...

  7. Cocos2d-x-javaScript 的webSocket的代码

    var WebSocket = WebSocket || window.WebSocket || window.MozWebSocket; var WebSocketManager = cc.Clas ...

  8. Laravel 学习笔记之数据库操作——Eloquent ORM

    1. 时间戳 默认情况下在使用ORM操作数据库进行添加.修改数据时, created_at 和 updated_at列会自动存在于数据表中,并显示的是 ‘2017’格式,如果想以 Unix时间戳格式存 ...

  9. 广播即时通信src和des

    package 第十二章; import java.io.IOException; import java.net.DatagramPacket; import java.net.InetAddres ...

  10. ST7735和ST7789驱动

    /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __LCD_H #de ...