zoukankan      html  css  js  c++  java
  • luogu5823 课表的排列

    题目链接

    problem

    构造一个长度为(2n)的数列。满足:
    1.[1,n]中每个数字恰好出现两次。
    2.将所有相同数字之间相隔的数字个数排序后,得到公差为1的等差数列。
    保证n为奇数。

    solution

    挺妙的一道题(来自蒟蒻的呻吟~)

    发现n是奇数。那么将序列分为四部分A,B,C,D。长度分别为k,k+1,k,k+1。让A与C互为相反串,B与D互为相反串。

    这样发现,A与C所造成的贡献分别是:k+1,k+3,k+5···。B与D所造成的贡献分别是:k,k+2,k+4,k+6···。合起来恰好是一个等差数列。

    一开始自己误加了一个条件(首项必须唯一/nc)

    code

    /*
    * @Author: wxyww
    * @Date:   2019-12-17 18:58:18
    * @Last Modified time: 2019-12-17 19:08:10
    */
    #include<cstdio>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<ctime>
    using namespace std;
    typedef long long ll;
    
    ll read() {
    	ll x = 0,f = 1;char c = getchar();
    	while(c < '0' || c > '9') {
    		if(c == '-') f = -1; c = getchar();
    	}
    	while(c >= '0' && c <= '9') {
    		x = x * 10 + c - '0'; c = getchar();
    	}
    	return x * f;
    }
    
    int main() {
    	int n = read();
    	for(int i = 1;i <= n;++i) printf("%d ",i);
    	for(int i = n / 2;i >= 1;--i) printf("%d ",i);
    	for(int i = n;i > n / 2;--i) printf("%d ",i);
    
    	return 0;
    }
    
  • 相关阅读:
    烦人的警告 Deprecated: convertStrings was not specified when starting the JVM
    Python 推送RabbitMQ
    JavaScript-json数组排序
    CSS-返回顶部代码
    CSS-页面滑屏滚动原理
    CSS-图像映射
    CSS-下拉导航条
    CSS-background-position百分比
    CSS- 横向和纵向时间轴
    JavaScript-闭包深入浅出
  • 原文地址:https://www.cnblogs.com/wxyww/p/luogu5823.html
Copyright © 2011-2022 走看看