CCFCSP推荐系统

此题有一个大坑id范围为1e9

此题题意是按照同类按照价格大小从大到小输出,如果价格相等再按照id从小到大输出。

​#include<bits/stdc++.h>
using namespace std;
struct node{
    int id;
    int score;
    int type;
    int sell;
    bool friend operator < (node a,node b){
        if(a.score != b.score) return a.score > b.score;
        else if(a.type != b.type) return a.type < b.type;
        else if(a.id != b.id) return a.id < b.id;
    }
};

map<long long,int> mp1;
set<node> s;

int n,m;
int main()
{
    //ios::sync_with_stdio(0);
    cin >> m >> n;
    for(int i = 0;i < n;i++){
        node temp;
        cin >> temp.id >> temp.score;
        for(int j = 0;j < m;j++){
            temp.type = j;
//            long long xx = temp.type * 1e9 + temp.id;
//            mp1[xx] = temp;
            s.insert(temp);
        }
    }
    int num;
    cin >> num;
    while(num--){
        int opt;cin >> opt;
        if(opt == 1){
            int type;
            cin >> type;
            node temp;
            cin >> temp.id >> temp.score;
            temp.type = type;
//            long long xx = temp.type * 1e9 + temp.id;
//            mp1[xx] = 1;
            s.insert(temp);
        }
        else if(opt == 2){
            int type;
            cin >> type;
            int id;cin >> id;
            long long xx = type * 1e9 + id;
            mp1[xx] = 1;
        }
        else if(opt == 3){
            int k;cin >> k;
            vector<int> g2;
            //int sum = 0;
            for(int i = 0;i < m;i++){
                int t;cin >> t;
                g2.push_back(t);
                //sum += t;
            }
            vector<int> ans[55];
            int p = k;
//            cout << "商品:" << endl;
//            for(set<node>::iterator it = s.begin();it != s.end();it++){
//
//                node temp = *it;
//                cout << temp.type << " " << temp.id << " " << temp.score << endl;
//            }
            for(set<node>::iterator it = s.begin();it != s.end();it++){
                node temp = *it;
                int type = temp.type;
                long long xx = temp.type * 1e9 + temp.id;
                if(mp1.find(xx) != mp1.end()) continue;
                if(g2[type] > 0){
                    p--;
                    g2[type]--;
                    ans[type].push_back(temp.id);
                    //sum--;
                }
                //if(sum == 0) break;
                if(p == 0) break;
            }
            for(int i = 0;i < m;i++){
                int len = ans[i].size();
                if(len == 0){
                    cout << -1 << endl;
                }
                else{
                    //sort(ans[i].begin(),ans[i].end());
                    for(int j = 0;j < len;j++){
                        cout << ans[i][j];
                        if(j != len - 1) cout << " ";
                    }
                    cout << endl;
                }
            }

        }
    }

    return 0;
}
​

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值