湖南第九届省赛 高桥和低桥

Q: There are one high bridge and one low bridge across the river. The river has flooded twice, why the

high bridge is flooded twice but the low bridge is flooded only once?

A: Because the lower bridge is so low that it’s still under water after the first flood is over.

If you’re confused, here’s how it happens:

? Suppose high bridge and low bridge’s heights are 2 and 5, respectively, and river’s initial water

level is 1.

? First flood: the water level is raised to 6 (Both bridges are flooded), and then back to 2 (high

bridge is not flooded anymore, but low bridge is still flooded).

? Second flood: the water level is raised to 8 (The high bridge is flooded again), and then back to

3.

Just a word game, right? The key is that if a bridge is still under water (i.e. the water level is no

less than the bridge height) after a flood, then next time it will not be considered flooded again.

Suppose the i-th flood raises the water level to ai and then back to bi

. Given n bridges’ heights,

how many bridges are flooded at least k times? The initial water level is 1.

Input

The input contains at most 25 test cases. Each test case begins with 3 integers n, m, k in the first line

(1 ≤ n, m, k ≤ 105

). The next line contains n integers hi

, the heights of each bridge (2 ≤ hi ≤ 108

).

Each of the next m lines contains two integers ai and bi (1 ≤ bi < ai ≤ 108

, ai > bi?1). The file size of

the whole input does not exceed 5MB.

Output

For each test case, print the number of bridges that is flooded at least k times.

Explanation:

For the second sample, 5 bridges are flooded 1, 2, 3, 2, 0 times, respectively.

Sample Input

2 2 2

2 5

6 2

8 3

5 3 2

2 3 4 5 6

5 3

4 2

5 2

Sample Output

Case 1: 1

Case 2: 3

被玩了文字游戏….

可能是我理解能力有问题,wa了好多次

关键是在于这个“又”淹没!!


#include<cstdio>
#include<iostream>
using namespace std;
#include<cstring>
#include<algorithm>

/*
    Name:
    Copyright:
    Author:
    Date: 07/05/16 21:29
    Description:
*/
const int maxn=100005;
int c[maxn<<2];
int a[maxn];

int low(int ns){
    return ns&(-ns);
}
int n;
void updata(int x,int y){
    while(x<=n){
        c[x]+=y;
        x+=low(x);
    }
}

int sum(int x){
    int ans=0;
    while(x){
        ans+=c[x];
        x-=low(x);
    }
    return ans;
}
int w[maxn][2];

int main(){
    int m,k;
    int coun=0;
#ifndef ONLINE_JUDGE
    freopen("h.in","r",stdin);
    freopen("outh.txt","w",stdout);
//freopen("hin.txt","r",stdin);
    #endif
    while(scanf("%d%d%d",&n,&m,&k)!=-1){

        for(int i=1;i<=n;++i)
           scanf("%d",a+i);
        sort(a+1,a+n+1);
        memset(c,0,sizeof(c));
        w[0][0] = 1;
        for(int i=0; i<m; i++){
            scanf("%d%d",&w[i][1],&w[i+1][0]);
        }
        for(int i=0;i<m;++i){
            int poss=upper_bound(a+1,a+n+1,w[i][1])-a-1;
            int post=upper_bound(a+1,a+n+1,w[i][0])-a;
//          cout<<"pos="<<post<<" "<<poss<<endl;
            updata(post,1);
            updata(poss+1,-1);
        }
        int ans=0;
        for(int i=1;i<=n;++i){
             if(sum(i)>=k)++ans;
//           cout<<sum(i)<<endl;
        }
        printf("Case %d: %d\n",++coun,ans);
    }
    return 0;
}
时间: 2024-10-28 11:08:51

湖南第九届省赛 高桥和低桥的相关文章

UVA 12663 第九届省赛 高桥与低桥 树状数组

1 #include <cstdio> 2 #include <math.h> 3 #include <iostream> 4 #include <cstring> 5 #include <cstdlib> 6 #include <algorithm> 7 using namespace std; 8 9 const int maxn = 1e5+10; 10 int c[maxn], a[maxn]; 11 int lowbit(i

湖南第九届省赛 好老师

I want to be a good teacher, so at least I need to remember all the student names. However, there are too many students, so I failed. It is a shame, so I don't want my students to know this. Whenever I need to call someone, I call his CLOSEST student

Interesting Calculator 湖南第九届省赛

There is an interesting calculator. It has 3 rows of button. ? Row 1: button 0, 1, 2, 3, - , 9. Pressing each button appends that digit to the end of the display. ? Row 2: button +0, +1, +2, +3, - , +9. Pressing each button adds that digit to the dis

湖南省第九届大学生计算机程序设计竞赛 高桥和低桥

高桥和低桥 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 358  Solved: 60 Description 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算"淹了两次".举例说明: 假定高桥和低桥的高度分别是5和2,初始水位为1 第一次洪水:水位提高到6(两个桥都被淹),退到2(高桥不再被淹,但低桥仍然

CSU 1335: 高桥和低桥(扫描线) 13年省赛题

1335: 高桥和低桥 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 957  Solved: 279 [Submit][Status][Web Board] Description 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算"淹了两次".举例说明: 假定高桥和低桥的高度分别是5和2,初始水位为1 第一

第九届省赛-表达式求值(模拟)

表达式求值 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表达式,则 X+Y, X*Y 也是表达式; *优先级高于+. 3. 如果 X 和 Y 是 表达式,则 函数 Smax(X,Y)也是表达式,其值为:先分别求出 X ,Y 值的各位数字之和,再从中选最大数. 4.如果 X 是 表达式,则 (X)也是表达式. 例如: 表达式 12*(2+3)+Smax(333,220+2

nyoj1273 河南省第九届省赛_&quot;宣传墙&quot;、状压DP+矩阵幂加速

宣传墙 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做一系列的宣传.为了统一规划,CBA 镇长要求每个宣传栏只能占相邻的两个方格 位置.但这条道路被另一条道路分割成左右两段.CBA 镇长想知道,若每个位置都贴上宣传栏, 左右两段各有有多少种不同的张贴方案. 例如: N=6,M=3, K=2, 左,右边各有 5 种不同的张贴方案 输入 第一行: T 表示

CSU 1335: 高桥和低桥 (二分查找,树状数组)

Description 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算“淹了两次”.举例说明: 假定高桥和低桥的高度分别是5和2,初始水位为1 第一次洪水:水位提高到6(两个桥都被淹),退到2(高桥不再被淹,但低桥仍然被淹) 第二次洪水:水位提高到8(高桥又被淹了),退到3. 没错,文字游戏.关键在于“又”的含义.如果某次洪水退去之后一座桥仍然被淹(即水位不小于桥的

csuoj 1335: 高桥和低桥

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1335 1335: 高桥和低桥 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 802  Solved: 221[Submit][Status][Web Board] Description 有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低