原題下載
答案:
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef pair<int,int> pii;
multiset<int> chickens;
vector<pii> cows;
int C, N;
int main(void)
{
ifstream fin("helpcross.in");
ofstream fout("helpcross.out");
fin >> C >> N;
int x, y, total=0;
for (int i=0; i<C; i++) { fin >> x; chickens.insert(x); }
for (int i=0; i<N; i++) { fin >> x >> y; cows.push_back(pii(y,x)); }
sort (cows.begin(), cows.end());
for (int j=0; j<N; j++) {
auto which_chicken = chickens.lower_bound(cows[j].second);
if (which_chicken != chickens.end() && *which_chicken <= cows[j].first) {
total++;
chickens.erase(which_chicken);
}
}
fout << total << "\n";
return 0;
}
以上就是關(guān)于【USACO 2017 February Contest, Silver Problem 1. Why Did the Cow Cross the Road】的解答,如需了解學(xué)校/賽事/課程動(dòng)態(tài),可至翰林教育官網(wǎng)獲取更多信息。
往期文章閱讀推薦:
2027 USAAIO人工智能奧賽報(bào)名進(jìn)行中!Round 1新規(guī)出爐,2月開賽如何備考?
外灘大會(huì)見證AI爆發(fā)!緊跟智能時(shí)代,從USACO計(jì)算機(jī)奧賽起步!

? 2026. All Rights Reserved. 滬ICP備2023009024號(hào)-1