解题思路:
看了题解在做的题目,完全摸不着头绪,最后得到 数目 = 左边右走的+右边左走的;
大概模拟了下,发现病蚂蚁并不是 左边右走的所有蚂蚁,这类题估计要想出模拟状态
注意事项:
参考代码:
#include<iostream>
#include<sstream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
const int maxn = 50;
int a[maxn];
bool cmp(int a,int b);
int coun(int *ant,int jud, int n);
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
int bi = a[0];
sort(a,a+n,cmp);
printf("%d\n",coun(a,bi,n));
return 0;
}
int coun(int *ant,int jud, int n){
int num = 0;
int cnt = find(ant,ant+n,jud) - ant;
for(int i = 0; i < cnt; i++){
if(ant[i] > 0) num++;
}
for(int i = cnt+1; i < n; i++){
if(ant[i] < 0) num++;
}
return num+1;
}
bool cmp(int a,int b){
return abs(a) < abs(b);
}
0.0分
0 人评分