SGU 171.Sarov zones
简单的贪心。优先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的更多相关文章
- SGU 171 Sarov zones (贪心)
题目 SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- [置顶] 2013_CSUST暑假训练总结
2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:h ...
- Contest 7.21(贪心专练)
这一次都主要是贪心练习 练习地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#overview Problem APOJ 13 ...
- [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 ...
- leetcode 171
171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...
- bind9+mysql dlz(Dynamically Loadable Zones)
yum install openssl openssl-devel groupadd mysqluseradd -g mysql -s /sbin/nologin -M mysqlchown -R m ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
随机推荐
- 开发备必:WEB前端开发规范文档
为提高团队协作效率, 便于后台人员添加功能及前端后期优化维护, 输出高质量的文档, 特制订此文档. 本规范文档一经确认, 前端开发人员必 须按本文档规范进行前台页面开发. 本文档如有不对或者不合适的地 ...
- URAL1079
Problem E Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/16384K (Java/Other) Total Sub ...
- Ubuntu系统下为IDEA创建启动图标
默认情况下,ubuntu将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,需要在该目录下创建一个名为“idea.desktop”的文件. ...
- a^b-b^a - SGU 112(高精度快速幂)
分析:直接上吧,建议不要使用模板,否则没啥意义了. 代码如下: ==================================================================== ...
- java.lang.ClassCastException: Ljava.lang.Object; cannot be cast to com.entity.Advertisem异常
今天一不小心就碰到了这样的问题,以前从来没有碰到过,在网上搜了很多办法,思路正确,但是还是要根据自己的程序改变. 一开始写的是hql语句进行统计每个月的数据,但是试了很久,程序一直提醒hql语句异常, ...
- Eclipse(Myeclipse)安装GoogleGWT
1,下载gpe http://code.google.com/p/googleappengine/并安装. 2,下载gwt http://code.google.com/intl/zh-CN/webt ...
- php mysqli注意问题
今天写了这个一段代码 function ip_get_method($action , $device){ if($action != 'search'){ request_die(false,'un ...
- STL的基本使用之关联容器:set和multiSet的基本使用
STL的基本使用之关联容器:set和multiSet的基本使用 简介 set 和 multiSet 内部都是使用红黑树来实现,会自动将元素进行排序.两者不同在于set 不允许重复,而multiSet ...
- Bash远程文件传输命令scp
备份远程文件(远程——>本地) scp -r 远程用户名@ip:文件绝对路径 本地绝对路径 还原远程文件(本地——>远程) scp -r 本地路径 远程用户名@ip:远程绝对路径 如果SS ...
- linux下sed命令笔记
sed 流编辑器 Stream EDitor三大文本处理工具:grep,sed,awk 语法:sed 'AddressCommand' file ...Address: 1,StartLine, ...