bzoj1635: [Usaco2007 Jan]Tallest Cow 最高的牛

链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1635

题意:中文题。。对了,输入的第二个值好像并没有用到。。

分析:根据题目描述,我们很容易想到不可能有两组给出的数据是相交的,只有可能是包含或者相离。既然这样我们就好办了,每次把L到R之间的点的高度-1,差分即可。。但是!有些情况是会错的,比如说L==R。。比如说两组Li==Lj&&Ri==Rj。。判个重即可。

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=10010;
const int MAX=151;
const int MOD=1000007;
const int MOD1=100000007;
const int MOD2=100000009;
const int INF=2100000000;
const double EPS=0.00000001;
typedef long long ll;
typedef unsigned long long ull;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int f[N];
struct node {
    int l,r;
}a[N];
int cmd(node x,node y) {
    if (x.l!=y.l) return x.l<y.l;
    return x.r<y.r;
}
int main()
{
    int i,n,t,h,m;
    scanf("%d%d%d%d", &n, &t, &h, &m);
    for (i=1;i<=m;i++) {
        scanf("%d%d", &a[i].l, &a[i].r);
        if (a[i].l>a[i].r) { a[i].l^=a[i].r;a[i].r^=a[i].l;a[i].l^=a[i].r; }
    }
    a[0].l=a[0].r=0;
    sort(a,a+n+1,cmd);
    memset(f,0,sizeof(f));
    for (i=1;i<=n;i++)
    if ((a[i].l==a[i].r)||(a[i].l==a[i-1].l&&a[i].r==a[i-1].r)) continue ;
    else { f[a[i].l+1]--;f[a[i].r]++; }
    for (i=1;i<=n;i++) f[i]+=f[i-1];
    for (i=1;i<=n;i++) printf("%d\n", h+f[i]);
    return 0;
}

/*
9 3 5 5
1 3
5 3
4 3
3 7
9 8
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值