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 ...
随机推荐
- Asp.Net MVC向视图View传值的三种常见的方法:
1.通过View( parameter )的参数传递 action: public ActionResult Index() { Person person=new Person("wumi ...
- rspec学习02
元数据 RSpec-core存储元数据哈希每实例和组,其中包含他们的描述,声明的位置等等,这个hash控制很多RSpec核心的功能,包括输出格式化程序(访问描述和位置),和before,after钩子 ...
- Unity3d HDR和Bloom效果(高动态范围图像和泛光)
文章开始先放两组效果,文章结尾再放两组效果本文测试场景资源来自浅墨大神,shader效果为本文效果 HDR 人们有限的视觉系统,只支持16.7百万的颜色,超出这个范围的颜色就不能显示了bmp或jprg ...
- ACM_2057
/* 2013暑期多校联合训练 - 80 +高校,300 +队伍,10000元奖金,敬请期待? A + B再次 时间限制:1000/1000 MS(JAVA /其他)内存限制:32768分之32768 ...
- linux mono
linux下.net环境; rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm &am ...
- Graphs and Minimum Cuts(Karger's Min-Cut Algorithm)
Graphs Two ingredients 1. vertices (nodes) v 2. edges(undirected or directed) Examples: road networ ...
- sonarQube Scanner
到现在为止,已经将sonarQube服务器搭建好,服务器是Linux服务器,基于sonarQube6.1配置的 原理关于sonarQube的工作原理,暂时还不是太清楚,据同事的分析,是在本机调用服务器 ...
- 关于平移的 scrollTo和scrollBy的区别
这几天在项目中要求一部分布局实现整体偏移的效果 在网上查了下我使用来ScrollBy(x,y)方法 他的意思是将view实现整体偏移 而ScollTo(x,y)则是将原点偏移到相应指定的位置即 移 ...
- mapreduce 读写lzo文件
1.读lzo文件 需要添加以下代码,并导入lzo相关的jar包 job.setInputFormatClass(LzoTextInputFormat.class); 2.写lzo文件 lzo格式默认 ...
- Oracle 同步表权限分配(同义词)
新建了同义词之后还要 分配权限