简单的贪心。优先weight最大的,优先匹配Q值大的地区

code

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. using namespace std;
  5. struct node {
  6. int num, level, weght, p;
  7. } f[209], g[17009];
  8. int ans[17009];
  9.  
  10. bool cmp1 (node a, node b) {
  11. return a.level > b.level;
  12. }
  13. bool cmp2 (node a, node b) {
  14. return a.weght > b.weght;
  15. }
  16.  
  17. int main() {
  18. int k, n = 0;
  19. scanf ("%d", &k);
  20. for (int i = 1; i <= k; i++) {
  21. scanf ("%d", &f[i].num );
  22. n += f[i].num;
  23. }
  24. for (int i = 1; i <= k; i++) {
  25. scanf ("%d", &f[i].level );
  26. f[i].p = i;
  27. }
  28. for (int i = 1; i <= n; i++) scanf ("%d", &g[i].level );
  29. for (int i = 1; i <= n; i++) {
  30. scanf ("%d", &g[i].weght);
  31. g[i].p = i;
  32. }
  33. sort (f + 1, f + 1 + k, cmp1);
  34. sort (g + 1, g + 1 + n, cmp2);
  35. for (int i = 1; i <= n ; i++) {
  36. int j;
  37. for (j = 1; j <= k; j++)
  38. if (g[i].level > f[j].level && f[j].num > 0) break;
  39. if (j > k) continue;
  40. ans[g[i].p] = f[j].p;
  41. f[j].num--;
  42. }
  43. int i = 1, j = 1;
  44. while (i <= n && j <= k) {
  45. while (!f[j].num) j++;
  46. while (ans[i]) i++;
  47. if(i<=n&&j<=k) {
  48. ans[i] = f[j].p;
  49. f[j].num--;
  50. }
  51. }
  52. for (int i = 1; i <= n; i++)
  53. printf ("%d ", ans[i]);
  54. return 0;
  55. }

  

SGU 171.Sarov zones的更多相关文章

  1. SGU 171 Sarov zones (贪心)

    题目   SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有 ...

  2. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  3. [置顶] 2013_CSUST暑假训练总结

    2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:h ...

  4. Contest 7.21(贪心专练)

    这一次都主要是贪心练习 练习地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#overview Problem APOJ 13 ...

  5. [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 ...

  6. leetcode 171

    171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...

  7. bind9+mysql dlz(Dynamically Loadable Zones)

    yum install openssl openssl-devel groupadd mysqluseradd -g mysql -s /sbin/nologin -M mysqlchown -R m ...

  8. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  9. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

随机推荐

  1. Matlab中常用操作

    (1)换行操作: 末尾加上“...”,然后加enter:有时候多条语句重起一行,这时shift+enter >> 4*sin(0.3)*...8 (2)一些快捷键: Ctrl+R 可多行同 ...

  2. 深入hibernate的三种状态【转载】

    这篇文章写得很好,举了很多例子. http://www.cnblogs.com/xiaoluo501395377/p/3380270.html

  3. 来更新一篇blog吧

    最近做了一下hackerrank的20/20的比赛.平时都只能过2题,这周顺利地通过了四道题目竟然.当妄图冲击衬衫的时候,发现剩下三个题一点招数都没有,之后就跑去看了一下node.js了... 这次比 ...

  4. hdu 4717 The Moving Points(三分+计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...

  5. nORA-01000: 超出打开游标的最大数(SDE连接)

    1.运行ArcObjects代码报错: IFeatureCursor pCursor = null; try { pCursor = m_pCatchLayer.m_pFeatureClass.Sea ...

  6. c#基础语言编程-异常处理

    异常的定义 异常就是程序中的运行时错误,当出现异常时,系统会捕获这个错误并抛出一个异常.若程序没有提供处理该异常的代码,系统会挂起这个程序. 常见异常的类型 System.Exception 最泛化的 ...

  7. sdut-2725-The Urge to Merge-状压DP

    把数组竖起来,从上往下走. 如果当前位置是竖着乘的,那么第一个点标记为1.否则标记为0. 样例最终的状态为: 0 0 1 0 1 0 1 0 0 0 0 0 #include<iostream& ...

  8. 简单的访客IP获取类-IPHelper.cs

    public class IPHelper { public static string GetVisitorsIPAddress() { string result = String.Empty; ...

  9. 海思android4.4 SDK编译Latin输入法

    原来的HiSTBAndroidV500R001C01SPC020\device\hisilicon\bigfish\packages\apps\HiLatinIME\Android.mk内容例如以下: ...

  10. Instruction (hdu 5083)

    Instruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...