【POJ 3263】 Tallest Cow
【题目链接】
http://poj.org/problem?id=3263
【算法】
若A和B两头牛可以互相看见,那么说明中间的牛的高度都至少比它们少1,因此,我们可以引入一个差分数组c
对于每组关系,我们将c[a+1]减一,c[b]加一
最后,每头牛的最高高度就是 h + c的前缀和
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010 int i,a,b,n,p,h,m;
map< pair<int,int>,bool > mp;
int d[MAXN]; int main()
{ scanf("%d%d%d%d",&n,&p,&h,&m);
for (i = ; i <= m; i++)
{
scanf("%d%d",&a,&b);
if (a > b) swap(a,b);
if (mp[make_pair(a,b)]) continue;
d[a+]--; d[b]++;
mp[make_pair(a,b)] = true;
}
for (i = ; i <= n; i++)
{
d[i] += d[i-];
printf("%d\n",h+d[i]);
} return ; }
【POJ 3263】 Tallest Cow的更多相关文章
- 【POJ 2018】 Best Cow Fences
[题目链接] http://poj.org/problem?id=2018 [算法] 二分平均值 检验时将每个数减去二分的值,求长度至少为L的子序列和的最大值,判断是否大于0 [代码] #includ ...
- 【POJ 3623】 Best Cow Line, Gold (后缀数组)
[题意] [分析] 后缀数组水题,嗯,不认真看输出像我一样就会被坑.. #include<cstdio> #include<cstdlib> #include<cstri ...
- 【POJ - 3268 】Silver Cow Party (最短路 Dijkstra算法)
Silver Cow Party Descriptions 给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x, ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
随机推荐
- centos 搭建pptp
很多朋友不会在CENTOS 在安装vpn,因为对于菜鸟来说安装VPN的确是个头晕的事情,特别是安装openvpn,不过安装pptp就稍微简单一点,国内网上有很多安装pptp的教程,但是都很繁杂,我在国 ...
- Spring框架系列(二)--装配和注入Bean
企业日常开发中,几乎都是Spring系的框架,无论是SSM.还是现在大火的SpringBoot+JPA/MyBatis,使用最大的目的就是简化开发 基本模块: 核心容器:Beans.Core.Cont ...
- P1077摆花
传送 总共要摆m盆花,而每种花最多有a[i]盆.仔细思索,发现它是一个多重背包求方案数问题.但是我蒟蒻的不会,于是跑去问大佬. 以下状态转移方程及化简from rqy 如果第i个物品有a[i],每个的 ...
- @Inherited注解
允许子类继承父类的注解 https://blog.csdn.net/renli2549/article/details/78432272
- Oracle 常用目录结构(10g)
大多数情况下,了解Oracle常用目录结构,将大大提高数据库管理与维护的工作效率,本文介绍了Oracle 10g 的常用目录. OFA: 下面给出Oracle 最优灵活体系结构OFA(Optimal ...
- Python爬虫常用库安装
建议更换pip源到国内镜像,下载会快很多:https://www.cnblogs.com/believepd/p/10499844.html requests pip3 install request ...
- scanf与getchar
如下: 5 5 R R R R R R R R R R R R R R R R R R R R R R R R R 只允许用scanf,如何写读取函数. 由于 ...
- textarea 高度调整
textarea 高度调整 通过 rows 属性调整 高度
- 【02】Node.js 安装配置(OK)
[02] Node.js 安装配置 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. Node.js安装包及源码下载地址为:http://www.nodejs.org/do ...
- 吧,其实spring自带的BeanUtils就有这样的功能,引入spring-beans和spring-core之后,就有BeanUtils.copyProperties(a, b);可以实现两个javabean之间的相互拷贝,自己写的就当是研究咯---https://www.cnblogs.com/NieXiaoHui/p/7150928.html
吧,其实spring自带的BeanUtils就有这样的功能,引入spring-beans和spring-core之后,就有BeanUtils.copyProperties(a, b);可以实现两个ja ...