• 题目链接:

    https://www.luogu.org/problemnew/show/P2879

  • 思路:

    先不管最大高度,我们读入一对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】的更多相关文章

  1. bzoj1635 / P2879 [USACO07JAN]区间统计Tallest Cow

    P2879 [USACO07JAN]区间统计Tallest Cow 差分 对于每个限制$(l,r)$,我们建立一个差分数组$a[i]$ 使$a[l+1]--,a[r]++$,表示$(l,r)$区间内的 ...

  2. 洛谷P2879 [USACO07JAN]区间统计Tallest Cow

    To 洛谷.2879 区间统计 题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. ...

  3. 洛谷 P2879 [USACO07JAN]区间统计Tallest Cow

    传送门 题目大意: n头牛,其中最高身高为h,给出r对关系(x,y) 表示x能看到y,当且仅当y>=x并且x和y中间的牛都比 他们矮的时候,求每头牛的最高身高. 题解:贪心+差分 将每头牛一开始 ...

  4. [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 ...

  5. [USACO07JAN]区间统计Tallest Cow

    前缀和 sum[i]表示前i个数的和 每次读入a[i]的时候 sum[i] = sum[i - 1] + a[i]; 查询l ~ r区间的和: sum[r] - sum[l - 1] 差分 即前缀和的 ...

  6. [Luogu] 区间统计Tallest Cow

    https://www.luogu.org/problemnew/show/P2879 差分 | 线段树 #include <iostream> #include <cstdio&g ...

  7. 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 ...

  8. 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 ...

  9. BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 346  Solved: 184 ...

随机推荐

  1. Qt学习之如何启动和终止一个线程

    先来给出每个文件的相关代码然后再加以分析 //*************dialog.h**************// #ifndef DIALOG_H #define DIALOG_H #incl ...

  2. tensorflow中一个矩阵和一个向量相加

    import tensorflow as tf x=tf.constant([[1,2],[3,4]]) y=tf.constant([[1],[1]])#列向量 z=tf.constant([1,1 ...

  3. Chrome console不输出内容

    设置成info就好了

  4. .netcore centos配置systemctl自动启动

    systemd分两种服务系统和用户服务 对应存储位路径为系统(/usr/lib/systemd/system).用户(/etc/systemd/user/) [Unit] Description=ap ...

  5. Python写的大小写转换小工具

    几行代码的小工具,用于进行如下转换 TRANSACTIONS ON CLOUD COMPUTING => Transactions On Cloud Computing orig = 'TRAN ...

  6. PCD(点云数据)文件格式

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=54 为什么用一种新的文件格式? PCD文件格式并非白费力气地做重复工作,现有 ...

  7. 002-tomcat目录简介、应用部署【自动部署 ② 控制台部署 ③ 自定义部署】

    一.目录及功能 主目录下有bin,conf,lib,logs,temp,webapps,work 7个文件夹 1.1.bin目录[重要] bin目录主要是用来存放tomcat的命令,主要有两大类,一类 ...

  8. 转 MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法

    http://blog.sina.com.cn/s/blog_637e04c9010117ri.html 1 问题 [root@localhost mysql]# /etc/rc.d/init.d/m ...

  9. centos6 安装tensorflow

    1.升级python2.6.6 至 python2.7.12+ 升级时./configure --prefix=/usr/local/python27 --enable-unicode=ucs4 2. ...

  10. SAP JCO3配置

    windows 环境设置 1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 例如: 新建环境变量 变量名: JAV ...