Codevs P1653 種樹 2

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.
這裏寫圖片描述

發佈了76 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章