标签:printf color ons max string cstring std size sum
抽屉原理:
#include<cstdio> #include<cstring> const int maxn = 1e5 + 5; int num[maxn], hash[maxn], sum[maxn]; int n; int main() { while (scanf("%d", &n) != EOF){ memset(hash, 0, sizeof(hash)); for (int i = 1; i <= n; ++i) scanf("%d", &num[i]); int t = 1, s = 1; for (int i = 1; i <= n; ++i) { sum[i] = (sum[i - 1] + num[i]) % n; if (sum[i] == 0){ t = i; break; } if (hash[sum[i]] > 0){ s = hash[sum[i]] + 1; t = i; break; } hash[sum[i]] = i; } printf("%d\n", t - s + 1); for (int i = s; i <= t; ++i) printf("%d\n", num[i]); } }
Find a multiple POJ - 2356 (抽屉原理)
标签:printf color ons max string cstring std size sum
原文地址:https://www.cnblogs.com/ALINGMAOMAO/p/9902103.html