L1-088 静静的推荐

题目 L1-088 静静的推荐

image-67027a69

思路分析

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

using ll = long long;

using ull = unsigned long long;

using PII = pair<int,int>;

using Pll = pair<ll,ll>;

int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};

const int inf = 0x3f3f3f3f;

struct Student{

	int s_tts;

	int s_pat;

	bool used;

	bool operator<(const Student& rhs) const {

		if(s_tts!=rhs.s_tts)	return s_tts<rhs.s_tts;

		return s_pat<rhs.s_pat;

	}

};

bool tuijian(const Student& last,const Student& cur,int s){

	return cur.s_tts>last.s_tts || (cur.s_tts==last.s_tts && cur.s_pat>=s);

}

int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int n,k,s;

	cin>>n>>k>>s;

	vector<Student> students;

	int cnt=0;

	while(n--){

		int stts,spat;cin>>stts>>spat;

		if(stts>=175)	students.push_back({stts,spat,false});

	}

	sort(students.begin(),students.end());

	int total=0;

	for(int batch=0;batch<k;batch++){

		int lastIndex=-1;

		for(int i=0;i<students.size();i++){

			if(students[i].used)	continue;

			if(lastIndex==-1 || tuijian(students[lastIndex],students[i],s)){

				students[i].used=true;

				total++;

				lastIndex=i;

			}

		}

	}

	cout<<total;

	return 0;

}

同类题型

视频讲解


⬅️ L1-087 机工士姆斯塔迪奥 🏠 00-天梯赛 ➡️ L1-089 最好的文档