NC220554. 切圈圈
描述
输入描述
输入第一行给出一个正整数,代表测试数据的组数
每组数据在第一行给出一个整数,然后在第二行给出
个整数
输出描述
对于每组输入在一行中输出一个正整数,代表最多片段的个数
示例1
输入:
2 4 4 2 -4 -2 5 2 -3 4 -4 1
输出:
1 2
C++(clang++11) 解法, 执行用时: 342ms, 内存消耗: 5580K, 提交时间: 2021-04-27 15:34:20
#include <bits/stdc++.h> using namespace std; int t, n, a[10000]; signed main() { cin >> t; while (t--) { cin >> n; int su = 0, an = 0; map<int,int>ma; while (n--) { int x; cin >> x; an = max(an, ++ma[su += x]); } cout << an << endl; } }