Codeforces Round #545 (Div. 2) C. Skyscrapers (离散化)
题意:
给你n*m个点,每个点有高度h [ i ][ j ] ,用[1,x][1,x]的数对该元素所处十字上的所有元素重新标号,
并保持它们的相对大小不变。n,m≤1000n,m≤1000 ,求其最小标号的最大值。
思路:
把行列离散化一下,然后答案是把十字上的所有数相对大小的最大值
代码:
#include<bits/stdc++.h>
using namespace std;
#define N 1005
int n,m;
vector<int>r[N],c[N];
int h[N][N]; int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i=;i<=n;i++) r[i].clear();
for(int j=;j<=m;j++) c[j].clear();
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&h[i][j]);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
r[i].push_back(h[i][j]);
sort(r[i].begin(),r[i].end());
r[i].erase(unique(r[i].begin(),r[i].end()),r[i].end());
}
for(int j=;j<=m;j++)
{
for(int i=;i<=n;i++)
c[j].push_back(h[i][j]);
sort(c[j].begin(),c[j].end());
c[j].erase(unique(c[j].begin(),c[j].end()),c[j].end());
}
/* for(int i=1;i<=n;i++)
{
for(int j=0;j<r[i].size();j++)
cout<<r[i][j]<<" ";
cout<<endl;
}*/
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
int tp1=lower_bound(r[i].begin(),r[i].end(),h[i][j])-r[i].begin();
int tp2=lower_bound(c[j].begin(),c[j].end(),h[i][j])-c[j].begin();
int tp3=r[i].end()-lower_bound(r[i].begin(),r[i].end(),h[i][j]);
int tp4=c[j].end()-lower_bound(c[j].begin(),c[j].end(),h[i][j]);
printf("%d ",max(tp1,tp2)+max(tp3,tp4));
}
printf("\n");
}
}
return ;
}
从中也学习了一下unique的用法
参考博客:https://www.cnblogs.com/antiquality/p/10501112.html#_label2_0
Codeforces Round #545 (Div. 2) C. Skyscrapers (离散化)的更多相关文章
- Codeforces Round #545 (Div. 2) C. Skyscrapers 离散化+贪心
题目链接 给你一个n∗m的矩阵res,让你输出一个n∗m的矩阵a,这个矩阵满足:给你一个n*m的矩阵res,让你输出一个n*m的矩阵a,这个矩阵满足:给你一个n∗m的矩阵res,让你输出一个n∗m的矩 ...
- Codeforces Round #545 (Div. 2)C(离散化,思维,PAIR排序)
#include<bits/stdc++.h>using namespace std;int a[1007][1007];pair<int,int>p1[1007],p2[10 ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- Codeforces Round #545 (Div. 1) Solution
人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...
- Codeforces Round #545 (Div. 1)
本来开头两道题写得挺快的,然后第三题想了一会儿胡出一个scc计算gcd的做法,写了一发凭借信仰交了上去结果一发pp了?然后第四题沙雕了想了很久才会,于是罚时瞬间变多.结果后面两题都没时间看了,赛后感觉 ...
- Codeforces Round #215 (Div. 2) D题(离散化+hash)
D. Sereja ans Anagrams time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #545 (Div. 2) D 贪心 + kmp
https://codeforces.com/contest/1138/problem/D 题意 两个01串s和t,s中字符能相互交换,问最多能得到多少个(可交叉)的t 题解 即将s中的01塞进t中, ...
- Codeforces Round #545 (Div. 2) D
链接:http://codeforces.com/contest/1138/problem/D 啊啊啊啊啊啊,自闭啊,比赛的时候判断条件 if(s1[i-1]=='0') aa++;写成了 if(s1 ...
随机推荐
- zip(), dict(), itertools.repeat(), list(迭代器)
*. zip(), dict() def demo_zip_dict(): keys = ['a', 'b', 'c'] values = [1, 2, 3] entrys = zip(keys, v ...
- Centos logrotate截断tomcat日志文件
1. 设置logrotate轮转日志文件 tomcat日志目录:/usr/local/tomcat/apache-tomcat-8.5.34/logs /etc/logrotate.d/目录下创建to ...
- 51nod1730 涂边
题目描述 题解 八级sb题 显然可以想到状压 枚举当前的宽度\(I\),设\(f[s]\)表示在当前的宽度下选的竖边的状态为s 再设\(g[s1][s2]\)表示状态s1转移到s2的方案数,枚举中间横 ...
- 解决json不能解析换行问题
今天遇到一个问题,当我读取数据库中某条带换行的数据时,解析错误. 解决方法是在存入数据库时对数据做处理,把换行换成其他字符.代码如下: remark = remark.replace(/\n/g,&q ...
- JS audio播放一个的时候,其他正在播放的关闭
audio在使用中,如果有多个,在播放的时候,如果一个声音没有播放完继续下一个的话,原来正在播放的并不会关闭(在Android和PC上测试是这样,苹果产品不清楚) 现在需要做的是,当播放其中一个的时候 ...
- python图像处理——频率域增强
图像的傅里叶变换: import chardet import numpy as np import cv2 as cv import cv2 from PIL import Image import ...
- 基于BootStrap的分页代码实现
public class PageUtil { //targetUrl 访问url totalNum总记录数 currentPage 当前页数 pageSize每页的大小 public static ...
- 大数据笔记(十三)——常见的NoSQL数据库之HBase数据库(A)
一.HBase的表结构和体系结构 1.HBase的表结构 把所有的数据存到一张表中.通过牺牲表空间,换取良好的性能. HBase的列以列族的形式存在.每一个列族包括若干列 2.HBase的体系结构 主 ...
- vsphere client 虚拟机随主机自动启动
- VMware 虚拟化编程(13) — VMware 虚拟机的备份方案设计
目录 目录 前文列表 备份思路 备份算法 备份细节 连接到 vCenter 还是 ESXi 如何选择快照类型 是否开启 CBT 如何获取备份数据 如何提高备份数据的传输率 备份厚置备磁盘和精简置备磁盘 ...