题面 :
题意:
一共有N层砖的平面,每一层砖块数宽度不定,问穿过这个平面直线与最小砖相交数量,从两块砖缝之间划过,不算相交。
思路:
统计每行宽度的前缀和出现次数,出现数量cnt最多的位置就是满足题意的位置,输出N-cnt就是结果。
代码:
#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);
}
}