L2-039 清点代码库

注:所谓数列 { 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;
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值