Swordsman

ps:比赛的时候想到了做法,k次排序,然后每次消去能消的。。。然而这种做法是错误的,神奇的是测试案例中排在奇数的案例会WA,排在偶数的案例都过了,被注释的代码会T.

#include<bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define P pair<int, int>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define lson root << 1
#define INF32 (int)2e9 + 7
#define rson root << 1 | 1
#define INF64 (unsigned long long)1e18
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define mem(arry, in) memset(arry, in, sizeof(arry))
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

namespace fastIO {
    #define BUF_SIZE 100000
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};
using namespace fastIO;

inline void upd(int &x, int y) { x < y && (x = y); }

const int N = 100005;

P a[15][N];
int T, n, k, v[10], b[N][15], point[15], cnt[N], c[N][15];
bool use[N];

int main()
{
    //freopen("D:\\1.in", "r", stdin);
    //freopen("D:\\1.txt", "w", stdout);
    read(T);
    while(T--) {
        read(n), read(k);
        for (int i = 1; i <= k; ++i) read(v[i]);
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= k; ++j) {
                read(a[j][i].first);
                a[j][i].second = i;
                //c[i][j] = a[j][i].first;
            }
            for (int j = 1; j <= k; ++j) read(b[i][j]);
        }

        mem(cnt, 0);
        mem(point, 0);
        //mem(use, 0);

        int ans = 0;
        for (int i = 1; i <= k; ++i) sort(a[i] + 1, a[i] + 1 + n);
        /*
// 写的代码真的很搓,也许换种优秀的写法就过了 sort(a[1] + 1, a[1] + n + 1); while(1) { int oldans = ans; for (int j = 1; j <= n; ++j) if (!use[a[1][j].second]) { int id = a[1][j].second;           if (c[id][1] > v[1]) break; int tot = 0; for (int q = 1; q <= k; ++q) if (c[id][q] <= v[q]) { tot++; } if (tot == k) { for (int q = 1; q <= k; ++q) v[q] += b[id][q]; use[id] = 1; ans++; } } if (oldans == ans) break; }
*/ while(1) { int oldans = ans; for (int i = 1; i <= k; ++i) { while(point[i] < n && a[i][point[i] + 1].first <= v[i]) { int x = a[i][++point[i]].second; cnt[x]++; if (cnt[x] == k) { ++ans; for (int j = 1; j <= k; ++j) v[j] += b[x][j]; } } } if (oldans == ans) break; } pr(ans); for (int i = 1; i < k; ++i) printf("%d ", v[i]); pr(v[k]); } return 0; }

 

posted @ 2018-08-14 15:09  天之道,利而不害  阅读(303)  评论(0编辑  收藏  举报