zoukankan      html  css  js  c++  java
  • Codeforces1343B Balanced Array(思维,奇数偶数)

    B. Balanced Array
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a positive integer nn, it is guaranteed that nn is even (i.e. divisible by 22).

    You want to construct the array aa of length nn such that:

    • The first n2n2 elements of aa are even (divisible by 22);
    • the second n2n2 elements of aa are odd (not divisible by 22);
    • all elements of aa are distinct and positive;
    • the sum of the first half equals to the sum of the second half (i=1n2ai=i=n2+1nai∑i=1n2ai=∑i=n2+1nai).

    If there are multiple answers, you can print any. It is not guaranteed that the answer exists.

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1t1041≤t≤104) — the number of test cases. Then tt test cases follow.

    The only line of the test case contains one integer nn (2n21052≤n≤2⋅105) — the length of the array. It is guaranteed that that nn is even (i.e. divisible by 22).

    It is guaranteed that the sum of nn over all test cases does not exceed 21052⋅105 (n2105∑n≤2⋅105).

    Output

    For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) satisfying conditions from the problem statement on the second line.

    Example
    input
    Copy
    5
    2
    4
    6
    8
    10
    
    output
    Copy
    NO
    YES
    2 4 1 5
    NO
    YES
    2 4 6 8 1 3 5 11
    NO

    找规律
    奇数个奇数的和是奇数,奇数个偶数的和是偶数,故不等
    奇数 + 奇数 = 奇数 奇数+偶数 = 奇数
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 #define scanf scanf_s
     6 
     7 int T;
     8 long long n, m;
     9 
    10 int main() {
    11     scanf("%d", &T);
    12     while (T--) {
    13         int n;
    14         scanf("%d", &n);
    15         if ((n/2) % 2 == 0) {
    16             printf("YES
    ");
    17             for (int i = 1; i <= n / 2; i++)
    18                 printf("%d ", i * 2);
    19             for (int i = 1; i < n / 2; i++)
    20                 printf("%d ", i * 2 - 1);
    21             printf("%d
    ", n + ((n/2)-1) * 1);
    22         }
    23         else
    24             printf("NO
    ");
    25     }
    26 
    27     return 0;
    28 }
  • 相关阅读:
    百度地图API地理位置和坐标转换
    解决Myeclipse中导入自定义的配色方案后,JSP中的js代码块为白色背景的问题
    Windows 平台下Myeclipse 10 中SVN 插件使用教程(TortoiseSVN)
    Java代码通过API操作HBase的最佳实践
    HBase中多Filter查询示例
    使用Ant编译和构建项目指南
    如何在Google Play商店发布多个版本apk
    Android 设备管理API概览(Device Administration API)
    Android呼叫管理服务之会话发起协议(SIP)API
    Android基础知识之String类使用详解
  • 原文地址:https://www.cnblogs.com/sineagle/p/14488399.html
Copyright © 2011-2022 走看看