传送门

解题思路

如果x与y互相看见,那么他们一定比之间的高,所以给他们之间的高度-1,最后得到的答案是所有牛的高度+h,之间-1会T,用差分数组或线段树维护即可。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map> using namespace std;
const int MAXN = 10005; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?0:1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
} int n,l,h,r,d[MAXN],a[MAXN];
map<pair<int,int>,bool> mp; int main(){
n=rd(),l=rd(),h=rd(),r=rd();int x,y;
for(int i=1;i<=r;i++){
x=rd(),y=rd();
if(mp.count(make_pair(x,y))) continue;
mp[make_pair(x,y)]=1,mp[make_pair(y,x)]=1;
if(x>y) swap(x,y);
d[x+1]--,d[y]++;
}
for(int i=1;i<=n;i++)
d[i]+=d[i-1],printf("%d\n",d[i]+h);
return 0;
}

poj 3263的更多相关文章

  1. 【POJ 3263】 Tallest Cow

    [题目链接] http://poj.org/problem?id=3263 [算法] 若A和B两头牛可以互相看见,那么说明中间的牛的高度都至少比它们少1,因此,我们可以引入一个差分数组c 对于每组关系 ...

  2. POJ - 3263 差分+前缀和

    只需不断维护相对值的前缀就能得到解 这种思想第一次是在树状数组区间更新那里看到的,由于题目要求是1~n所以直接可以用前缀和维护 注意不能直接-1 +1 还有POJ的数据..要不是书里有提谁知道会这么毒 ...

  3. 【差分】POJ 3263 Tallest Cow

    题目大意 POJ链接 给出\(n\)头牛的身高,和\(m\)对关系,表示牛\(a[i]\)与\(b[i]\)可以相互看见.已知最高的牛为第\(p\)头,身高为\(h\). 求每头牛的身高最大可能是多少 ...

  4. poj 3263 Tallest Cow

    一个压了很久的题目,确实很难想,看了别人的做法后总算明白了. 首先要明白一点,因为题目说明了不会有矛盾,所以题目给出来的区间是不能相交的,否则是矛盾的.(原因自己想) 然后既然区间只能是包含的,就很明 ...

  5. Tallest Cow POJ - 3263 (区间点修改)

    FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positi ...

  6. poj 3263 Tallest Cow(线段树)

    Language: Default Tallest Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1964   Ac ...

  7. POJ 3263 差分+set判重

    题意: 思路: 对于每一个区间 [a,b] [a+1,b-1]肯定是比a,b低至少1的 因为题目要求最大值 所以就直接差分一下 搞之 (复杂度 O(n)) Discuss里说有重复的数据 用set判一 ...

  8. POJ 3263 Tallest Cow 题解

    题目 FJ's \(N (1 ≤ N ≤ 10,000)\) cows conveniently indexed 1..N are standing in a line. Each cow has a ...

  9. 一道codeforces题目引发的差分学习

    Codeforces Round #688 (Div. 2) 题目:B. Suffix Operations 题意:给定一个长为n的数组a,你可以进行两种操作:1).后缀+1;     2)后缀-1: ...

随机推荐

  1. Delphi利用Windows GDI实现文字倾斜

    Delphi利用Windows GDI实现文字倾斜 摘要 Delphi利用Windows GDI实现文字倾斜 procedure TForm1.FormPaint(Sender: TObject);v ...

  2. SQLite wrapper

    SQLiteWrapper is a C++ wrapper for SQLite. There are some test programs that demonstrate how the SQL ...

  3. LUOGU P1402 酒店之王 (网络流)

    解题思路 应该比较显然得能看出这是个网络流,将$S$与房间连边,房间与人连边,人与菜连边,菜与汇点连边,边的流量均为1.但这样是错误的,因为有可能一个人跑过去2的流量,所以要将人拆点限流. #incl ...

  4. 手机端判断安卓,iso,微信

    var uaContains = function (key) { return navigator.userAgent.toLowerCase().indexOf(key.toLowerCase() ...

  5. System.Web.Mvc.ControllerBase.cs

    ylbtech-System.Web.Mvc.ControllerBase.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, Pub ...

  6. CCPC 2019 网络赛 1002 array (权值线段树)

    HDU 6703 array   题意:   给定一个数组 \(a_1,a_2, a_3,...a_n\) ,满足 \(1 \le a[i]\le n\) 且 \(a[i]\) 互不相同.   有两种 ...

  7. 19.SimLogin_case04

    # 利用cookies登录马蜂窝 import requests from lxml import etree session = requests.Session() phone_number = ...

  8. 使用CEfSharp之旅(1) 加载网络页面

    原文:使用CEfSharp之旅(1) 加载网络页面 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https://blog.csdn ...

  9. 用MapReduce实现关系的自然连接

  10. 连接RDS数据库