1060 爱丁顿数(测试点5)

在这里插入图片描述
在这里插入图片描述

solution1(测试点5不通过)

所谓“E天骑行超过E公里”,注意没有要求是第E天
对于直接判断变成了第E天骑行距离超过E公里,曲解了题意
例如对于

3
1 2 3

输出为1
第1天骑行3公里,满足条件;第2天骑行2公里,不满足超过的条件,最大的e为1

#include<iostream>
using namespace std;
int main(){
	int n, cnt = 0, x;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &x);
		if(x > i) cnt++;
	}
	printf("%d", cnt);
	return 0;
}

solution2

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a, int b){
	return a > b;
}
const int maxn = 1e5 + 10;
int a[maxn];
int main(){
	int n, cnt = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", a + i);
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++){
		if(i < a[i]) cnt++;
	}
	printf("%d", cnt);
	return 0;
}

相关推荐

  1. Crow:Middlewares 庖解牛5 context

    2024-05-16 06:10:18       68 阅读
  2. 单元测试之JUnit5知识总结及代码示例

    2024-05-16 06:10:18       23 阅读
  3. 分—AB测试

    2024-05-16 06:10:18       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-16 06:10:18       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-16 06:10:18       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-16 06:10:18       87 阅读
  4. Python语言-面向对象

    2024-05-16 06:10:18       96 阅读

热门阅读

  1. 15. 三数之和

    2024-05-16 06:10:18       29 阅读
  2. docker版MySQL5.7重置root密码并授权localhost访问

    2024-05-16 06:10:18       27 阅读
  3. Qt初识

    Qt初识

    2024-05-16 06:10:18      28 阅读
  4. 时间格式数据向前或向后归于整时

    2024-05-16 06:10:18       30 阅读
  5. Zookeeper笔记,MIT6.824

    2024-05-16 06:10:18       37 阅读
  6. Go 语言将 PDF 转为 Word 如何处理

    2024-05-16 06:10:18       38 阅读
  7. hashmap数据结构为什么是链表

    2024-05-16 06:10:18       39 阅读