关于CSP-S T2爆零
  • 板块学术版
  • 楼主Tom俩
  • 当前回复7
  • 已保存回复7
  • 发布时间2020/11/18 13:16
  • 上次更新2023/11/5 07:47:53
查看原帖
关于CSP-S T2爆零
198716
Tom俩楼主2020/11/18 13:16

RT,为什么我自测有60分,实际成绩却只有0分。 代码如下:

#include <bits/stdc++.h>
using namespace std;
int n, m, c, k;
vector<int> table[65];
vector<int> table2[100005];
vector<int> foodlist;
bool vis[100005];
bool vis2[65];
int p[100005];
struct disc {
    int ori, id, now;
} q[100005];
bool cmp1(disc a, disc b) {
    return a.ori < b.ori;
} 
bool cmp2(disc a, disc b) {
    return a.id < b.id;
}
int main() {
    freopen("zoo.in", "r", stdin);
    freopen("zoo.out", "w", stdout);
    long long type = 0;
    scanf("%d%d%d%d", &n, &m, &c, &k);
    for (int i = 1; i <= n; i++) {
        long long a;
        scanf("%lld", &a);
        type |= a;
    }
    for (int i = 1; i <= m; i++)
        scanf("%d%d", &p[i], &q[i].ori);
    sort(q + 1, q + m + 1, cmp1);
    for (int i = 1; i <= m; i++) {
        q[i].now = q[i - 1].now;
        if (q[i].ori != q[i - 1].ori)
            q[i].now++;
    }
    sort(q + 1, q + m + 1, cmp2);
    for (int i = 1; i <= m; i++) {
        vis2[p[i]] = true;
        table[p[i]].push_back(q[i].now);
        table2[q[i].now].push_back(p[i]);
    }
    int bitcnt = 0;
    while (type) {
        if (type & 1) {
            for (int i = 0; i < table[bitcnt].size(); i++) {
                if (vis[table[bitcnt][i]])
                    continue;
                vis[table[bitcnt][i]] = true;
                foodlist.push_back(table[bitcnt][i]);
            }
        }
        type >>= 1;
        bitcnt++;
    }
    long long animal = 0;
    for (int i = 0; i < foodlist.size(); i++) {
        int foodname = foodlist[i];
        for (int j = 0; j < table2[foodname].size(); j++)
            animal |= (1 << table2[foodname][j]);
    }
    int cnt = 0;
    while (animal) {
        if (animal & 1)
            cnt++;
        animal >>= 1;
    }
    for (int i = 0; i < k; i++)
        if (!vis2[i])
            cnt++;
    printf("%lld", (1 << cnt) - n);
}
2020/11/18 13:16
加载中...