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 ...
随机推荐
- SD卡中FAT32文件格式快速入门(图文详细介绍)
说明: MBR :Master Boot Record ( 主引导记录) DBR :DOS Boot Record ( 引导扇区) FAT :File Allocation Table ( 文件分配表 ...
- MYSQL删除以数字开头的字段
例子: // 删除以0开头的字段 DELETE FROM `week_energy_copy` WHERE openid like '0%'; // 删除以数字开头的字段 DELETE FROM `w ...
- Delphi实现WebService带身份认证的数据传输
WebService使得不同开发工具开发出来的程序可以在网络连通的环境下相互通信,它最大的特点就是标准化(基于XML的一系列标准)带来的跨平台.跨开发工具的通用性,基于HTTP带来的畅通无阻的能力(跨 ...
- 用Delphi 实现WebService 转
一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application 选择IS ...
- Tree2cycle
Problem Description A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, w ...
- C++之拷贝构造函数
为什么要引入拷贝构造函数?(提出问题) 作用:创建一个对象的同时,使用一个已经存在的对象给另一个对象赋值 做比较:拷贝构造函数:对象被创建 + 用一个已经存在的对象 进行初始化 拷贝赋值函数:对象已 ...
- hdu 4465 Candy(二次项概率)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4465 参考博客:http://www.cnblogs.com/goagain/archive/2012 ...
- Treasure Hunt - POJ 1066(线段相交判断)
题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙. 分析:这个题意刚开 ...
- 320. Generalized Abbreviation
首先想到的是DFS,对于每个单词的字母都遍历,比如 spy: 1py,s1y,sp1 然后每个遍历完的单词再DFS..左右有数字就合并比如 1py: 11y=>2py, 1p1 这样.. 但是单 ...
- thinkphp xml编码函数
/** * XML编码 * @param mixed $data 数据 * @param string $root 根节点名 * @param string $item 数字索引的子节点名 * @pa ...