zoukankan      html  css  js  c++  java
  • [POJ 2356] Find a multiple

    Find a multiple
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 6535   Accepted: 2849   Special Judge

    Description

    The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000. This numbers are not necessarily different (so it may happen that two or more of them will be equal). Your task is to choose a few of given numbers ( 1 <= few <= N ) so that the sum of chosen numbers is multiple for N (i.e. N * k = (sum of chosen numbers) for some natural number k).

    Input

    The first line of the input contains the single number N. Each of next N lines contains one number from the given set.

    Output

    In case your program decides that the target set of numbers can not be found it should print to the output the single number 0. Otherwise it should print the number of the chosen numbers in the first line followed by the chosen numbers themselves (on a separate line each) in arbitrary order.
    If there are more than one set of numbers with required properties you should print to the output only one (preferably your favorite) of them.

    Sample Input

    5
    1
    2
    3
    4
    1
    

    Sample Output

    2
    2
    3
    

    Source

    Ural Collegiate Programming Contest 1999
     
    鸽巢定理,注意代码实现的细节,0MS ac
    #include<iostream>
    #include<cstdlib>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    #define N 10010
    
    struct Node
    {
        int x,y,s; //下标,余数,前缀和
        bool operator <(const Node &t)const
        {
            if(y!=t.y) return y<t.y;
            return x<t.x;
        }
    }p[N];
    
    int main()
    {
        int n;
        int flag;
        int a[N];
        while(scanf("%d",&n)!=EOF)
        {
            flag=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                p[i].s=p[i-1].s+a[i];
                p[i].x=i;
                p[i].y=p[i].s%n;
                if(!flag && p[i].y==0)
                {
                    flag=1;
                    printf("%d
    ",i);
                    for(int j=1;j<=i;j++) printf("%d
    ",a[j]);
                }
            }
            if(flag) continue;
            sort(p+1,p+n+1);
            for(int i=2;i<=n;i++)
            {
                if(p[i].y==p[i-1].y)
                {
                    int &l=p[i-1].x;
                    int &r=p[i].x;
                    printf("%d
    ",r-l);
                    for(int j=l+1;j<=r;j++) printf("%d
    ",a[j]);
                    break;
                }
            }
        }
        return 0;
    }
    趁着还有梦想、将AC进行到底~~~by 452181625
  • 相关阅读:
    iOS启动项目(二)引入第三方库
    Swift技巧(九)CGImage To CVPixelBuffer
    Swift技巧(四)设置照片尺寸和格式
    Swift技巧(十) Protocol 的灵活使用
    Alamofire5.0.0 以上报错
    Swift技巧(八)CVPixelBuffer To CGImage
    Swift技巧(十一)重写运算符
    Swift技巧(五)设置圆角的代码
    Swift技巧(七)重识 Array
    Swift技巧(六)设置按钮状态并更改
  • 原文地址:https://www.cnblogs.com/hate13/p/4474805.html
Copyright © 2011-2022 走看看