给你n个数字组成原数列;
然后,让你生成n个新的数列a
其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列;
然后问你这n个数列组成的排序数组(即按照把第i个位置上的数改为第i大的数在未改变之前数组中的位置这个规则转化成的数组);
有多少种不同类型
首先,枚举第i个数字被删掉了;
然后用结构体来存剩下的n-1个数字形成的数组,
(存数值和下标)
然后排序,获取第i大的数的下标;
存到vector里面,用map< vector < int >,int>来判重;
0
map判重很方便。
遇到要知道下标的,一般都用结构体排序吧;
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
//head
struct abc{
int x,id;
};
abc a[N];
map <vector <int>,int > dic;
bool cmp(abc a,abc b){
return a.x > b.x;
}
class RelativeHeights
{
public:
int countWays(vector <int> h)
{
int ans = 0;
dic.clear();
int len = h.size(),n;
vector <int> v;
rep1(i,0,len-1){
n = 0;
rep1(j,0,len-1)
if (i!=j){
n++;
a[n].id = n-1,a[n].x = h[j];
}
sort(a+1,a+1+n,cmp);
v.clear();
rep1(j,1,n){
v.pb(a[j].id);
}
if (!dic[v]){
ans++;
dic[v] = 1;
}
}
return ans;
}
};