题意:首先输入c n,接着是n个数,问你有没有k个数(1<=k<=n),使得其和能整除c
输出其对应下标,只输出一组符合条件的就行;
分析:http://blog.csdn.net/bigsungod/article/details/41450729
代码:
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <limits.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <functional>
#define N 100010
#define LL long long
#define mem(a) memset(a,0,sizeof(a));
#define mem_1(a) memset(a,-1,sizeof(a));
using namespace std;
int n,c;
int f[N];
int sum[N];
int pos[N];
void work()
{
int j;
memset(pos, -1, sizeof(pos));
pos[0] = 0;
for (int i = 1; i <= n; i++)
if (pos[sum[i]] == -1)
pos[sum[i]] = i;
else
{
for ( j = pos[sum[i]] + 1; j < i; j++)
printf("%d ", j);
printf("%d\n", j);
return;
}
}
int main()
{
while(scanf("%d%d", &c,&n)){
if(c==0&&n==0)
break;
for (int i = 1; i <= n; i++)
scanf("%d", &f[i]);
sum[0] = f[0] = 0;
for (int i = 1; i <= n; i++)
sum[i] = (sum[i - 1] + f[i]) % c;
work();
}
return 0;
}