解题思路:
看了题解在做的题目,完全摸不着头绪,最后得到 数目 = 左边右走的+右边左走的;
大概模拟了下,发现病蚂蚁并不是 左边右走的所有蚂蚁,这类题估计要想出模拟状态
注意事项:
参考代码:
#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 人评分
陶陶摘苹果 (C语言代码)浏览:1606 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:487 |
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
A+B for Input-Output Practice (V) (C++代码)浏览:451 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:483 |
【绝对值排序】 (C语言代码)浏览:821 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:939 |
IP判断 (C语言代码)浏览:763 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:556 |
矩阵乘方 (C语言代码)浏览:1030 |