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. ...
随机推荐
- 编程的毛病——C++之父访谈
原文见:http://www.technologyreview.com/InfoTech/17831/ 翻译:xeon 11/29/2006 在20世纪的80年代和90年代,Bjarne Strou ...
- Eclipse 编码区-保护色-快捷大全
Eclipse快捷键大全 Eclipse编码区-保护色-快捷设置 1.设置路径: windows-preferences-general-editors-text Editors-ba ...
- vc 获取网页内容(HTTP)
BOOL bResult = FALSE; // 初始化WinInet 环境 HINTERNET hInternet = InternetOpen("CEHTTP", ...
- 你会用swift创建复杂的加载动画吗(1)
时至今日,iOS 应用商店已经拥有超过了140万 应用,让你自己的应用脱颖而出确实是个不小的挑战.不过,在你的应用掉入默默无闻的大黑洞之前,你拥有一个小小的机遇窗,它能帮你吸引用户的注意. AD: 时 ...
- js 验证手机号 以及身份证正则表达式
手机号:① /^1(3[0-9]{9}|5[0-35-9][0-9]{8}|7[07][0-9]{8}|8[25-9][0-9]{8})$/ ② /^1(3\d|5[0-35-9]|7[07]|8[2 ...
- [Swust OJ 491]--分数的位置(简单版)
题目链接:http://acm.swust.edu.cn/problem/0491/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- ContentProvider中的数据生成时机
目录结构: , 先给个结论: 仅仅是实例化mySqliteHelper()这个类的时候是不会创建数据库的,实际上数据库的真正创建是在helper.getWritableDatabase()的方法执行后 ...
- __autoload函数
./index.php----------------------------------------------------------------------------------<?ph ...
- This exception may occur if matchers are combined with raw values
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!3 ma ...
- hdu 2276 Kiki & Little Kiki 2
点击打开hdu 2276 思路: 矩阵快速幂 分析: 1 题目给定一个01字符串然后进行m次的变换,变换的规则是:如果当前位置i的左边是1(题目说了是个圆,下标为0的左边是n-1),那么i就要改变状态 ...