The Ninth Hunan Collegiate Programming Contest (2013) Problem H

Problem H

High bridge, low bridge

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.

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

Output for the Sample Input

Case 1: 1
Case 2: 3

Explanation

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


The Ninth Hunan Collegiate Programming Contest (2013)

Problemsetter: Rujia Liu Special Thanks: Feng Chen, Md. Mahbubul Hasan

 

    这道试题很好。用笔画一下,其实就是区间更新,区间询问的树状数组吧,关键是求更新的区间,其实直接使用StL的查找也是可以的。还是那个道理,二分查找的变法很多,

不要太依赖STL ,基础一定要打好。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int Max_N=100008 ;
struct Node{
     int raise ;
     int down ;
};
Node water[Max_N] ;
int bridge[Max_N] ;
int N ,M ,K ;
int find_first_big_id(int x){
   int Left=1 ;
   int Right=N ;
   int mid ;
   int ans_id=-1 ;
   while(Left<=Right){
        mid=(Left+Right)>>1  ;
        if(bridge[mid]>x){
            ans_id=mid ;
            Right=mid-1 ;
        }
        else
            Left=mid+1 ;
   }
   return ans_id ;
}
int find_last_less_or_equal_id(int x){
    int Left=1 ;
    int Right=N ;
    int mid ;
    int ans_id=-1 ;
    while(Left<=Right){
        mid=(Left+Right)>>1  ;
        if(bridge[mid]>x){
            Right=mid-1 ;
        }
        else{
            ans_id=mid ;
            Left=mid+1 ;
        }
    }
    return ans_id ;
}
int C[Max_N] ;
inline int lowbit(int x){
   return x&(-x) ;
}
void Insert(int id ,int x){
   while(id<=N){
        C[id]+=x ;
        id+=lowbit(id) ;
   }
}
int get_sum(int id){
   int sum=0 ;
   while(id>=1){
       sum+=C[id] ;
       id-=lowbit(id) ;
   }
   return sum ;
}
int main(){
   /*int x ;
   while(cin>>N>>x){
       for(int i=1;i<=N;i++)
           cin>>bridge[i] ;
       cout<<find_last_less_or_equal_id(x)<<endl ;
   }*/
   int L ,R ,ans ,k=1 ;
   while(scanf("%d%d%d",&N,&M,&K)!=EOF){
        for(int i=1;i<=N;i++)
            scanf("%d",&bridge[i]) ;
        for(int i=1;i<=M;i++)
            scanf("%d%d",&water[i].raise,&water[i].down) ;
        sort(bridge+1,bridge+1+N) ;
        water[0].down=0 ;
        fill(C,C+N+1,0) ;
        for(int i=0;i<M;i++){
            L=find_first_big_id(water[i].down) ;
            R=find_last_less_or_equal_id(water[i+1].raise) ;
           // cout<<L<<"  "<<R<<endl  ;
            if(L==-1||R==-1)
                continue ;

            Insert(L,1) ;
            Insert(R+1,-1) ;
        }
        ans=0 ;
        for(int i=1;i<=N;i++){
            if(get_sum(i)>=K)
                ans++ ;
        }
        printf("Case %d: %d\n",k++,ans) ;
   }
   return 0 ;
}

 

转载于:https://www.cnblogs.com/liyangtianmen/p/3371301.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值