3582281_ac_63ms_248k.cpp
来自「北大大牛代码 1240道题的原代码 超级权威」· C++ 代码 · 共 62 行
CPP
62 行
#include <stdio.h>
#include <algorithm>
using namespace std;
struct SunScreen
{
int spf;
int cnt;
bool operator < (const SunScreen & that) const
{
return spf < that.spf;
}
};
struct Cow
{
int min;
int max;
bool operator < (const Cow & that) const
{
return max < that.max;
}
};
SunScreen sun[2500];
Cow cow[2500];
int main()
{
int c, l, i, j, ans;
scanf("%d%d", &c, &l);
for (i = 0; i < c; i++)
{
scanf("%d%d", &cow[i].min, &cow[i].max);
}
for (i = 0; i < l; i++)
{
scanf("%d%d", &sun[i].spf, &sun[i].cnt);
}
sort(cow, cow + c);
sort(sun, sun + l);
ans = 0;
for (i = 0; i < c; i++)
{
for (j = 0; j < l; j++)
{
if (sun[j].cnt != 0 && sun[j].spf <= cow[i].max && sun[j].spf >= cow[i].min)
{
ans++;
sun[j].cnt--;
break;
}
}
}
printf("%d\n", ans);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?