Disclaimer: the author is limited, blog inevitably a lot of flaws and even serious mistakes, I hope you correct. While writing the biggest goal is also to exchange learning, not paying attention and spread. Long way to go, and you encourage each other. https://blog.csdn.net/yexiaohhjk/article/details/89736233
Questions surface:
Meaning of the questions:
A common plane N brick layer, each layer width uncertain number of bricks, this plane Q passing through the intersection of the straight line and the minimum number of bricks, the bricks across from between the two, not intersect.
Ideas:
Statistics prefix each line width and number of occurrences, the most frequent location is the number cnt meet the meaning of the title of the position, the output of N-cnt is the result.
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, int> Map;
int main(){
int n;
while(~scanf("%d",&n)){
Map.clear();
for(int i = 0;i < n;i++){
int m;scanf("%d",&m);
ll sum = 0;
for(int j = 0;j < m;j++){
ll x; scanf("%lld",&x);
if(j == m-1) break;
sum +=x;
Map[sum] +=1;
}
}
int ans = n;
for(map<ll,int>::iterator it = Map.begin();it != Map.end();it++){
ans = min(ans, n - it->second);
//printf("%d %d\n",it->first, it->second);
}
printf("%d\n",ans);
}
}