日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

bzoj3410[Usaco2009 Dec]Selfish Grazing 自私的食草者*

發布時間:2025/3/20 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bzoj3410[Usaco2009 Dec]Selfish Grazing 自私的食草者* 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

bzoj3410[Usaco2009 Dec]Selfish Grazing 自私的食草者

題意:

n個區間,求最多的區間集合使其互不覆蓋。n≤50000

題解:

好像是第三次出現這種題了~但是區間范圍可達10^9,不能dp了QAQ膜了一發題解發現只要按區間右端點排序然后貪心取即可。

代碼:

1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 50100 5 #define inc(i,j,k) for(int i=j;i<=k;i++) 6 using namespace std; 7 8 inline int read(){ 9 char ch=getchar(); int f=1,x=0; 10 while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} 11 while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); 12 return f*x; 13 } 14 struct nd{int l,r;} nds[maxn]; 15 inline bool cmp(const nd &a,const nd &b){return a.r<b.r;} 16 int n,r,ans; 17 int main(){ 18 n=read(); inc(i,1,n){int a=read(),b=read(); nds[i]=(nd){a,b};} 19 sort(nds+1,nds+1+n,cmp); 20 inc(i,1,n){ 21 if(nds[i].l>=r)ans++,r=nds[i].r; 22 } 23 printf("%d",ans); return 0; 24 }

?

20160810

轉載于:https://www.cnblogs.com/YuanZiming/p/5769462.html

總結

以上是生活随笔為你收集整理的bzoj3410[Usaco2009 Dec]Selfish Grazing 自私的食草者*的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。