当前位置: 首页 > news >正文

[USACO07JAN]区间统计Tallest Cow

题目描述

FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of that cow.

FJ has made a list of R (0 ≤ R ≤ 10,000) lines of the form "cow 17 sees cow 34". This means that cow 34 is at least as tall as cow 17, and that every cow between 17 and 34 has a height that is strictly smaller than that of cow 17.

For each cow from 1..N, determine its maximum possible height, such that all of the information given is still correct. It is guaranteed that it is possible to satisfy all the constraints.

给出牛的可能最高身高,然后输入m组数据 a b,代表a,b可以相望,最后求所有牛的可能最高身高输出

输入输出格式

输入格式:

Line 1: Four space-separated integers: N, I, H and R

Lines 2..R+1: Two distinct space-separated integers A and B (1 ≤ A, B ≤ N), indicating that cow A can see cow B.

输出格式:

Lines 1..N: Line i contains the maximum possible height of cow i.

输入输出样例

输入样例#1: 复制
9 3 5 5
1 3
5 3
4 3
3 7
9 8
输出样例#1: 复制
5
4
5
3
4
4
5
5
5

有头牛从1到n线性排列,每头牛的高度为h[i]现在告诉你这里面的牛的最大高度为maxH,而且有r组关系,每组关系输入两个数字,假设为a和b,表示第a头牛能看到第b头牛,能看到的条件是a, b之间的其它牛的高度都严格小于min(h[a], h[b]),而h[b] >= h[a]
最后求所有牛的可能最高身高输出

先将身高全部假设为最高身高
把给的信息(a,b)去重之后,为了使[a+1,b-1]内所有数都小于v[a],v[b]只需要区间减1即可
维护一个差分数组,在x[a]++,x[b+1]--然后扫一遍就可以得到每个位置的值



 1 //2018年2月14日17:41:54
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <map>
 5 using namespace std;
 6 
 7 const int N = 100001;
 8 
 9 int n, id, f[N], m;
10 map<pair<int, int>, bool> mp;
11 
12 int main(){
13     scanf("%d%d%d%d", &n, &id, &f[1], &m);
14     while(m--){
15         int x, y;
16         scanf("%d%d", &x, &y);
17         if(x > y) swap(x, y);
18         if(x != y){
19             if(mp[pair<int, int>(x, y)] != 1){
20                 mp[pair<int, int>(x, y)] = 1;
21                 f[x+1]--;
22                 f[y]++;
23             }
24         }
25     }
26     for(int i=1, now=0;i<=n;i++)
27         printf("%d\n", now+=f[i]);
28 
29     return 0;
30 }

 



转载于:https://www.cnblogs.com/sineagle/p/8448610.html

相关文章:

  • 【题集】k倍区间(抽屉原理)
  • 006 数组
  • 寒假作业3
  • 前端面试题 ---- html篇
  • CSS实现点击3D效果
  • 2018/02/24
  • Vijos p1772 巧妙填数
  • js 中的call apply
  • 对RESTfull的初见理解
  • 微信小程序开发01
  • 敏捷软件开发:原则、模式与实践
  • Linux chown问题分享
  • 【转载】Git,Github和Gitlab简介和基本使用Gitlab安装和使用
  • 面试中自己项目和你应该问的问题环节总结
  • AMR文件结构
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • 【comparator, comparable】小总结
  • 30秒的PHP代码片段(1)数组 - Array
  • eclipse(luna)创建web工程
  • GDB 调试 Mysql 实战(三)优先队列排序算法中的行记录长度统计是怎么来的(上)...
  • Hexo+码云+git快速搭建免费的静态Blog
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • js如何打印object对象
  • Magento 1.x 中文订单打印乱码
  • SQLServer之创建显式事务
  • 高性能JavaScript阅读简记(三)
  • 构建二叉树进行数值数组的去重及优化
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 关于for循环的简单归纳
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 基于遗传算法的优化问题求解
  • 技术胖1-4季视频复习— (看视频笔记)
  • 跨域
  • 如何进阶一名有竞争力的程序员?
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • 由插件封装引出的一丢丢思考
  • 原生 js 实现移动端 Touch 滑动反弹
  • FaaS 的简单实践
  • ​queue --- 一个同步的队列类​
  • # 安徽锐锋科技IDMS系统简介
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • #周末课堂# 【Linux + JVM + Mysql高级性能优化班】(火热报名中~~~)
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • (01)ORB-SLAM2源码无死角解析-(66) BA优化(g2o)→闭环线程:Optimizer::GlobalBundleAdjustemnt→全局优化
  • (02)Cartographer源码无死角解析-(03) 新数据运行与地图保存、加载地图启动仅定位模式
  • (1)安装hadoop之虚拟机准备(配置IP与主机名)
  • (env: Windows,mp,1.06.2308310; lib: 3.2.4) uniapp微信小程序
  • (Redis使用系列) Springboot 使用Redis+Session实现Session共享 ,简单的单点登录 五
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (八)Docker网络跨主机通讯vxlan和vlan
  • (二)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (九)One-Wire总线-DS18B20
  • (力扣题库)跳跃游戏II(c++)
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (三)centos7案例实战—vmware虚拟机硬盘挂载与卸载