简单的贪心。优先weight最大的,优先匹配Q值大的地区

code

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node {
int num, level, weght, p;
} f[209], g[17009];
int ans[17009]; bool cmp1 (node a, node b) {
return a.level > b.level;
}
bool cmp2 (node a, node b) {
return a.weght > b.weght;
} int main() {
int k, n = 0;
scanf ("%d", &k);
for (int i = 1; i <= k; i++) {
scanf ("%d", &f[i].num );
n += f[i].num;
}
for (int i = 1; i <= k; i++) {
scanf ("%d", &f[i].level );
f[i].p = i;
}
for (int i = 1; i <= n; i++) scanf ("%d", &g[i].level );
for (int i = 1; i <= n; i++) {
scanf ("%d", &g[i].weght);
g[i].p = i;
}
sort (f + 1, f + 1 + k, cmp1);
sort (g + 1, g + 1 + n, cmp2);
for (int i = 1; i <= n ; i++) {
int j;
for (j = 1; j <= k; j++)
if (g[i].level > f[j].level && f[j].num > 0) break;
if (j > k) continue;
ans[g[i].p] = f[j].p;
f[j].num--;
}
int i = 1, j = 1;
while (i <= n && j <= k) {
while (!f[j].num) j++;
while (ans[i]) i++;
if(i<=n&&j<=k) {
ans[i] = f[j].p;
f[j].num--;
}
}
for (int i = 1; i <= n; i++)
printf ("%d ", ans[i]);
return 0;
}

  

SGU 171.Sarov zones的更多相关文章

  1. SGU 171 Sarov zones (贪心)

    题目   SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有 ...

  2. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  3. [置顶] 2013_CSUST暑假训练总结

    2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:h ...

  4. Contest 7.21(贪心专练)

    这一次都主要是贪心练习 练习地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#overview Problem APOJ 13 ...

  5. [REP]AWS Regions and Availability Zones: the simplest explanation you will ever find around

    When it comes to Amazon Web Services, there are two concepts that are extremely important and spanni ...

  6. leetcode 171

    171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...

  7. bind9+mysql dlz(Dynamically Loadable Zones)

    yum install openssl openssl-devel groupadd mysqluseradd -g mysql -s /sbin/nologin -M mysqlchown -R m ...

  8. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  9. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

随机推荐

  1. 贪心(哈夫曼树):HDU 5884 sort

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2QAAAKACAIAAAB8KCy/AAAgAElEQVR4nOy9a5Adx3UmWL+kHxuekU ...

  2. Longest Consecutive Sequence——Leetcode

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  3. 2013腾讯编程马拉松初赛第一场(3月21日) 湫湫系列故事——减肥记II ----线段树

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4509 虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动! 于是,结果显而易见… 但 ...

  4. AFNetworking2.0 NSHipster翻译

    AFNetworking 是当前 iOS 和 Mac OS X 开发中最广泛使用的开源项目之一.它帮助了成千上万叫好又叫座的应用,也为其它出色的开源库提供了基础.这个项目是社区里最活跃.最有影响力的项 ...

  5. Linux 下DNS服务器主从配置

    注意: 关闭防火墙  关闭selinux  在客户端配置vim /etc/resolv.conf的DNS  安装  yum install -y bind bind-chroot bind-utils ...

  6. 【设计模式 - 4】之原型模式(Prototype)

    1      模式简介 原型模式的定义:通过复制一个现有的对象(原型)来得到一个相似的对象. 原型模式的UML图如下图所示: 从上图中可以看到,所有的对象实体类都是继承自一个Prototype的父类, ...

  7. 【Android - 进阶】之MultiDex的配置

    一.什么是MultiDex 随着时代的进步,人们对手机 APP 的需求越来越大,越来越苛刻,很多APP都变得很大,再加上APP都不可避免的需要导入一些框架.第三方类库等等,就更加大了项目的整体文件体系 ...

  8. SQL字符串处理函数大全

    select语句中只能使用sql函数对字段进行操作(链接sql server),select 字段1 from 表1 where 字段1.IndexOf("云")=1;这条语句不对 ...

  9. linux lsof命令详解

    linux lsof命令详解 简介 lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访 ...

  10. UVa 993: Product of digits

    这道题很简单.先将N用2,3,5,7(即10以内的素数)分解因数(需要先特殊判断N不为1),然后将可以合并的因数合并(如2*2合并成4,)这样求得的结果位数会减少,大小肯定会小一些.具体实现见代码. ...