额,,,其实这题很简单,就是因为我不知道unique函数的用法,所以我才错了
unique(开始的迭代器,结束的迭代器,表示相等的函数(=))
这个函数
1.使用前要先排序(如果想要去重)
2.返回一段不重复序列的末端
3.会将重复多余的内容放到返回值和容器末端之间,而不是将他们删除
因此,如果你只是想将这个容器去重,那么你要,sort,unique,最重要的是,最后还要erase删掉重复的元素
//Problem:
//Date:
//Skill:
//Bug:
/Definations/
//循环控制
#define CLR(a) memset((a),0,sizeof(a))
#define F(i,a,b) for(int i=a;i<=int(b);++i)
#define F2(i,a,b) for(int i=a;i>=int(b);--i)
#define RE(i,n) for(int i=0;i<int(n);i++)
#define RE2(i,n) for(int i=1;i<=int(n);i++)
//输入输出
//#define INC(c) do{scanf("%c",&c);}while(isspace(c))
//#define ON cout<<endl
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
Options//
typedef long long ll;
#define stdcpph
#define CPP_IO
#ifdef stdcpph
#include<bits/stdc++.h>
#else
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#ifdef CPP_IO
#include<iostream>
#include<iomanip>
#include<string>
#else
#include<stdio.h>
#endif
#endif
Basic Functions//
template<typename INint>
inline void IN(INint &x)
{
x = 0; int f = 1; char c; cin.get(c);
while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); }
while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); }
x *= f;
}
template<typename INint>
inline void OUT(INint x)
{
if (x > 9)OUT(x / 10); cout.put(x % 10 + '0');
}
Added Functions//
const int maxn = int(1e3 + 4);
int n, m;
PII H[maxn][maxn];
int ans[maxn][maxn];
int a[maxn][maxn];
int ope(PII A, PII B)
{
return max(A.first, B.first) + max(A.second, B.second) + 1;
}
void get1(vector<int>&v, int row)
{
sort(v.begin(), v.end());
int cnt = unique(v.begin(), v.end()) - v.begin();
v.erase(v.begin() + cnt, v.end());
RE2(j, m)
{
int x = a[row][j];
int xiao = lower_bound(v.begin(), v.end(), x) - v.begin();
int da = cnt - 1 - xiao;
H[row][j] = PII(xiao, da);
if (row == 5 && j == 4)
j=j;
}
}
void get2(vector<int>&v, int col)
{
sort(v.begin(), v.end());
int cnt = unique(v.begin(), v.end()) - v.begin();
v.erase(v.begin() + cnt, v.end());
RE2(i, n)
{
int x = a[i][col];
int xiao = lower_bound(v.begin(), v.end(), x) - v.begin();
int da = cnt - 1 - xiao;
ans[i][col] = ope(PII(xiao, da), H[i][col]);
}
}
Code/
int main()
{
//freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
int T(1), times(0);
#ifdef CPP_IO// CPP_IO
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
//cin >> T;
#else
//IN(T);
#endif
/
while (++times, T--)
{
srand(int(time(0)));
cin >> n >> m;
RE2(i, n)RE2(j, m)cin >> a[i][j];
//RE2(i, n)RE2(j, m)a[i][j] = rand() % 20;
RE2(i, n)
{
vector<int>v;
RE2(j, m)v.push_back(a[i][j]);
get1(v, i);
}
RE2(j, m)
{
vector<int>v;
RE2(i, n)
v.push_back(a[i][j]);
get2(v, j);
}
RE2(i, n)
{
RE2(j, m)
{
cout << ans[i][j] << ' ';
}
cout << endl;
}
}
///
return 0;
}