CSUSTOJ-藤原千花不想知道数学成绩(数组及无数组解法)

题目连接:http://acm.csust.edu.cn/problem/4055
博客园食用链接:https://www.cnblogs.com/lonely-wind-/p/13941855.html

Description

秀知院期末考试的数学成绩终于出来了,藤原千花知道自己考的很差,所以不想面对,于是她找了一个借口来安慰自己:如果这次数学考试及格的人数小于等于参与人数的一半,或者这次数学考试通过的人数是历年来 n n n 次数学考试通过人数的前三少的(即最多有两次考试通过人数严格比这次少),那么说明这次考试确实太难了,这样藤原千花的内心就不会受伤,否则她会很伤心。

input

第一行输入两个整数 n n n m m m ( 1 ≤ n ≤ 1 e 6 , 1 ≤ m ≤ 1 e 6 ) (1 \leq n \leq 1e6, 1 \leq m \leq 1e6) (1n1e6,1m1e6)分别表示数学考试次数(包括此次考试),以及每次考试的参与人数(每次考试参与人数都相同)

第二行输入 n n n个整数 a 1 , a 2 , … . a n a_1, a_2,….a_n a1,a2,.an ( 0 ≤ a i ≤ m ) (0 \leq a_i \leq m) (0aim)表示每次考试的通过人数,其中 a 1 a_1 a1表示此次考试通过人数

output

输出一行,若此次数学考试确实太难了输出YES,否则输出NO

Sample Input 1
4 4
2 1 1 1
Sample Output 1
YES

Sample Input 2
4 4
3 3 1 1
Sample Output 2
YES

Sample Input 3
4 3
2 1 1 1
Sample Output 3
NO

Hint

样例1:虽然有3次考试通过人数严格小于此次通过人数, 但此次考试通过人数小于等于总参与人数的一半,所以说明此次比较难

样例2:虽然此次考试通过人数大于总参与人数的一半,但通过人数严格小于此次的考试只有2次,所以说明此次比较难

样例3:两种条件都不满足,所以不能说明此次比较难

emmm,用数组的就比较无脑了,先将第一个数x保存下来,直接排个序然后顺序找过去有几个小于x的数就完事了。
以下是AC代码:

#include <bits/stdc++.h>
using namespace std;

const int mac=1e6+10;

int a[mac];

int main(int argc, char const *argv[])
{
	int n,m;
	scanf ("%d%d",&n,&m);
	for (int i=1; i<=n; i++)
		scanf ("%d",&a[i]);
	if (a[1]<=m/2) printf("YES\n");
	else {
		int p=a[1];
		sort(a+1,a+1+n);
		int idx=lower_bound(a+1,a+1+n,p)-a;//这里是二分查找,快一点
		if (idx<=3) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

当然,这题实际上也用不是数组,我们先将第一个数字保留下来,然后对非第一个数字的统计一下有几个小于它的就好了

以下是AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n,m;
	scanf ("%d%d",&n,&m);
	int flag=0,x1,num=0;
	for (int i=1; i<=n; i++){
		int x;
		scanf ("%d",&x);
		if (i==1){
			if (x<=m/2) flag=1;
			x1=x;
		}
		else if (i>1 && x<x1) num++;
	}
	if (num<=2) flag=1;
	if (flag) printf("YES\n");
	else printf("NO\n"); 
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我不能在这里展示完整的 "docker --help" 内容,因为它非常长,并且超过了限制。但是,我可以解释一下其中的一些基本内容: ``` Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/etc/docker/ca.pem") --tlscert string Path to TLS certificate file (default "/etc/docker/server.pem") --tlskey string Path to TLS key file (default "/etc/docker/server-key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem ... Run 'docker COMMAND --help' for more information on a command. ``` 这是docker命令行帮助的基本格式。它告诉我们如何使用docker命令,并列出了一些常用的选项和命令。 - `Usage`: 显示如何使用docker命令,包括选项和命令。 - `Options`: 显示可用的选项,例如设置日志级别、使用TLS等。 - `Commands`: 显示可用的命令,例如创建、启动、停止、删除容器等。 可以使用 "docker COMMAND --help" 命令查看每个命令的详细选项和用法。例如,使用 "docker run --help" 命令可以查看 "run" 命令的帮助文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值