解题思路:
毫无意义的题解,别看了,我看了一下别人的题解发现我还是溜了,这个方法适合扩展蚂蚁的速度不同,以及一些其他的物理模拟的方式
参考代码:
#include<bits/stdc++.h> #define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); using namespace std; const int maxn=55; int n,ans=1,l=0,r=0; struct Ant{ int pos; //位置 bool way; //朝向,true是正向(右),反之为反向(左) }; Ant ant[maxn];//蚂蚁 int main(){ hh; cin>>n; for(int i=0;i<n;i++){ int temp; cin>>temp; ant[i].pos=abs(temp); if(temp>=0){ ant[i].way=true; }else{ ant[i].way=false; } if(i!=0){ if(ant[i].way&&ant[i].pos<ant[0].pos){ l++; } if(!ant[i].way&&ant[i].pos>ant[0].pos){ r++; } } } if((ant[0].way&&r==0)||(!ant[0].way&&l==0)) cout<<ans; else cout<<ans+l+r<<endl; return 0; }
0.0分
0 人评分