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 ...
随机推荐
- 网络流(最大流)CodeForces 512C:Fox And Dinner
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). T ...
- Selenium如何实现dropbar移动
遇到这个拖拽的dropbar,如何实现呢,, 经过网上查找,可以用Action的方式实现或者js来控制 原理:移动按钮的同时,数字也随着变化 解决方法:1.最简单的就是直接在文本框输入相应的数字 2. ...
- leetcode 最大矩形和
1.枚举法(超时) public class Solution { public int largestRectangleArea(int[] height) { int max=-1; for(in ...
- poj 2505 A multiplication game(博弈)
A multiplication game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5622 Accepted: ...
- Linux process state codes
Here are the different values that the s, stat and state output specifiers (header "STAT" ...
- udev:renamed network interface eth0 to eth1
删除/etc/udev/rules.d/70-persistent-net.rules这个文件,重启
- poj 1696 Space Ant 极角排序
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...
- 2015/11/06 社保查询系统持续 挂机ing
- TOYS - POJ 2318(计算几何,叉积判断)
题目大意:给你一个矩形的左上角和右下角的坐标,然后这个矩形有 N 个隔板分割成 N+1 个区域,下面有 M 组坐标,求出来每个区域包含的坐标数. 分析:做的第一道计算几何题目....使用叉积判断方 ...
- Xcode7.1与iOS9之坑
一.更改http为https 两种方案: 公司后台服务器更改; 作为开发者,可在Xcode暂时退回到http协议. 开发者更改方法如下: 在Info.plist中添加App Transport Se ...