SGU171:Sarov zones

贪心,将W从大到小排序,每次选P-Q最小的。

#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> pii;

inline int read()
{
    int x = 0; int v = 1, c = getchar();
    for(; c < '0' || c > '9'; c = getchar()) if(c == '-') v = -1;
    for(;c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    return x * v;
}

template<typename T>
inline void write(T x, int ch = 10)
{
    int s[20], t = 0;
    if(x < 0) { x = -x; putchar('-'); }
    do s[t++] = x % 10; while(x /= 10);
    while(t--) putchar('0' + s[t]);
    putchar(ch);
}

#define rep(i, a, b) for(register int i = (a); i <= (b); ++i)

const int maxn = 16005;
const int maxk = 105;

int n, k;
int w[maxn], p[maxn];
int num[maxk], q[maxk];
int orz[maxn], city[maxn];

void input()
{
    k = read();
    rep(i, 1, k) n += num[i] = read();
    rep(i, 1, k) q[i] = read();
    rep(i, 1, n) p[i] = read();
    rep(i, 1, n) w[i] = read();
}

bool cmp(int a, int b)
{
    return w[a] > w[b];
}

void solve()
{
    rep(i, 1, n) orz[i] = i;
    sort(orz + 1, orz + n + 1, cmp);
    rep(i, 1, n)
    {
        int xj = 0, Min = 2e9;
        rep(j, 1, k)
        {
            if(num[j] && p[orz[i]] > q[j])
            {
                int tmp = p[orz[i]] - q[j];
                if(tmp < Min)
                {
                    Min = tmp;
                    xj = j;
                }
            }
        }
        if(xj)
        {
            city[orz[i]] = xj;
            num[xj]--;
        }
    }
    rep(i, 1, n) if(!city[i])
        rep(j, 1, k)
            if(num[j])
            {
                num[j]--;
                city[i] = j;
                break;
            }
}

void output()
{
    rep(i, 1, n) write(city[i], ' ');
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    input();
    solve();
    output();

#ifndef ONLINE_JUDGE
    fprintf(stderr, "Run Time: %dms\n", clock());
    fclose(stdin), fclose(stdout);
#endif
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值