

题解:刚开始想用优先队列做……就是每一条建议取重叠最多的几个点种树,然后SE了= =数据比较大 = =
这题有个比较迷的地方……就是如果用while(cin>>n>>h)输入会WA……打开测试数据看了下发现有几组数据这样输入的话会有多组输出……= =另外就是点的数量是n,范围在30000,建议的范围在5000.弄混了好多次- -
按照右端点从小到大排序,每次都尽量往右种树。
AC代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
struct node
{
int b, e;
int t;
friend bool operator < (node a, node b)
{
return a.e<b.e;
}
}se[5005];
bool vis[30005];
int main()
{
int n, h;
int ans;
cin>>n>>h;
memset(vis, 0, sizeof(vis));
for(int i=1; i<=h; i++)
{
cin>>se[i].b>>se[i].e>>se[i].t;
}
sort(se+1, se+h+1);
ans=0;
for(int i=1; i<=h; i++)
{
int cnt=0;
for(int j=se[i].b; j<=se[i].e; j++)
{
cnt+=vis[j];
}
for(int j=se[i].e; j>=se[i].b && cnt<se[i].t; j--)
{
if(!vis[j])
{
vis[j]=1;
cnt++;
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}
|