竞赛讨论区 > C题哪里错了,大佬教教
头像
lan鱼
编辑于 01-26 22:40
+ 关注

C题哪里错了,大佬教教

#include<bits/stdc++.h>

using namespace std;

#define int long long

void did(){

int n,m,l=0,r=0,lans=0,rans=0;

cin>>n>>m;

l=m-1,r=m+1;//标记左右点

vector<int>a(n+5);

for(int i=1;i<=n;i++)cin>>a[i];

a[m]++;

if(a[m]==10){

if(l>0)a[l]++;

else lans++;

if(r<=n)a[r]++;

else rans++;

while(1){

if(a[l]==10&&a[r]==10){

l--;r++;

if(l>0){

if(a[l]<9)a[l]+=2;//如果a[l]>=9就只用吸收1滴

else {

a[l]++;

if(l==1)lans++;

else a[l-1]++;

}

}

else lans+=2;//如果l<=0水滴都飞向无穷远

if(r<=n){

if(a[r]<9) a[r]+=2;//如果a[r]>=9就只用吸收1滴

else {

a[r]++;

if(r==n)rans++;

else a[r+1]++;

}

}

else rans+=2;//如果r>n水滴都飞向无穷远

}

else if(a[l]==10){//只有左边水滴分裂

l--;

if(l>0)a[l]++;

else lans++;

if(r<=n)a[r]++;

else rans++;

}

else if(a[r]==10){//只有右边水滴分裂

r++;

if(l>0)a[l]++;

else lans++;

if(r<=n)a[r]++;

else rans++;

}

else break;//都不分裂

}

}

cout<<lans<<' '<<rans<<'\n';

}

signed main(){

ios::sync_with_stdio(0);

cin.tie(0);

cout.tie(0);

int t=1;

cin>>t;

while(t--){

did();

}

return 0;

}

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐