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
  • 相关阅读:
    gvim在windows下的一些小技巧
    解决eclipse在ubuntu下无法找到jdk方法
    ubuntu 12.04 下安装wireshark
    使用坚果云同步数据
    Windows WMIC命令详解 (Windows Management Instrumentation Commandline)
    ubuntu 12.04 配置指南
    CHROME自定义样式扩展 —— STYLISH
    地漏
    卫生间装修,想要坐便改成蹲便,地面需要加高多少?
    不锈钢橱柜
  • 原文地址:https://www.cnblogs.com/hate13/p/4474805.html
Copyright © 2011-2022 走看看