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 ...
随机推荐
- 使用logrotate轮询nginx和apache日志
使用logrotate轮询nginx和apache日志 文章目录 [隐藏] 配置nginx 配置apache 使用logrotate轮询日志很方便,配置也很简单. 配置nginx 1.建立/e ...
- vue组件结构
1.组件结构 2.项目结构
- 查询重复数据group by menu_id having count(menu_id)>1
select * from sys_power_menu WHERE menu_id in ( select menu_id from sys_power_menu group by menu_id ...
- Headless Windows
Google Chrome 79.0.3945.79 (正式版本) (64 位) (cohort: 79_Win_79) .\chrome --headless --user-data-dir=tmp ...
- asp.net大文件上传解决方案
以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传 ...
- [洛谷2257]ZAP-Queries 题解
前言 这道题还是比较简单的 解法 首先将题目转化为数学语言. 题目要我们求的是: \[\sum_{i=1}^a\sum_{j=1}^b[gcd(i,j)=d]\] 按照套路1,我们将其同时除以d转换为 ...
- GPSMap程序源代码
1. 界面 第一次打开时选择工程文件 MainActivity.java Tools.OpenDialog(new ICallback(){ public void OnClick(String pa ...
- 移动端续讲及zepto移动端插件外加touch插件介绍
媒体查询:针对不同设备,显示不同的样式. 设备像素比:dpr device-piexl-ratio 在he开发中,要一个3陪高清图片: 1080>=320*3 (主要是为了解决图片的失真问题) ...
- php system exexc 立即返回
有时候会用到php调用服务器端的其它可执行文件,system和exec函数都是阻塞执行的,执行完第三方程序再返回. 如果我们需要立即返回,让第三方程序在后台继续执行,调用方式如下: linux,noh ...
- Gradle 详解
Gradle简单来说,就是工程的管理,帮我们做了依赖,打包,部署,发布等工作.就像一个管家管理我们的项目,我们只用关心写代码就可以了. 1 gradle-wraaper.properties 主工程的 ...