题解 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 ...
随机推荐
- WPF global exception handler
WPF global exception handler [duplicate] https://stackoverflow.com/questions/1472498/wpf-global-exce ...
- nginx 的使用
nginx 反向代理,并拥有其高效的性能,并发效果好,是解决跨域最好的选择 nginx 的使用 1. 下载:在官网上下载 window 系统的 nginx 网址:http://nginx.org/en ...
- activemq备忘
ActiveMQ队列消息积压问题调研 http://blog.51cto.com/winters1224/2049432ActiveMQ的插件开发介绍 https://blog.csdn.net/zh ...
- python从入门到放弃之Tensorflow(一)
Tensorflow使用错误集锦: 错误1 : FutureWarning: Conversion of the second argument of issubdtype from ‘float’ ...
- Springboot将mybatis替换为mybatis-plus
知识点: 1.Mybatis-plus相比mybatis,功能更加强大,简而言之,不需要我们去写mapper.xml配置,但是对于特殊需求的sql语句,还是需要写mapper.xml文件中的sql语句 ...
- Linux系统管理_主题01 :初识Linux_1.7 关闭和重启Linux_shutdown
shutdown [选项] 时间 [警告消息] 系统关机 -c 取消前一个 shutdown 命令.值得注意的是,当执行一个如 “shutdown -h 11:10”的命令时,只要按“Ctrl+C ...
- 在Spring中配置jdbc为什么不能用${username}问题
楼主在spring中配置jdbc时,引用的是dbcp.jar包,在dataSource.properties配置文件中,有mysql用户名,楼主自然的选择了使用username,密码是root, 然后 ...
- kubeadm安装集群系列-5.其他操作
常用的一些操作记录 imagePullSecrets kubectl -n [namespace] create secret docker-registry regsecret --docker-s ...
- USACO 1.1 Your Ride Is Here
直接模拟 #include<cstdio> #include<cstring> using namespace std; #define MAXN 10 #define MOD ...
- Android Service 入门
说明 Service 工作在主进程上.生命周期图 两种状态 Started 比如Activity通过调用startService 方法.一旦被启动(Started),服务就永久在后台运行,即使创建他的 ...