zoukankan      html  css  js  c++  java
  • POJ 2356 Find a multiple( 鸽巢定理简单题 )


    链接:传送门

    题意:题意与3370类似

    注意:注意输出就ok,输出的是集合的值不是集合下标


    /*************************************************************************
        > File Name: poj2356.cpp
        > Author:    WArobot 
        > Blog:      http://www.cnblogs.com/WArobot/ 
        > Created Time: 2017年04月30日 星期日 12时24分20秒
     ************************************************************************/
    
    #include<cstdio>
    #include<cstring>
    using namespace std;
    
    int a[10100] , vis[10100];
    int S , N;
    
    void print(int s,int e){
    	printf("%d
    ",e-s+1);
    	for(int i=s;i<=e;i++)	printf("%d
    ",a[i]);
    }
    int main(){
    	int ok;
    	while(~scanf("%d",&N)){
    		ok = 0;
    		for(int i=1;i<=N;i++)	scanf("%d",a+i);
    		memset(vis,0,sizeof(vis));
    		S = 0;
    		for(int i=1;i<=N;i++){
    			S = ( S + a[i] ) % N;
    			if( S==0 ){
    				print( 1 , i );	break;
    			}
    			if( vis[S] ){
    				print( vis[S]+1 , i );	break;
    			}
    			vis[S] = i;
    		}
    	}
    	return 0;
    }
  • 相关阅读:
    1370
    1336
    1298
    1289
    Buy Tickets(poj2828)
    The Balance(poj2142)
    1067
    Lightoj1011
    1319
    Back to Underworld(lightoj 1009)
  • 原文地址:https://www.cnblogs.com/WArobot/p/6789285.html
Copyright © 2011-2022 走看看