题目传送门

题意:

给你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. java web中乱码的种类和一些解决方式

    在java web课堂测试中遇到了一些乱码问题 ,从百度上找到了许多种解决方法和乱码的种类,在这里总结一下. 一.文件出现乱码 [右击文件]->[Properties]->[Resourc ...

  2. man da'te

    DATE(1)                 用户命令                      DATE(1) 名称  日期-打印或设置系统日期和时间  简介   date [OPTION]... ...

  3. [UVa1057] Routing

    问题描述 As more and more transactions between companies and people are being carried out electronically ...

  4. 微信小程序-坑1-await-async

    VM45:1 thirdScriptError sdk uncaught third Error regeneratorRuntime is not defined ReferenceError: r ...

  5. android 7.0适配(总结)

    file_paths.xml <?xml version="1.0" encoding="utf-8"?><paths xmlns:andro ...

  6. Actor Roles 图示

    Udemy上的教程<Unreal Multiplayer Mastery - Online Game Development in C++>中对Actor Roles的总结非常直观到位,一 ...

  7. 使用java语言实现一个队列(两种实现比较)(数据结构)

    一.什么是队列,换句话说,队列主要特征是什么? 四个字:先进先出 六个字:屁股进,脑袋出 脑补个场景:日常排队买饭,新来的排在后面,前面打完饭的走人,这就是队列: OK,思考一个问题,我为什么写了两种 ...

  8. WCF - Home

    https://www.tutorialspoint.com/wcf/index.htm WCF Tutorial WCF stands for Windows Communication Found ...

  9. 使用Mybatis执行sql脚本

    pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  10. Linux驱动开发5——同步机制

    上一章讲到了并发,指的是多个进程同时存取临界区资源的处理机制.这一章讲的同步机制,讲的是多个进程之间协同工作的处理机制,如临界区数据还没有准备好,A进程负责准备数据,B进程等待A进程完成之后读取数据. ...