题目传送门

题意:

给你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 (离散化)的更多相关文章

  1. Codeforces Round #545 (Div. 2) C. Skyscrapers 离散化+贪心

    题目链接 给你一个n∗m的矩阵res,让你输出一个n∗m的矩阵a,这个矩阵满足:给你一个n*m的矩阵res,让你输出一个n*m的矩阵a,这个矩阵满足:给你一个n∗m的矩阵res,让你输出一个n∗m的矩 ...

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

  3. Codeforces Round #545 (Div. 1) 简要题解

    这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...

  4. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)

    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...

  5. Codeforces Round #545 (Div. 1) Solution

    人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...

  6. Codeforces Round #545 (Div. 1)

    本来开头两道题写得挺快的,然后第三题想了一会儿胡出一个scc计算gcd的做法,写了一发凭借信仰交了上去结果一发pp了?然后第四题沙雕了想了很久才会,于是罚时瞬间变多.结果后面两题都没时间看了,赛后感觉 ...

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

  8. Codeforces Round #545 (Div. 2) D 贪心 + kmp

    https://codeforces.com/contest/1138/problem/D 题意 两个01串s和t,s中字符能相互交换,问最多能得到多少个(可交叉)的t 题解 即将s中的01塞进t中, ...

  9. Codeforces Round #545 (Div. 2) D

    链接:http://codeforces.com/contest/1138/problem/D 啊啊啊啊啊啊,自闭啊,比赛的时候判断条件 if(s1[i-1]=='0') aa++;写成了 if(s1 ...

随机推荐

  1. 【leetcode】1129. Shortest Path with Alternating Colors

    题目如下: Consider a directed graph, with nodes labelled 0, 1, ..., n-1.  In this graph, each edge is ei ...

  2. 【leetcode】698. Partition to K Equal Sum Subsets

    题目如下: 解题思路:本题是[leetcode]473. Matchsticks to Square的姊妹篇,唯一的区别是[leetcode]473. Matchsticks to Square指定了 ...

  3. HTML中的marquee标签实现滚动效果

    一.标签<marquee>简介 通过开始标签<marquee>和结束标签</marquee>的共同配合而实现滚动效果,<marquee>滚动的内容< ...

  4. Java——容器(List)

    [List接口]  

  5. Distinctive Image Features from Scale-Invariant Keypoints(SIFT) 基于尺度不变关键点的特征描述子——2004年

    Abstract摘要本文提出了一种从图像中提取特征不变性的方法,该方法可用于在对象或场景的不同视图之间进行可靠的匹配(适用场景和任务).这些特征对图像的尺度和旋转不变性,并且在很大范围的仿射失真.3d ...

  6. [CSP-S模拟测试]:环(图论+期望)

    题目传送门(内部题79) 输入格式 第一行读入两个整数$n,e$表示节点数及$cwystc$已确定的有向边边数. 接下来$e$行,每行两个整数$x,y$描述$cwystc$确定的边. 输出格式 输出一 ...

  7. HTTP入门(二):用Chrome开发者工具查看 HTTP 请求与响应

    HTTP入门(二):用Chrome开发者工具查看 HTTP 请求与响应 本文简单总结HTTP的请求与响应. 本文主要目的是对学习内容进行总结以及方便日后查阅. 详细教程和原理可以参考HTTP文档(MD ...

  8. org.xml.sax.SAXParseException: 元素类型 "input" 必须由匹配的结束标记 "</input>" 终止。

    错误记录 Spring Boot推荐使用thymeleaf作为视图,按照SpringBoot实战一书的案例写Demo. 发生错误: org.xml.sax.SAXParseException: 元素类 ...

  9. vue 的sync用法

    这个关键字在v2.3.0+ 新增,注意带有 .sync 修饰符的 v-bind 不能和表达式一起使用 (例如 v-bind:title.sync=”doc.title + ‘!’” 是无效的).说白了 ...

  10. sql数据库收缩

    回收步骤: 1.查看日志文件大小[一般回收比较大的] --适用于RDS For SQL Server2012\2016 SELECT DB_NAME(database_id) AS [Database ...