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 ...
随机推荐
- Matlab中常用操作
(1)换行操作: 末尾加上“...”,然后加enter:有时候多条语句重起一行,这时shift+enter >> 4*sin(0.3)*...8 (2)一些快捷键: Ctrl+R 可多行同 ...
- 深入hibernate的三种状态【转载】
这篇文章写得很好,举了很多例子. http://www.cnblogs.com/xiaoluo501395377/p/3380270.html
- 来更新一篇blog吧
最近做了一下hackerrank的20/20的比赛.平时都只能过2题,这周顺利地通过了四道题目竟然.当妄图冲击衬衫的时候,发现剩下三个题一点招数都没有,之后就跑去看了一下node.js了... 这次比 ...
- hdu 4717 The Moving Points(三分+计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...
- nORA-01000: 超出打开游标的最大数(SDE连接)
1.运行ArcObjects代码报错: IFeatureCursor pCursor = null; try { pCursor = m_pCatchLayer.m_pFeatureClass.Sea ...
- c#基础语言编程-异常处理
异常的定义 异常就是程序中的运行时错误,当出现异常时,系统会捕获这个错误并抛出一个异常.若程序没有提供处理该异常的代码,系统会挂起这个程序. 常见异常的类型 System.Exception 最泛化的 ...
- sdut-2725-The Urge to Merge-状压DP
把数组竖起来,从上往下走. 如果当前位置是竖着乘的,那么第一个点标记为1.否则标记为0. 样例最终的状态为: 0 0 1 0 1 0 1 0 0 0 0 0 #include<iostream& ...
- 简单的访客IP获取类-IPHelper.cs
public class IPHelper { public static string GetVisitorsIPAddress() { string result = String.Empty; ...
- 海思android4.4 SDK编译Latin输入法
原来的HiSTBAndroidV500R001C01SPC020\device\hisilicon\bigfish\packages\apps\HiLatinIME\Android.mk内容例如以下: ...
- Instruction (hdu 5083)
Instruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...