题解 P2879 【[USACO07JAN]区间统计Tallest Cow】
思路:
先不管最大高度,我们读入一对x,y.说明,x+1~y-1之间牛的身高都小于x,y。
然后不妨将这个区间打个标记-1。所有操作后,可知最高的那个牛它的标记一定是0,并且标记数量与身高排名正相关,于是再将所有奶牛的标记数加上最高身高h就是可能的最大身高。
因为之前的操作保证标记的数量是按着身高排名来的,加上最大身高当然是最大可能身高。
然后我们是要将x+1~y-1打标记,根据差分数组的思维,就要让x+1处-1,y处+1。
注意:
- 判重,用map,pair或hash。
- 可能读入x,y大小关系符的需要swap
代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=10005;
int n,m,h,i;
int f[maxn],tp[maxn];
bool h_[19260817]; //暴力Hash需谨慎 逃)
bool m_hash(int x,int y)
{
int t=(x*y+x/y+x+y+(x>>1)-(y>>1))%19260817; +1s
if(h_[t])return 0;
else h_[t]=1;
return 1;
}
int main()
{
cin>>n>>i>>h>>m;
for(register int i=1;i<=m;i++)
{
register int a,b;
scanf("%d %d",&a,&b);
if(a>b)swap(a,b);
if(m_hash(a,b)){
tp[a+1]--,tp[b]++;
}
}
for(register int i=1;i<=n;i++)
{
f[i]=f[i-1]+tp[i];
cout<<f[i]+h<<endl;
}
return 0;
}
题解 P2879 【[USACO07JAN]区间统计Tallest Cow】的更多相关文章
- bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow
P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...
- 洛谷P2879 [USACO07JAN]区间统计Tallest Cow
To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. ...
- 洛谷 P2879 [USACO07JAN]区间统计Tallest Cow
传送门 题目大意: n头牛,其中最高身高为h,给出r对关系(x,y) 表示x能看到y,当且仅当y>=x并且x和y中间的牛都比 他们矮的时候,求每头牛的最高身高. 题解:贪心+差分 将每头牛一开始 ...
- [Luogu2879][USACO07JAN]区间统计Tallest Cow
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a p ...
- [USACO07JAN]区间统计Tallest Cow
前缀和 sum[i]表示前i个数的和 每次读入a[i]的时候 sum[i] = sum[i - 1] + a[i]; 查询l ~ r区间的和: sum[r] - sum[l - 1] 差分 即前缀和的 ...
- [Luogu] 区间统计Tallest Cow
https://www.luogu.org/problemnew/show/P2879 差分 | 线段树 #include <iostream> #include <cstdio&g ...
- 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 ...
- 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 ...
- BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛
1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 346 Solved: 184 ...
随机推荐
- python安装appium模块
(base) localhost:~ ligaijiang$ pip3 install Appium-Python-Client Collecting Appium-Python-Client Dow ...
- linux下的开源NFC协议栈
1. 协议栈名称 neardal 2. 源码 https://github.com/connectivity/neardal.git 3. 由谁维护? intel 4. 基于neardal的nfc协议 ...
- LC 738. Monotone Increasing Digits
Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...
- MYSQL通过循环向数据库中插入数据
BEGINdeclare i int default 305;declare a char(255);REPEATset a=concat("测试机构00",cast(i as c ...
- JVM源码分析之JDK8下的僵尸(无法回收)类加载器[z]
[z]http://lovestblog.cn/blog/2016/04/24/classloader-unload/ 概述 这篇文章基于最近在排查的一个问题,花了我们团队不少时间来排查这个问题,现象 ...
- Linux下通过crontab命令来实现定时任务
一.crond的介绍 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cr ...
- React Native初始化项目0.47.1报错
首先看一下安卓和iOS报错: iOS终端运行报错: Xcode运行报错: 解决办法一: 将版本降到0.44.3,修改package,具体请看我的另一篇博客: http://www.cnblogs.co ...
- 安装flanal报错解决
1.:Error registering network: failed to acquire lease: node "test4" pod cidr not assigned ...
- Java数组(3):创建测试数据
有时我们需要使用数组批量创建测试数据,接下来通过以下4点来举例. (1) 使用Arrays.fill()填充数据 (2) 使用Random类中JDK1.8提供的新方法用来生成随机数 (3) 一个随机数 ...
- 在TeamCity中执行gtest单元测试
1. 在Visual Studio 2017中新建一个gtest项目 Sample-Test1.这个项目会自动安装“Microsoft.googletest.v140.windesktop.msvcs ...