[贪心] BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
来源:互联网 发布:linux 最好用的输入法 编辑:程序博客网 时间:2024/05/20 17:23
题目大意:取尽量多的区间 两两交为空
按照右端点排序然后贪心。因为右端点小显然接下来可以取更多的区间
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;inline char nc(){static char buf[100000],*p1=buf,*p2=buf;if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }return *p1++;}inline void read(int &x){char c=nc(),b=1;for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=500005;int now,n,ans;struct abcd{int x,y;}a[N];inline bool cmp(abcd a,abcd b){ return a.y<b.y;}int main(){ freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); for (int i=1;i<=n;i++) read(a[i].x),read(a[i].y); sort(a+1,a+n+1,cmp); now=1; for (int i=1;i<=n;i++) if(a[i].x>=now)ans++,now=a[i].y; printf("%d\n",ans); return 0;}
0 0
- [贪心] BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
- [贪心]BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者
- BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者 贪心
- 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者
- BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者 离散化dp
- bzoj3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
- bzoj3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
- 【贪心】BZOJ3410(Usaco2009 Dec)[Selfish Grazing 自私的食草者]题解
- 【USACO2009Decsilver T1 自私的食草者
- toj3479 Selfish Grazing
- [Usaco09Dec] Selfish Grazing
- 【BZOJ 1774】 [Usaco2009 Dec]Toll 过路费
- Bzoj 1774 [Usaco2009 Dec]Toll 过路费
- BZOJ 1774 [Usaco2009 Dec] Toll 过路费
- (bzoj 1774 [Usaco2009 Dec]Toll 过路费)
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- bzoj 3412: [Usaco2009 Dec]Music Notes乐谱
- 【BZOJ 1691】[Usaco2007 Dec]挑剔的美食家 treap+贪心
- 小兵围大炮||大兵小将【C++】
- 母函数(生成函数)
- 开源 java CMS - FreeCMS2.5 标签 infoPreList
- python
- 最小公倍数
- [贪心] BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者
- mongodb 基本查询
- [Cloud Computing]Mechanisms: RAID-level Identifier
- 先安装windows7_64bit,再安装Centos7,windows7的启动项不出现
- explain详细说明
- 配置qt需要的dll
- The MAX
- [AC自动机 概率DP 矩阵乘法||高斯消元] BZOJ 1444 [Jsoi2009]有趣的游戏
- 计算机内存寻址