H - 高橋和低橋

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   ar   for   

H - 高橋和低橋Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %lluSubmit Status Practice CSU 1335

Description

有個腦筋急轉彎是這樣的:有距離很近的一高一低兩座橋,兩次洪水之後高橋被淹了兩次,低橋卻只被淹了一次,為什嗎?答案是:因為低橋太低了,第一次洪水退去之後水位依然在低橋之上,所以不算“淹了兩次”。舉例說明:

假定高橋和低橋的高度分別是5和2,初始水位為1

第一次洪水:水位提高到6(兩個橋都被淹),退到2(高橋不再被淹,但低橋仍然被淹)

第二次洪水:水位提高到8(高橋又被淹了),退到3。

沒錯,文字遊戲。關鍵在於“又”的含義。如果某次洪水退去之後一座橋仍然被淹(即水位不小於橋的高度),那麼下次洪水來臨水位提高時不能算“又”淹一次。

輸入n座橋的高度以及第i次洪水的漲水水位ai和退水水位bi,統計有多少座橋至少被淹了k次。初始水位為1,且每次洪水的漲水水位一定大於上次洪水的退水水位。

 

Input

輸入檔案最多包含25組測試資料。每組資料第一行為三個整數n, m, k(1<=n,m,k<=105)。第二行為n個整數hi(2<=hi<=108),即各個橋的高度。以下m行每行包含兩個整數ai和bi(1<=bi<ai<=108, ai>bi-1)。輸入檔案不超過5MB。

 

Output

對於每組資料,輸出至少被淹k次的橋的個數。

 

Sample Input

2 2 22 56 28 35 3 22 3 4 5 65 34 25 2 

Sample Output

Case 1: 1Case 2: 3 
二分尋找題
 1 #include"iostream" 2 #include"cstring" 3 #include"cstdio" 4 #include"algorithm" 5 using namespace std; 6 const int ms=100005; 7 int n,m,k; 8 int h[ms]; 9 int cnt[ms];10 int main()11 {12     int i,j,ans,p=1,k,a,b;13     int ta,tb; 14     while(scanf("%d%d%d",&n,&m,&k)!=EOF)15     {16         memset(cnt,0,sizeof(cnt));17         tb=1;18         for(i=0;i<n;i++)19         {20             scanf("%d",&h[i]);21         }22         sort(h,h+n);23         for(i=0;i<m;i++)24         {25             scanf("%d%d",&a,&b);26             int tmpa=upper_bound(h,h+n,a)-h;27             while(h[tmpa]>a)28                 tmpa--;29             int tmpb=upper_bound(h,h+n,tb)-h;30             while(h[tmpb]<=tb)31                 tmpb++;32             tb=b;33             cnt[tmpb]++;34             cnt[tmpa+1]--;35         }36         for(i=0;i<n;i++)37             cnt[i+1]+=cnt[i];38         ans=0;39         for(i=0;i<n;i++)40             if(cnt[i]>=k)41                 ans++;42         printf("Case %d: %d\n",p++,ans);43     }44     return 0;45 }

 

H - 高橋和低橋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.