zoukankan      html  css  js  c++  java
  • CodeForces 1205A Almost Equal(数学规律)

    题目链接:https://vjudge.net/problem/CodeForces-1205A

    题目大意:给你一个n,问你能不能用1~2*n这2*n个数组成一个环,在环上每个相邻的n个数的和相差不大于1

      (数学不好只能找规律了QAQ)首先两个相邻的n个数和肯定不会相等的,因为两个相邻的n个数中只有一位不同,而数字没有重复的。那么我们就只能考虑让一个比另一个大1,2*n个元素的环选连续的n个数的和做一个数,那么一共有2*n个情况, 每个元素被计算n次,总和就是(1+2+...+2*n)*nn个数平均数就是总和除以2*n,也就是((1+2*n)*(2*n)/2)/(2*n) = n*(1+2n)/2,当n是偶数的时候,1+2n是奇数,偶数乘奇数还是偶数,这样所有的2*n个数组成的数就不能组成相差都大于1的情况了,当n是奇数的时候,就是奇数乘奇数,那么他的平均数就可以一个是偶数(除以2向下取整),一个是奇数(+1除以2向下取整)所以当n是奇数的时候有解,偶数的时候无解.至于构造吗....就只能打出来符合条件的全排列找规律了......结果是对于下标为1~n,满足如果i是偶数a[i] = 2*i-1, 如果i是奇数,a[i] = 2*i, 至于i+n~2*n的情况则正好相反. 

    #include<set>
    #include<map>
    #include<list>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdio>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define endl '\n'
    #define rtl rt<<1
    #define rtr rt<<1|1
    #define lson rt<<1, l, mid
    #define rson rt<<1|1, mid+1, r
    #define maxx(a, b) (a > b ? a : b)
    #define minn(a, b) (a < b ? a : b)
    #define zero(a) memset(a, 0, sizeof(a))
    #define INF(a) memset(a, 0x3f, sizeof(a))
    #define IOS ios::sync_with_stdio(false)
    #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    typedef pair<ll, ll> P2;
    const double pi = acos(-1.0);
    const double eps = 1e-7;
    const ll MOD =  1000000007LL;
    const int INF = 0x3f3f3f3f;
    const int _NAN = -0x3f3f3f3f;
    const double EULC = 0.5772156649015328;
    const int NIL = -1;
    template<typename T> void read(T &x){
        x = 0;char ch = getchar();ll f = 1;
        while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
        while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
    }
    const int maxn = 2e5+10;
    int arr[maxn];
    int main(void) {
        int times = 1e2;
        while(times--) {
            ll sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
            int times2 = 1e6;
            while(times2--) {
                ll res = rand()%2;
                if (times2&1) {
                    sum1 += 7LL*res;
                    sum2 += 3LL*res;
                }
                else {
                    sum1 += 3LL*res;
                    sum2 += 7LL*res;
                }
                sum3 += 5LL*res;
                sum4 += 5LL*res;
            }
            cout << sum1 << ' ' << sum2 << ' ' << sum3 << ' ' << sum4 << endl;
        }
        return 0;
    }
  • 相关阅读:
    Linux内核之 I/O多路复用
    Linux内核之 页高速缓存与页回写
    Linux内核之 块I/O层及I/O调度
    Linux内核之 文件I/O
    C++雾中风景15:聊聊让人抓狂的Name Mangling
    音频数据增强及python实现
    深度学习中“过拟合”的产生原因和解决方法
    资料-资源(不定期更新)
    论文翻译:2020_Acoustic Echo Cancellation Challenge Datasets And Testingframework
    语音信号处理概念
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12425932.html
Copyright © 2011-2022 走看看