注:所谓数列 { A1, ..., AM } 比 { B1, ..., BM } 大,是指存在 1≤i<M,使得 A1=B1,...,Ai=Bi 成立,且 Ai+1>Bi+1。
输入样例:
7 3
35 28 74
-1 -1 22
28 74 35
-1 -1 22
11 66 0
35 28 74
35 28 74
输出样例:
4
3 35 28 74
2 -1 -1 22
1 11 66 0
1 28 74 35
看样例可以猜一下题意,没猜出来的话,题目在下面:
一些知识点:
#关于排序重载:
struct node{
vector<int>v;
int ct;
bool operator <(const node&n1) const{
if(ct==n1.ct) return v<n1.v;
return ct>n1.ct;
}
};
#map中的key可以是任何类型:
#map<vector<int>,int>p;
#vector数组可以直接通过 ">" 比较大小
ac代码:
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
struct node{
vector<int>v;
int ct;
bool operator <(const node&n1) const{
if(ct==n1.ct) return v<n1.v;
return ct>n1.ct;
}
}; //!!!
map<vector<int>,int>p;
vector<node> ans;
int n,m;
int main(){
cin>>n>>m;
while(n--){
vector<int> v;
for(int i=0;i<m;i++){
int num; scanf("%d",&num);
v.push_back(num);
}
if(p[v]) p[v]++; //v 是一个vector也可以直接做下标
else p[v]=1;
}
cout<<p.size()<<endl;
for(auto it=p.begin();it!=p.end();it++){
node nod;
nod.ct=it->second; nod.v=it->first;
ans.push_back(nod);
}
sort(ans.begin(),ans.end());
for(auto i:ans){
printf("%d",i.ct);
for(auto j:i.v) printf(" %d",j);
printf("\n");
}
return 0;
}