Codevs P1653 种树 2

来源:互联网 发布:mac 10.12.6系统怎么样 编辑:程序博客网 时间:2024/05/29 07:23

1653 种树 2


题目描述 Description

一条街的一边有几座房子。因为环保原因居民想要在路边种些树。路边的地区被分割成块,并被编号为1…n。每个块的大小为一个单位尺寸并最多可种一裸树。每个居民想在门前种些树并指定了三个号码b,e,t。这三个数表示该居民想在b和e之间最少种t棵树。当然,b≤e,居民必须保证在指定地区不能种多于地区被分割成块数的树,即要求T≤ e-b+1。允许居民想种树的各自区域可以交叉。出于资金短缺的原因,环保部门请你求出能够满足所有居民的要求,需要种树的最少数量。

输入输出


输入描述 Input Description

第一行为n,表示区域的个数;
第二行为h,表示房子的数目;
下面h行描述居民的需要:bet(0< b≤30000,t≤e-b+ 1)分别用一个空格分开。


输出描述 Output Description

输出为满足所有要求的最少树的数量。

样例

样例输入 Sample Input

9
4
1 4 2
4 6 2
8 9 2
3 5 2

样例输出 Sample Output

5

数据范围及提示 Data Size & Hint

【数据规模】
30%的数据满足0<n ≤1000,0<h ≤ 500; 100%的数据满足n ≤30000,h ≤5000。

分析

因为如果将区间按照右端点从小到大排序,那么右端点有序,这样从左往右扫,区间的折叠部分一定在右侧,所以从后往前种。这样使得种的棵树最少

代码如下

program p1653;type rec=record      l,r,v:longint;     end;var i,j,n,m,ans:longint;    demand:array[1..5000] of rec;    line:array[1..30000] of boolean;procedure qsort(i,j:longint);var l,r,mid,mid2:longint;    temp:rec;begin l:=i; r:=j; mid:=demand[(l+r)>>1].r; mid2:=demand[(l+r)>>1].l; while l<=r do  begin   while (demand[l].r<mid) or ((demand[l].r=mid) and (demand[l].l<mid2)) do inc(l);   while (demand[r].r>mid) or ((demand[r].r=mid) and (demand[r].l>mid2)) do dec(r);   if l<=r    then     begin      temp:=demand[l];      demand[l]:=demand[r];      demand[r]:=temp;      inc(l);      dec(r);     end;  end; if l<j then qsort(l,j); if i<r then qsort(i,r);end;begin readln(n); readln(m); for i:=1 to m do  with demand[i] do   readln(l,r,v); qsort(1,m); fillchar(line,sizeof(line),true); ans:=0; for i:=1 to m do  begin   for j:=demand[i].l to demand[i].r do    begin     if not line[j] then demand[i].v:=demand[i].v-1;    end;   if demand[i].v>0 then    for j:=demand[i].r downto demand[i].l do     begin      if line[j]       then        begin         inc(ans);         line[j]:=false;         dec(demand[i].v);         if demand[i].v=0 then break;        end;     end;  end; write(ans);end.

评测结果

运行结果
测试点#trees1.in 结果:AC 内存使用量: 256kB 时间使用量: 0ms
测试点#trees10.in 结果:AC 内存使用量: 256kB 时间使用量: 45ms
测试点#trees2.in 结果:AC 内存使用量: 256kB 时间使用量: 0ms
测试点#trees3.in 结果:AC 内存使用量: 256kB 时间使用量: 0ms
测试点#trees4.in 结果:AC 内存使用量: 256kB 时间使用量: 0ms
测试点#trees5.in 结果:AC 内存使用量: 256kB 时间使用量: 8ms
测试点#trees6.in 结果:AC 内存使用量: 256kB 时间使用量: 3ms
测试点#trees7.in 结果:AC 内存使用量: 256kB 时间使用量: 68ms
测试点#trees8.in 结果:AC 内存使用量: 256kB 时间使用量: 4ms
测试点#trees9.in 结果:AC 内存使用量: 256kB 时间使用量: 44ms

。。。

当相遇却无语。
转瞬而去的时刻

Enchanted

Verse 1
there I was again tonight

forcing laughter, faking smiles
same old tired, lonely place
walls of insincerity
shifting eyes and vacancy
vanished when I saw your face
All I can say is it was enchanting to meet you
your eyes whispered “have we met?”
across the room, your silhouette
starts to make its way to me
the playful conversation starts
counter all your quick remarks like passing notes in secrecy
and it was enchanting to meet you
all I can say is I was enchanted to meet you
Chorus
this night is sparking, don’t you let it go
I’m wonderstruck, blushing all the way home
I’ll spend forever wondering
if you knew I was enchanted to meet you
Verse 2
the lingering question kept me up
2 a.m. who do you love?
I wonder till I’m wide awake
and now I’m pacing back and forth
wishing you were at my door
I’d open up and you would say
hey, it was enchanting to meet you
alI I know is I was enchanted to meet you
Chorus
this night is sparking, don’t you let it go
I’m wonderstruck, blushing all the way home
I’ll spend forever wondering if you knew
this night is flawless, don’t you let it go
I’m wonderstruck, dancing around all alone
I’ll spend forever wondering
if you knew I was enchanted to meet you
Bridge
this is me praying that this was the very first page
not where the story line ends
my thoughts will echo your name
until I see you again
these are the words I held back as I was leaving too soon
I was enchanted to Meet you
please don’t be in love with someone else
please don’t have somebody waiting on you
please don’t be in love with someone else
please don’t have somebody waiting on you
Chorus
this night is sparking, don’t you let it go
I’m wonderstruck, blushing all the way home
I’ll spend forever wondering if you knew
this night is flawless, don’t you let it go
I’m wonderstruck, dancing around all alone
I’ll spend forever wondering
if you knew I was enchanted to meet you
please don’t be in love with someone else
please don’t have somebody waiting on you

THE VOW

SHE:I vow to help you love life, to always hold you with tenderness;and to have patience that love demands,to speak when words needed,and to share the silence when they are not;and to live within the warmth of you heart and always call it home.

HE:I vow fiercely love you in all you forms ,now and forever.i promise not to forget that this is a once-in-a-life love.and always know in the deepest part of my soul that no matter what challenges carry us apart,and we will always find the way back to each other.
这里写图片描述

0 0
原创粉丝点击