正文
增加 7 行删除 7 行
22 行未改动23242526272829303132333435363738394041424344454647484 行未改动22 行未改动#include<bits/stdc++.h>#define int long longusing namespace std;const int N=255555;int cnt,n,a[2*N],mmax,t,st,f=1;//由于要首尾相接所以数组的大小要开到2*Nsigned main(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin>>n;for(int i=1;i<=n;i++){cin>>a[i];if(a[i]!=0&&!st) st=i;//st用于记录第一个非0的数的位置if(!st) a[i+n]=a[i];//如果开头是0就丢到数组末尾}if(!st){//如果全是0直接输出即可cout<<n/2;return 0;}for(int i=st,k=1;k<=n;k++,i++){if(a[i]!=0) cnt+=a[i]+t%2+t/2,t=0;//有小房间就全加起来,再结算前面连续的大房间,最后将大房间的个数清零else t++;//没有小房间的话就累加个数}cout<<cnt+t%2+t/2;//输出的时候再算一次防止数组末尾是0导致没算进去return 0;}/*64 行未改动22 行未改动23242526272829303132333435363738394041424344454647484 行未改动22 行未改动#include<bits/stdc++.h>#define int long longusing namespace std;const int N=255555;int cnt,n,a[2*N],mmax,t,st,f=1;//由于要首尾相接所以数组的大小要开到2*Nsigned main(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin>>n;for(int i=1;i<=n;i++){cin>>a[i];if(a[i]!=0&&!st) st=i;//st用于记录第一个非0的数的位置if(!st) a[i+n]=a[i];//如果开头是0就丢到数组末尾}if(!st){//如果全是0直接输出即可cout<<n/2;return 0;}for(int i=st,k=1;k<=n;k++,i++){if(a[i]!=0) cnt+=a[i]+t%2+t/2,t=0;//有小房间就全加起来,再结算前面连续的大房间,最后将大房间的个数清零else t++;//没有小房间的话就累加个数}cout<<cnt+t%2+t/2;//输出的时候再算一次防止数组末尾是0导致没算进去return 0;}/*64 行未改动