zoukankan      html  css  js  c++  java
  • CodeForces 382C【模拟】

    活生生打成了大模拟。。。

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int,int>PII;
    const double eps=1e-5;
    const double pi=acos(-1.0);
    //const int mod=1e9+7;
    const int INF=0x3f3f3f3f;
    //http://codeforces.com/contest/382/submission/22599025
    
    const int N=1e5+10;
    int a[N];
    int ans[N],num;
    int n;
    
    void shuchu()
    {
        sort(ans,ans+num);
        int e=unique(ans,ans+num)-ans;
        printf("%d
    ",e);
        for(int i=0; i<e; i++)
            printf("%d ",ans[i]);
    }
    
    map<int,int>mp;
    int mp_num;
    
    int main()
    {
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]);
    
        sort(a+1,a+1+n);
    
        if(n==1)
        {
            puts("-1");
            return 0;
        }
        if(n==2)
        {
            int d=a[n]-a[n-1];
            if(d%2==1)
            {
                num=0;
                ans[num++]=a[n-1]-d;
                ans[num++]=a[n]+d;
                shuchu();
            }
            else
            {
                num=0;
                ans[num++]=a[n-1]-d;
                ans[num++]=a[n]-d/2;
                ans[num++]=a[n]+d;
                shuchu();
            }
            return 0;
        }
        //3 4 4 5
        //1 2 3
        //1 2 4
        int d1,temp,d2,num1,num2;
        int dx1,dx2;
        num2=num1=0;
        d1=a[2]-a[1];
        dx1=2;
        num1++;
        mp_num=1;
        mp[d1]=1;
        for(int i=3; i<=n; i++)
        {
            temp=a[i]-a[i-1];
            if(!mp[temp])
            {
                mp[temp]=1;
                mp_num++;
            }
            if(temp!=d1)
            {
                num2++;
                dx2=i;
                d2=temp;
            }
            else
                num1++;
        }
        if(mp_num>=3)
        {
            puts("0");
            return 0;
        }
        if(!num2)
        {
            num=0;
            ans[num++]=a[1]-d1;
            ans[num++]=a[n]+d1;
            shuchu();
        }
        else
        {
            if(num1==1&&num2==1)
            {
                int res=a[dx2]-d1;
                if(res*2==(a[dx2]+a[dx2-1]))
                {
                    puts("1");
                    printf("%d
    ",res);
                    return 0;
                }
                res=a[dx1]-d2;
                if(res*2==(a[dx1]+a[dx1-1]))
                {
                    puts("1");
                    printf("%d
    ",a[dx1]-d2);
                    return 0;
                }
                puts("0");
            }
            else if(num2==1)
            {
                int res=a[dx2]-d1;
                if(res*2==(a[dx2]+a[dx2-1]))
                {
                    puts("1");
                    printf("%d
    ",res);
                }
                else
                    puts("0");
            }
            else if(num1==1)
            {
                int res=a[dx1]-d2;
                if(res*2==(a[dx1]+a[dx1-1]))
                {
                    puts("1");
                    printf("%d
    ",a[dx1]-d2);
                }
                else
                    puts("0");
            }
            else
                puts("0");
        }
        return 0;
    }
    


  • 相关阅读:
    ASP.Net MVC开发基础学习笔记:五、区域、模板页与WebAPI初步
    解决编写 xml 没有代码提示
    使用Windows Live Writer拉取之前写的博客
    C# 中的语法糖
    在 visual studio 中添加 ILDASM 工具
    EasyUI 学习笔记
    JQuery 学习笔记--02
    AngularJS 中特性(attr)和属性(prop)的区别
    AngularJS 学习笔记--01
    C# 中常用的索引器
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/6777509.html
Copyright © 2011-2022 走看看