A. HDU 5999 The Third Cup is Free

简单模拟。

B. HDU 6000 Wash

n 件衣服, m 个洗衣机,k 个烘干机。每个洗衣机和烘干机需要不同的时间。问 n 件衣服洗完 + 烘干最小时间。

看做两部:洗 + 烘干,用洗需要时间长的去配烘干需要时间短的,所有衣服取max。

优先队列维护,取最小的,加上时长再放进去。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <queue>
  5. using namespace std;
  6. typedef long long LL;
  7. typedef pair<LL, int> pr;
  8.  
  9. int main()
  10. {
  11. int t;
  12. scanf("%d", &t);
  13. for (int ca = 1; ca <= t; ca++)
  14. {
  15. int n, m, k;
  16. scanf("%d%d%d", &n, &m, &k);
  17.  
  18. priority_queue<pr, vector<pr>, greater<pr> > q1, q2;
  19. LL x;
  20. for (int i = 1; i <= m; i++)
  21. scanf("%lld", &x), q1.push(pr(x, x));
  22. for (int i = 1; i <= k; i++)
  23. scanf("%lld", &x), q2.push(pr(x, x));
  24.  
  25. vector<LL> a, b;
  26. LL ans = 0;
  27. for (int i = 1; i <= n; i++)
  28. {
  29. pr tmp = q1.top(); q1.pop();
  30. a.push_back(tmp.first); q1.push(pr(tmp.first + tmp.second, tmp.second));
  31. }
  32. int len = a.size();
  33. for (int i = 1; i <= n; i++)
  34. {
  35. pr tmp = q2.top(); q2.pop();
  36. q2.push(pr(tmp.first + tmp.second, tmp.second));
  37. ans = max(ans, a[len-i] + tmp.first);
  38. }
  39.  
  40. printf("Case #%d: %lld\n", ca, ans);
  41. }
  42. }

C. HDU 6001 Mr.Panda and Survey

容斥 + DFS

D. HDU 6002 Game Leader

优先队列贪心

E. HDU 6003 Problem Buyer

贪心。

F. HDU 6004 Periodical Cicadas

DP预处理 + exgcd

G. HDU 6005 Pandaland

给你一些边,求最小环。边数 <= 4000。

枚举每条边,设其长度为 inf 后求两端点的最短路,最后再把答案加上原本的边长。

最短路用堆优化的Dijkstra,若 dis + 边长 > ans直接停止,否则会TLE。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <map>
  6. #include <queue>
  7. #include <set>
  8. using namespace std;
  9. typedef pair<int, int> pr;
  10. const int INF = 0x3f3f3f3f;
  11. const int maxn = 4000 + 100;
  12. int n;
  13. int sz = 0, tot;
  14. int v[2*maxn], last[2*maxn], nxt[2*maxn], lo[2*maxn];
  15. int dis[2*maxn], vis[2*maxn], ans;
  16.  
  17. void build(int x,int y,int z)
  18. {
  19. sz++;
  20. v[sz] = y, nxt[sz] = last[x], last[x] = sz, lo[sz] = z;
  21. sz++;
  22. v[sz] = x, nxt[sz] = last[y], last[y] = sz, lo[sz] = z;
  23. }
  24.  
  25. int Dijkstra(int s, int t, int extr)
  26. {
  27. for (int i = 1; i <= tot; i++)
  28. dis[i] = INF, vis[i] = 0;
  29. dis[s] = 0;
  30. priority_queue<pr, vector<pr>, greater<pr> > q;
  31. q.push(pr(0, s));
  32.  
  33. while(!q.empty())
  34. {
  35. pr node = q.top(); q.pop();
  36. int x = node.second, length = node.first;
  37. if (length + extr > ans) break;
  38. if (vis[x]) continue;
  39. vis[x] = 1;
  40. for (int i = last[x]; i; i = nxt[i])
  41. if (dis[v[i]] > dis[x] + lo[i])
  42. {
  43. dis[v[i]] = dis[x] + lo[i];
  44. q.push(pr(dis[v[i]], v[i]));
  45. }
  46. }
  47. return dis[t];
  48. }
  49.  
  50. int main()
  51. {
  52. int t;
  53. scanf("%d", &t);
  54. for (int ca = 1; ca <= t; ca++)
  55. {
  56. tot = sz = 0;
  57. memset(last, 0, sizeof(last));
  58.  
  59. map<pr, int> mp;
  60. scanf("%d", &n);
  61. int x1, x2, y1, y2, x;
  62. for (int i = 1; i <= n; i++)
  63. {
  64. scanf("%d%d%d%d%d", &x1,&y1,&x2,&y2,&x);
  65. if (mp[pr(x1, y1)] == 0) mp[pr(x1, y1)] = ++tot;
  66. if (mp[pr(x2, y2)] == 0) mp[pr(x2, y2)] = ++tot;
  67. build(mp[pr(x1, y1)], mp[pr(x2, y2)], x);
  68. }
  69.  
  70. ans = INF;
  71. for (int i = 1; i <= sz; i += 2)
  72. {
  73. int x = v[i], y = v[i+1];
  74. int tmplen = lo[i];
  75. lo[i] = lo[i+1] = INF;
  76. ans = min(ans, Dijkstra(x, y, tmplen) + tmplen);
  77. lo[i] = lo[i+1] = tmplen;
  78. }
  79.  
  80. if (ans >= INF) ans = 0;
  81.  
  82. printf("Case #%d: %d\n", ca, ans);
  83. }
  84. }

H. HDU 6006 Engineer Assignment

n 个工程,每个工程都有一些需求的领域。 m 个工程师,每个工程师有几个擅长的领域,且仅能被分配到一个项目。

当且仅当一些工程师满足了项目的全部需求领域,这个项目才会被完成。问最多可以完成几个项目。

n,m都很小,预处理出每个项目需要的工程师,状态压缩 + 背包。

(x & j) == x时,证明 j 包含 x; j ^ x 就是 j 代表的集合减去 x 代表的集合。

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <vector>
  5. #include <set>
  6. using namespace std;
  7. const int maxn = 10 + 10;
  8.  
  9. vector<int> a[maxn], b[maxn];
  10. int e[maxn][1 << 11];
  11. int dp[maxn][1 << 11];
  12.  
  13. int main()
  14. {
  15. int t;
  16. scanf("%d", &t);
  17. for (int ca = 1; ca <= t; ca++)
  18. {
  19. int n, m, k, x;
  20. scanf("%d%d", &n, &m);
  21.  
  22. for (int i = 1; i <= n; i++) a[i].clear();
  23. for (int j = 1; j <= m; j++) b[j].clear();
  24. memset(e, 0, sizeof(0));
  25.  
  26. for (int i = 1; i <= n; i++)
  27. {
  28. scanf("%d", &k);
  29. for (int j = 1; j <= k; j++)
  30. scanf("%d", &x), a[i].push_back(x);
  31. }
  32. for (int i = 1; i <= m; i++)
  33. {
  34. scanf("%d", &k);
  35. for (int j = 1; j <= k; j++)
  36. scanf("%d", &x), b[i].push_back(x);
  37. }
  38.  
  39. for (int i = 1; i <= n; i++)
  40. {
  41. set<int> st;
  42. for (int j = 0; j < a[i].size(); j++) st.insert(a[i][j]);
  43.  
  44. for (int j = 1; j < (1<<m); j++)
  45. {
  46. set<int> s2;
  47. for (int k = 0; k < m; k++)
  48. if (j & (1<<k)) for (int l = 0; l < b[k+1].size(); l++) s2.insert(b[k+1][l]);
  49.  
  50. set<int> :: iterator it;
  51. int flag = 1;
  52. for (it = st.begin(); it != st.end(); it++)
  53. if (!s2.count(*it))
  54. {
  55. flag = 0;
  56. break;
  57. }
  58.  
  59. e[i][j] = flag;
  60. }
  61. }
  62.  
  63. for (int i = 1; i <= n; i++)
  64. for (int j = 1; j < (1<<m); j++)
  65. {
  66. dp[i][j] = dp[i-1][j];
  67. for (int x = 1; x < (1<<m); x++)
  68. if (e[i][x] && (x&j) == x)
  69. dp[i][j] = max(dp[i][j], dp[i-1][j^x] + 1);
  70. }
  71.  
  72. int ans = 0;
  73. for (int i = 1; i < (1<<m); i++)
  74. ans = max(ans, dp[n][i]);
  75.  
  76. printf("Case #%d: %d\n", ca, ans);
  77. }
  78. }

  

I. HDU 6007 Mr. Panda and Crystal

制造所有宝石都是可以用花费来衡量的。最短路跑出所有宝石的最小制作费用,然后完全背包就可以了。

一种宝石可以更新花费,当且仅当有一种配方的总花费小于它的花费。可以用vector记录配方信息,然后再用一个vector记录每个宝石的配方下标。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <queue>
  6. using namespace std;
  7. typedef long long LL;
  8. const int maxn = 300 + 10;
  9. const int maxm = 400010;
  10. const int INF = 0x3f3f3f3f;
  11.  
  12. int dis[maxn], weg[maxn];
  13. int vis[maxn];
  14. vector<int> a[maxn], aid[maxn], sum[maxn], tp[maxn];
  15. int v[2*maxm], last[2*maxm], nxt[2*maxm];
  16. int dp[maxm];
  17.  
  18. int n, m, k, sz;
  19.  
  20. void build(int x, int y)
  21. {
  22. sz++;
  23. v[sz] = y, nxt[sz] = last[x], last[x] = sz;
  24. }
  25.  
  26. bool relax(int x, int y)
  27. {
  28. int siz = tp[y].size(), res = INF;
  29. for (int i = 0; i < siz; i++)
  30. {
  31. int to = tp[y][i], s = aid[to].size(), ans = 0, flag = 0;
  32. for (int j = 0; j < s; j++)
  33. {
  34. int ad = aid[to][j], sm = sum[to][j];
  35. if (dis[ad] == INF)
  36. {
  37. flag = 1;
  38. break;
  39. }
  40. ans += dis[ad] * sm;
  41. }
  42. if (flag == 0) res = min(res, ans);
  43. }
  44.  
  45. if (dis[y] > res)
  46. return dis[y] = res, true;
  47. return false;
  48. }
  49.  
  50. void SPFA()
  51. {
  52. queue<int> q;
  53. memset(vis, 0, sizeof(vis));
  54.  
  55. for (int i = 1; i <= n; i++)
  56. if (dis[i] != INF) q.push(i), vis[i] = 1;
  57.  
  58. while(!q.empty())
  59. {
  60. int x = q.front(); q.pop();
  61. for (int i = last[x]; i; i = nxt[i])
  62. if (relax(x, v[i]) && !vis[v[i]])
  63. vis[v[i]] = 1, q.push(v[i]);
  64. vis[x] = 0;
  65. }
  66. }
  67.  
  68. int main()
  69. {
  70. int t;
  71. scanf("%d", &t);
  72. for (int ca = 1; ca <= t; ca++)
  73. {
  74. sz = 0;
  75. memset(last, 0, sizeof(last));
  76.  
  77. scanf("%d%d%d", &m, &n, &k);
  78. for (int i = 0; i < max(n, k); i++) aid[i].clear(), sum[i].clear(), tp[i].clear();
  79. //死在这里的clear了。不能只循环到n,因为k可能大于n。
  80.  
  81. for (int i = 1; i <= n; i++)
  82. {
  83. int typ;
  84. scanf("%d", &typ);
  85. typ == 1 ? scanf("%d", &dis[i]):dis[i] = INF;
  86. scanf("%d", &weg[i]);
  87. }
  88.  
  89. for (int i = 1; i <= k; i++)
  90. {
  91. int x, s, fr, d;
  92. scanf("%d%d", &x, &s);
  93. for (int j = 1; j <= s; j++)
  94. {
  95. scanf("%d%d", &fr, &d);
  96. build(fr, x);
  97. aid[i].push_back(fr), sum[i].push_back(d);
  98. }
  99. tp[x].push_back(i);
  100. }
  101.  
  102. SPFA();
  103.  
  104. memset(dp, 0, sizeof(dp));
  105. for (int i = 1; i <= n; i++)
  106. for (int j = dis[i]; j <= m; j++)
  107. dp[j] = max(dp[j], dp[j-dis[i]]+weg[i]);
  108.  
  109. printf("Case #%d: %d\n", ca, dp[m]);
  110. }
  111. }

  

  

J. HDU 6008 Worried School

题意复杂。

set判重即可,分别求出两个名次。注意 region + final <= G-1 时是 "ADVANCED!" 。

K. HDU 6009 Lazors

模拟。

L. HDU 6010 Daylight Saving Time

模拟。只要处理出second Sunday in March first Sunday in November 是几号就可以了。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7. const int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  8.  
  9. int run(int x)
  10. {
  11. if (x%4 == 0 && x%100 != 0) return 1;
  12. if (x%400 == 0) return 1;
  13. return 0;
  14. }
  15.  
  16. int day(int y, int m, int d)
  17. {
  18. int sum = 0;
  19. for (int i = 2007; i < y; i++)
  20. sum += 365 + run(i);
  21.  
  22. for (int i = 1; i < m; i++)
  23. {
  24. sum += mon[i];
  25. if (run[y] && i == 2) sum++;
  26. }
  27.  
  28. sum += d;
  29. return sum%7;
  30. }
  31.  
  32. int main()
  33. {
  34.  
  35. int t;
  36. scanf("%d", &t);
  37.  
  38. for (int ca = 1; ca <= t; ca++)
  39. {
  40. int y, m, d, h, mi, s;
  41. scanf("%d-%d-%d %d:%d:%d", &y,&m,&d,&h,&mi,&s);
  42. int pst = 0, pdt = 0;
  43.  
  44. int times = 0, Nov = 1, Mar = 1;
  45. for (int i = 1; i <= 30; i++)
  46. {
  47. if (!day(y, 11, i)) times++;
  48. if (times == 2) { Nov = i; break; }
  49. }
  50. times = 0;
  51. for (int i = 1; i <= 30; i++)
  52. {
  53. if (!day(y, 11, i)) times++;
  54. if (times == 2) { Mar = i; break; }
  55. }
  56.  
  57. printf("Case #%d: ", ca);
  58.  
  59. if (m > 3 && m < 11) printf("PDT");
  60. if (m > 11 || m < 3) printf("PST");
  61. if (m == 3)
  62. {
  63. if (h >= 3) printf("PDT");
  64. else if (h < 2) printf("PST");
  65. else printf("Neither");
  66. }
  67. else if (m == 11)
  68. {
  69. if (h >= 2) printf("PST");
  70. else if (h < 1) printf("PDT");
  71. else printf("Both");
  72. }
  73. printf("\n");
  74.  
  75. }
  76. }

  

CCPC 2016-2017, Finals的更多相关文章

  1. 【转】2016/2017 Web 开发者路线图

    链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  3. 关于ECMAScript 2016, 2017, 和2018中新增功能(摘抄)

    ECMAScript 2016 1. Array.prototype.includes includes是数组上的简单实例方法,并有助于轻松查找某个项是否在Array中(包括NaN不像indexOf) ...

  4. SQL Server 2012/2016/2017 新增函数

    /************************************************************** SQL Server 2012 新增的函数 ************** ...

  5. ECMAScript 2016,2017 和 2018 中所有新功能的示例

    很难追踪 JavaScript(ECMAScript)中的新功能. 想找到有用的代码示例更加困难. 因此,在本文中,我将介绍 TC39 已完成 ES2016,ES2017 和 ES2018(最终草案) ...

  6. [转]ECMAScript 2016,2017 和 2018 中所有新功能的示例

    很难追踪 JavaScript(ECMAScript)中的新功能. 想找到有用的代码示例更加困难. 因此,在本文中,我将介绍 TC39 已完成 ES2016,ES2017 和 ES2018(最终草案) ...

  7. Mindjet MindManager 2016/2017 折腾记录

    https://community.mindjet.com/mindjet/topics/ensure-2017-64-bit-version-installation Mindmanager sho ...

  8. [SinGuLaRiTy] COCI 2016~2017 #5

    [SinGuLaRiTy-1012] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 最近神犇喜欢考COCI...... 测试题目 对于所有的 ...

  9. macbook pro 2016 2017 15寸 雷电3 外接显卡 epu 简单教程(不修改UEFI)

    雷电3外接显卡效果还不错,但是除了akitio node 其他厂家并不会维护自己的固件来适配新机型,我自己买的mbp 2016 15''就出现了和AORUS Gaming Box 1070不兼容的问题 ...

  10. ccpc 2016 省赛

    1.configuration if ide. 2.file import and export. 3.check your program more than once. ============= ...

随机推荐

  1. HTML5 有哪些不同类型的存储?

    HTML 5 支持本地存储,在之前版本中是通过 Cookie 实现的.HTML5 本地存储速度快而且安全. 有两种不同的对象可用来存储数据: localStorage 适用于长期存储数据,浏览器关闭后 ...

  2. personalWebsite_1:历史记录汇总

    最开始,根据  https://blog.csdn.net/zbl1146556298/article/details/79714239 进行网站构思设计,根据源码, 1.把gradle项目转为mav ...

  3. 构建高性能JavaScript应用

    前端性能优化准则: 一.减少http请求.     措施:合并小图片,css控制背景图.合并CSS,合并JS 二.使用CDN(Content Deliver Network 内容分发网络)发布静态资源 ...

  4. 在Magento System Configuration页面添加配置项

    以 Jp_Coupon 模块为例: 目标: 在 System configuration 页面添加一个 JP tab, 在JP中添加 Coupon section, 然后给 Coupon sectio ...

  5. java-jsch实现sftp文件操作

    (曾在天涯)的文章详细讲解了jsch中的函数以及用法 http://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html http://www. ...

  6. sql队伍的胜负情况

    1.数据显示情况 2.sql语句执行情况 USE [数据库名] GO /****** Object: Table [dbo].[测试] Script Date: 08/03/2017 10:58:02 ...

  7. Windows下用cmd命令安装及卸载服务[转]

    第一种方法: 1. 开始 ->运行 ->cmd2. cd到C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727(Framework版本号按IIS配置) ...

  8. [转]iOS开发总结之代码规范

    转自:http://www.cocoachina.com/ios/20151014/13678.html 命名规范 总 的来说, iOS命名两大原则是:可读性高和防止命名冲突(通过加前缀来保证). O ...

  9. SAP成都研究院非典型程序猿,菜园子小哥:当我用UI5诊断工具时我用些什么

    身边有些年轻同事曾经向我表达过这种困扰:尽管完成日常工作没有任何问题,但是还想更进一步,把代码写得更好些,做到精益求精.现在写的代码能实现功能,但是不知道可以怎样写得更好. 除了阅读优秀的开源库开源框 ...

  10. help.hybris.com和help.sap.com网站的搜索实现

    help.hybris.com 我使用help.hybris.com时,发现每次在搜索栏输入文字时,没有发出任何HTTP请求,那么这个自动完成的下拉框里的记录从哪里来的?我看了下实现,发现所有自动完成 ...