poj 3263 Tallest Cow
一个压了很久的题目,确实很难想,看了别人的做法后总算明白了。
首先要明白一点,因为题目说明了不会有矛盾,所以题目给出来的区间是不能相交的,否则是矛盾的。(原因自己想)
然后既然区间只能是包含的,就很明显了,一个数被包含了几次它就要比最高的牛矮多少。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e4+9;
struct D
{
int l,r;
bool operator <(const struct D & xx) const
{
if(l==xx.l)
return r<xx.r;
return l<xx.l;
}
}qry[maxn];
int dp[maxn];
int main()
{
int n,m,h,r;
scanf("%d %d %d %d",&n,&m,&h,&r);
for(int i=1;i<=r;i++)
{
scanf("%d %d",&qry[i].l,&qry[i].r);
if(qry[i].l>qry[i].r)
swap(qry[i].l,qry[i].r);
}
sort(qry+1,qry+1+r);
qry[0].l=0;
for(int i=1;i<=r;i++)
{
if(qry[i].l==qry[i-1].l&&qry[i].r==qry[i-1].r)
continue;
dp[qry[i].l+1]--;
dp[qry[i].r]++;
}
int ret=0;
for(int i=1;i<=n;i++)
{
ret+=dp[i];
printf("%d\n",ret+h);
}
return 0;
}
poj 3263 Tallest Cow的更多相关文章
- poj 3263 Tallest Cow(线段树)
Language: Default Tallest Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1964 Ac ...
- 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 ...
- 【差分】POJ 3263 Tallest Cow
题目大意 POJ链接 给出\(n\)头牛的身高,和\(m\)对关系,表示牛\(a[i]\)与\(b[i]\)可以相互看见.已知最高的牛为第\(p\)头,身高为\(h\). 求每头牛的身高最大可能是多少 ...
- 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 ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 346 Solved: 184 ...
- BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MB Description FJ's N ( ...
- 1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 383 Solved: 211 ...
- 洛谷P2879 [USACO07JAN]区间统计Tallest Cow
To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. ...
随机推荐
- QRadionButton 圆点样式
QRadioButton::indicator { width: 13px; height: 13px;} QRadioButton::indicator::unchecked { ...
- 函数重载不仅仅是看其参数,还要看是否有const修饰
比如QString有两个函数,可以堂而皇之的存在,原因就在于有了const修饰以后,编译器不把两个函数当作同一个函数名了: QChar * data() const QChar * data() co ...
- AVOS Cloud Hackathon - SegmentFault
AVOS Cloud Hackathon - SegmentFault AVOS Cloud Hackathon
- HDU4648+Easy
N^2都能过!!!!!!! /* Easy */ #include<stdio.h> #include<string.h> #include<stdlib.h> # ...
- pod update --verbose --no-repo-update
最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级Co ...
- 【jQuery】使用JQ来编写面板的淡入淡出效果
本文与上一篇的<[jQuery]使用JQ来编写最主要的淡入淡出效果>(点击打开链接)为姊妹篇. 但上一篇仅仅是对文本的基本控制,本篇则是对面板元素进行控制. 尽管功能上很类似,可是所用到的 ...
- Android:自己定义输入法(输入password时防止第三方窃取)
对于Android用户而言.一般都会使用第三方的输入法. 但是,在输入password时(尤其是支付相关的password),使用第三方输入法有极大的安全隐患. 眼下非常多网银类的APP和支付宝等软件 ...
- iOS开发之理解iOS中的MVC设计模式
模型-视图-控制器(Model-View-Controller,MVC)是Xerox PARC在20世纪80年代为编程语言Smalltalk-80发明的一种软件设计模式,至今已广泛应用于用户交互应用程 ...
- redis的管理工具
phpredisadmin工具 rdbtools管理工具 saltstack管理redis 通过codis完成redis管理 一:phpredisadmin工具:类似于mysqladmin管理mysq ...
- CodeForces 543A - Writing Code DP 完全背包
有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后 ...