poj 3370 Halloween treats

这个题跟http://poj.org/problem?id=2356;是一样,这里就不解释了http://www.cnblogs.com/bo-tao/archive/2012/07/27/2611306.html

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

#include<string>

#define LL long long

using namespace std;



int main(  )

{

    int num[100024],a;

    int n , m;

    while( scanf( "%d %d",&n,&m ),n|m )

    {

        bool flag = false;

        LL sum = 0;

        memset( num , 0 , sizeof( num ) );

        for( int i = 1 ;i <= m ; i ++)

        {

             scanf( "%d",&a );

             if( flag ) continue;

             sum += a;

             int t = (int)(sum%n);

             if( t == 0 ){

                    flag = true;

                    for( int j = 1 ; j < i ; j ++ )

                         printf( "%d ",j );

                    printf( "%d\n",i );

             }

             else if( num[t] == 0 )

                      num[t] = i;

             else{

                 flag = true;

                 for( int j = num[t] + 1 ; j < i ; j++ )

                      printf( "%d ",j );

                 printf( "%d\n",i );

             }

        }

    }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(poj)