天空


私信TA

用户名:673953508

访问量:14714

签 名:

别看了,全是水题

等  级
排  名 482
经  验 4524
参赛次数 1
文章发表 22
年  龄 20
在职情况 学生
学  校 广东技术师范学院
专  业 计算机科学与技术

  自我简介:

解题思路:
看了题解在做的题目,完全摸不着头绪,最后得到 数目 = 左边右走的+右边左走的;

大概模拟了下,发现病蚂蚁并不是 左边右走的所有蚂蚁,这类题估计要想出模拟状态


注意事项:





参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区