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
  • 相关阅读:
    列表组件抽象(5)-简洁易用的表格组件
    列表组件抽象(4)-滚动列表及分页说明
    列表组件抽象(3)-分页和排序管理说明
    列表组件抽象(2)-listViewBase说明
    列表组件抽象(1)-概述
    简单实用的进度条加载组件loader.js
    简单封装分页功能pageView.js
    为什么不能用速度与时间的关系去实现动画
    java开发面试题目及答案(持续更新)
    Java Web目前主流比较成熟的框架以及正在兴起的框架
  • 原文地址:https://www.cnblogs.com/hate13/p/4474805.html
Copyright © 2011-2022 走看看