CSU 1335: Takahashi and Low Bridge (scan line) 13 Provincial game problem

Source: Internet
Author: User

1335: Takahashi and Low bridge time limit: 1 Sec Memory Limit: MB
Submit: 957 Solved: 279
[Submit] [Status] [Web Board] Description

One of the brain teasers is this: there is a very close to a low two bridge, two floods after the Takahashi was flooded two times, the low bridge was only flooded once, why? The answer is: Because the low bridge is too low, the first flood after the water is still on the low bridge, so does not count as "flooded two times." To illustrate:

It is assumed that the height of Takahashi and Low Bridge is 5 and 2, the initial water level is 1

First flood: water level raised to 6 (two bridges flooded), retreated to 2 (Takahashi no longer flooded, but low bridge is still flooded)

Second flood: The water level was raised to 8 (Takahashi was flooded again) and retreated to 3.

Yes, word games. The key is the meaning of "another". If a bridge is still flooded after a flood has receded (that is, the water level is not less than the height of the bridge), then the next flood will not be "flooded" once again.

Enter the height of the N bridge and the swollen level AI and water level bi for the flood of the first I, and count how many bridges have been flooded at least k times. The initial water level is 1, and the swollen water level of each flood must be greater than the water level of the last flood.

Input

The input file contains up to 25 sets of test data. The first behavior of each group of data is three integers n, m, K (1<=n,m,k<=105). The second behavior is n integers hi (2<=hi<=108), which is the height of each bridge. The following m lines contain two integers of AI and bi (1<=bi<ai<=108, ai>bi-1) per line. The input file does not exceed 5MB.

Output

For each set of data, output the number of bridges that have been flooded at least k times.

Sample Input
2 2 22 56 28 35 3 22 3 4 5 65 34 25 2
Sample Output
Case 1:1case 2:3
Hintsource

The nineth session of Hunan Province College students computer Program design Contest


#include <stdio.h> #include <algorithm> #include <string.h>using namespace std;const int N = 100010; int    Num[n],h[n];int (int N, int ans) {int l=1, r=n, mid;        while (l<=r) {mid= (l+r) >>1;        if (H[mid]>=ans) r = mid-1;    else L = mid+1; } return L;}    int main () {int n,m,k;    int T = 0;        while (scanf ("%d%d%d", &n,&m,&k) >0) {memset (num, 0, (n+3) *sizeof (int));        for (int i=1; i<=n; i++) scanf ("%d", &h[i]);        Sort (h+1, h+1+n);        int A, B, th=2, id;            while (m--) {scanf ("%d%d", &a,&b);            id = both (n, Th);            num[id]++;            id = both (n, a+1);            num[id]--;        th = b+1;        } int ans = 0, ad= 0;            for (int i=1; i<=n; i++) {AD + = Num[i];        if (ad>=k) ans++;    } printf ("Case%d:%d\n", ++t,ans); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

CSU 1335: Takahashi and Low Bridge (scan line) 13 Provincial game problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.