题解 | #Laptop#

Laptop

https://ac.nowcoder.com/acm/problem/14266

用sort进行结构体排序: 1.采用结构体去保存,一个结构体类型Computer中有两个属性,内存和速度,先确定一列数据从小到大排列,之后再找要满足的条件 2.从第五排速度为300向上看,如果上面有小于300的那么它肯定是被完爆的,但是我们不能用两重循环,所以要不断更新最大值max,比如让max=400,比350大;

内存 速度
50 100
100 350
300 400
400 20
500 300

2.因为

#include <iostream>
#include <algorithm>
using namespace std;
struct Computer
{
	int Rom;//内存缩写
	int Speed;//速度
};
bool compare( Computer c1, Computer c2)
{
	return c1.Rom < c2.Rom;
}



int main()
{
	long long n; cin >> n;//n的值较大
	Computer com[n]; int count = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> com[i].Rom >> com[i].Speed;
	}
	sort(com+1, com + n+1, compare);//进行第一列对内存的排序
	int max = com[n].Speed;
	for (int i = n-1; i > 0; i--)
	{
		if (com[i].Speed < max)
		{
			count++;
		}
		else
			max = com[i].Speed;
	}
    cout<<count;
	return 0;
}
全部评论

相关推荐

05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
昨天 10:44
青岛工学院 Java
机械打工仔:对方没做错任何事,你自己在这自找没趣呢,就算他工资不高,人家定多少薪资是人家的事,况且人家写了1~3年清清楚楚
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务