A    Relic Discovery

水。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int t, n;
  5.  
  6. int main()
  7. {
  8. scanf("%d", &t);
  9. while (t--)
  10. {
  11. scanf("%d", &n);
  12. int res = ;
  13. for (int i = , a, b; i <= n; ++i)
  14. {
  15. scanf("%d%d", &a, &b);
  16. res += a * b;
  17. }
  18. printf("%d\n", res);
  19. }
  20. return ;
  21. }

B    Pocket Cube

按题意模拟即可,注意顺时针转逆时针转均可,也就是说一个面有八种旋转可能

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int t;
  5. int G[][], tmp[][];
  6.  
  7. bool ok()
  8. {
  9. for (int i = ; i <= ; ++i)
  10. for (int j = ; j <= ; ++j)
  11. if (tmp[i][j] != tmp[i][j - ])
  12. return false;
  13. return true;
  14. }
  15.  
  16. void clear()
  17. {
  18. for (int i = ; i <= ; ++i)
  19. for (int j = ; j <= ; ++j)
  20. tmp[i][j] = G[i][j];
  21. }
  22.  
  23. int origin[][][] =
  24. {
  25. // top
  26. {, , , , , , , , , , , , , , , ,},
  27. // bottom
  28. {, , , , , , , , , , , , , , , ,},
  29. // left
  30. {, , , , , , , , , , , , , , , ,},
  31. // right
  32. {, , , , , , , , , , , , , , , ,},
  33. // front
  34. {, , , , , , , , , , , , , , , ,},
  35. // back
  36. {, , , , , , , , , , , , , , , ,},
  37. };
  38.  
  39. int Move[][][] =
  40. {
  41. {, , , , , , , , , , , , , , , ,},
  42. {, , , , , , , , , , , , , , , ,},
  43. {, , , , , , , , , , , , , , , ,},
  44. {, , , , , , , , , , , , , , , ,},
  45. {, , , , , , , , , , , , , , , ,},
  46. {, , , , , , , , , , , , , , , ,},
  47. };
  48.  
  49. bool work()
  50. {
  51. clear(); if (ok()) return true;
  52. for (int i = ; i < ; ++i)
  53. {
  54. for (int j = ; j < ; j += )
  55. {
  56. clear();
  57. for (int k = ; k < ; ++k)
  58. {
  59. int x = (j + k) % ;
  60. tmp[origin[i][x][]][origin[i][x][]] = G[Move[i][x][]][Move[i][x][]];
  61. }
  62. if (ok()) return true;
  63. }
  64. for (int j = ; j < ; j += )
  65. {
  66. clear();
  67. for (int k = ; k > -; --k)
  68. {
  69. int x = (j + k + ) % ;
  70. int y = (x + ) % ;
  71. tmp[origin[i][x][]][origin[i][x][]] = G[Move[i][y][]][Move[i][y][]];
  72. }
  73. if (ok()) return true;
  74. }
  75. }
  76. return false;
  77. }
  78.  
  79. int main()
  80. {
  81. scanf("%d", &t);
  82. while(t--)
  83. {
  84. for (int i = ; i <= ; ++i)
  85. for (int j = ; j <= ; ++j)
  86. scanf("%d", &G[i][j]);
  87. puts(work() ? "YES" : "NO");
  88. }
  89. return ;
  90. }

C    Pocky

根据样例发现规律 答案为  log(l / d) + 1.0  如果 l <= d  答案为0

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const double eps = 1e-;
  5.  
  6. int t;
  7. double l, d;
  8.  
  9. int main()
  10. {
  11. scanf("%d", &t);
  12. while (t--)
  13. {
  14. scanf("%lf%lf", &l, &d);
  15. if (l <= d || fabs(l - d) <= eps)
  16. printf("%.6f\n", 0.0);
  17. else
  18. printf("%.6f\n", log(l / d) + 1.0);
  19. }
  20. return ;
  21. }

D    Lucky Coins

留坑。

E    Fibonacci

留坑。

F    Lambda Calculus

留坑。

G    Coding Contest

题意:有n个区域,每个区域有$s_i$个人以及$b_i$个食物,有m条路,每条路最多让$c_i$个人走,其中第一个人走不产生影响,后面的每个人都有p的可能破坏 求最小的破坏可能

思路:将p取log就变成了累加最小,建立一个源点以及一个汇点,其中每块区域需要出走的人和汇点相连,可以进来的人与源点相连,跑一遍最小费用最大流即可

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const double eps = 1e-;
  6. const double EI = exp(1.0);
  7. const int maxn = ;
  8. const int maxm = ;
  9. const int INF = 0x3f3f3f3f;
  10.  
  11. int sgn(double x)
  12. {
  13. if(fabs(x) < eps) return ;
  14. else return x > ? : -;
  15. }
  16.  
  17. struct Edge{
  18. int to, nxt, cap, flow;
  19. double cost;
  20. }edge[maxm];
  21.  
  22. double ans;
  23. int head[maxn], tot;
  24. int pre[maxn];
  25. double dis[maxn];
  26. bool vis[maxn];
  27. int N;
  28.  
  29. void Init(int n)
  30. {
  31. N = n;
  32. tot = ;
  33. for(int i = ; i <= n; ++i) head[i] = -;
  34. }
  35.  
  36. void addedge(int u, int v,int cap, double cost)
  37. {
  38. edge[tot].to = v;
  39. edge[tot].cap = cap;
  40. edge[tot].cost = cost;
  41. edge[tot].flow = ;
  42. edge[tot].nxt = head[u];
  43. head[u] = tot++;
  44.  
  45. edge[tot].to = u;
  46. edge[tot].cap = ;
  47. edge[tot].cost = -cost;
  48. edge[tot].flow = ;
  49. edge[tot].nxt = head[v];
  50. head[v] = tot++;
  51. }
  52.  
  53. bool SPFA(int s,int t)
  54. {
  55. queue<int>q;
  56. for(int i = ; i < N; ++i)
  57. {
  58. dis[i] = INF;
  59. vis[i] = false;
  60. pre[i] = -;
  61. }
  62. dis[s] = ;
  63. vis[s] = true;
  64. q.push(s);
  65. while(!q.empty())
  66. {
  67. int u = q.front();
  68. q.pop();
  69. vis[u] = false;
  70. for(int i = head[u]; ~i; i = edge[i].nxt)
  71. {
  72. int v = edge[i].to;
  73. if(edge[i].cap > edge[i].flow && sgn(dis[v] - dis[u] - edge[i].cost) > )
  74. {
  75. dis[v] = dis[u] + edge[i].cost;
  76. pre[v] = i;
  77. if(!vis[v])
  78. {
  79. vis[v] = true;
  80. q.push(v);
  81. }
  82. }
  83. }
  84. }
  85. if(pre[t] == -) return false;
  86. else return true;
  87. }
  88.  
  89. int minCostMaxflow(int s, int t)
  90. {
  91. int flow = ;
  92. ans = ;
  93. while(SPFA(s, t))
  94. {
  95. int Min = INF;
  96. for(int i = pre[t]; ~i; i = pre[edge[i ^ ].to])
  97. {
  98. Min = min(Min, edge[i].cap - edge[i].flow);
  99. }
  100. for(int i = pre[t]; ~i; i = pre[edge[i ^ ].to])
  101. {
  102. edge[i].flow += Min;
  103. edge[i ^ ].flow -= Min;
  104. ans += edge[i].cost * Min;
  105. }
  106. flow += Min;
  107. }
  108. return flow;
  109. }
  110.  
  111. int n, m;
  112. int s[maxn], b[maxn], tmp[maxn];
  113.  
  114. int main()
  115. {
  116. int t;
  117. scanf("%d", &t);
  118. while(t--)
  119. {
  120. scanf("%d %d", &n, &m);
  121. Init(n + );
  122. for(int i = ; i <= n; ++i)
  123. {
  124. scanf("%d %d", s + i, b + i);
  125. if(s[i] - b[i] > ) addedge(, i, s[i] - b[i], );
  126. if(s[i] - b[i] < ) addedge(i, n + , b[i] - s[i], );
  127. }
  128.  
  129. for(int i = ; i <= m; ++i)
  130. {
  131. int u, v, c;
  132. double p;
  133. scanf("%d %d %d %lf", &u, &v, &c ,&p);
  134. p = -log(1.0 - p);
  135. if(c > ) addedge(u, v, , );
  136. if(c > ) addedge(u, v, c - , p);
  137. }
  138. int flow = minCostMaxflow(, n + );
  139. ans = pow(EI, -ans);
  140. printf("%.2f\n", 1.0 - ans);
  141. }
  142. return ;
  143. }

H    Pattern

留坑。

I    Travel Brochure

留坑。

J    Cliques

留坑。

K    Finding Hotels

题意:有若干酒店,以及一些旅客,每个旅客有价格接受范围,对于每个旅客要找出可接受价格以内的所有酒店中最近的

思路:KDTree 对于价格直接特判,如果超出,直接return INF  还要注意多解的情况下取id小的

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define N 200010
  6. #define DIM 10
  7. #define INF 0x3f3f3f3f3f3f3f3f
  8. inline ll sqr(ll x) { return x * x; }
  9. namespace KD
  10. {
  11. int K;
  12. struct Point
  13. {
  14. ll x[DIM];
  15. int id;
  16. ll distance(const Point &b) const
  17. {
  18. if (x[] < b.x[]) return INF;
  19. ll ret = ;
  20. for (int i = ; i < K; ++i) ret += sqr(x[i] - b.x[i]);
  21. return ret;
  22. }
  23. void input(int id) { this->id = id; for (int i = ; i < K + ; ++i) scanf("%lld", x + i); }
  24. void output() { for (int i = ; i < K + ; ++i) printf("%lld%c", x[i], " \n"[i == K]); }
  25. };
  26. struct cmpx
  27. {
  28. int div;
  29. cmpx(const int &div) { this->div = div; }
  30. bool operator () (const Point &a, const Point &b)
  31. {
  32. for (int i = ; i < K; ++i) if (a.x[(div + i) % K] != b.x[(div + i) % K])
  33. return a.x[(div + i) % K] < b.x[(div + i) % K];
  34. return true;
  35. }
  36. };
  37. bool cmp(const Point &a, const Point &b, int div) { return cmpx(div)(a, b); }
  38. struct node
  39. {
  40. Point e;
  41. node *lc, *rc;
  42. int div;
  43. }pool[N], *tail, *root;
  44. void init() { tail = pool; }
  45. node* build(Point *a, int l, int r, int div)
  46. {
  47. if (l >= r) return NULL;
  48. node *p = tail++;
  49. p->div = div;
  50. int mid = (l + r) >> ;
  51. nth_element(a + l, a + mid, a + r, cmpx(div));
  52. p->e = a[mid];
  53. p->lc = build(a, l, mid, (div + ) % K);
  54. p->rc = build(a, mid + , r, (div + ) % K);
  55. return p;
  56. }
  57. Point res; ll Min;
  58. void search(Point p, node *x, int div)
  59. {
  60. if (!x) return;
  61. if (cmp(p, x->e, div))
  62. {
  63. search(p, x->lc, (div + ) % K);
  64. ll tmp = p.distance(x->e);
  65. if (tmp < Min || tmp == Min && x->e.id < res.id)
  66. {
  67. Min = tmp;
  68. res = x->e;
  69. }
  70. if (sqr(x->e.x[div] - p.x[div]) <= Min)
  71. search(p, x->rc, (div + ) % K);
  72. }
  73. else
  74. {
  75. search(p, x->rc, (div + ) % K);
  76. ll tmp = p.distance(x->e);
  77. if (tmp < Min || tmp == Min && x->e.id < res.id)
  78. {
  79. Min = tmp;
  80. res = x->e;
  81. }
  82. if (sqr(x->e.x[div] - p.x[div]) <= Min)
  83. search(p, x->lc, (div + ) % K);
  84. }
  85. }
  86. void search(Point p)
  87. {
  88. Min = INF;
  89. search(p, root, );
  90. }
  91. }
  92.  
  93. int t, n, q;
  94. KD::Point p[N];
  95.  
  96. void Run()
  97. {
  98. for (scanf("%d", &t); t--; )
  99. {
  100. KD::K = ;
  101. scanf("%d%d", &n, &q);
  102. for (int i = ; i < n; ++i) p[i].input(i);
  103. KD::init();
  104. KD::root = KD::build(p, , n, );
  105. for (int i = ; i <= q; ++i)
  106. {
  107. KD::Point o; o.input();
  108. KD::search(o);
  109. KD::res.output();
  110. }
  111. }
  112. }
  113.  
  114. int main()
  115. {
  116. #ifdef LOCAL
  117. freopen("Test.in", "r", stdin);
  118. #endif
  119.  
  120. Run();
  121. return ;
  122.  
  123. }

L    Tower Attack

留坑。

M    Generator and Monitor

留坑。

牛客国庆集训派对Day7 Solution的更多相关文章

  1. 牛客国庆集训派对Day2 Solution

    A    矩阵乘法 思路: 1° 牛客机器太快了,暴力能过. #include <bits/stdc++.h> using namespace std; #define N 5000 in ...

  2. 计算几何板子题【2019牛客国庆集训派对day7——三角形和矩形】【多边形相交的面积】

    链接:https://ac.nowcoder.com/acm/contest/1112/J来源:牛客网 题目描述 Bobo 有一个三角形和一个矩形,他想求他们交的面积. 具体地,三角形和矩形由 8 个 ...

  3. 2019牛客国庆集训派对day7 A 2016

    链接:https://ac.nowcoder.com/acm/problem/52800来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...

  4. 牛客国庆集训派对Day4 Solution

    A    深度学习 puts(n) #include <bits/stdc++.h> using namespace std; int main() { double n; while ( ...

  5. 牛客国庆集训派对Day1 Solution

    A    Tobaku Mokushiroku Kaiji 水. #include <bits/stdc++.h> using namespace std; ], b[]; void Ru ...

  6. 牛客国庆集训派对Day3 Solution

    A    Knight 留坑. B    Tree 思路:两次树形DP,但是要考虑0没有逆元 可以用前缀后缀做 #include <bits/stdc++.h> using namespa ...

  7. 牛客国庆集训派对Day5 Solution

    A    璀璨光滑 留坑. B    电音之王 蒙特马利大数乘模运算 #include <bits/stdc++.h> using namespace std; typedef long ...

  8. 牛客国庆集训派对Day6 Solution

    A    Birthday 思路:设置一个源点,一个汇点,每次对$源点对a_i, b_i , a_i 对 b_i 连一条流为1,费用为0的边$ 每个点都再连一条 1, 3, 5, 7, ....的边到 ...

  9. 牛客国庆集训派对Day6 A Birthday 费用流

    牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...

随机推荐

  1. ios开发 int,NSInteger,NSUInteger,NSNumber

    分享一下,在工作工程中遇到的一些不留心的地方: 1.当需要使用int类型的变量的时候,可以像写C的程序一样,用int,也可以用NSInteger,但更推荐使用NSInteger,因为这样就不用考虑设备 ...

  2. iOS调用系统相册、相机 显示中文标题

    解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed          YES 表 ...

  3. 怎么下载tomcat的其他版本

    下载地址: http://archive.apache.org/dist/tomcat/ 里面包含tomcat的各个版本,windows版本.linux版本,tomcat7.0.x等.

  4. 如何在Oculus官网下载OculusSetup.exe(当前时间20170720)

    踩着免费的蓝灯FQ登录了Oculus官网,找了半天找不到哪里下载OculusSetup.exe,最后在最下面的支持中心找到了..... https://www.oculus.com/

  5. Java自动类型转换

    ■ 自动类型转换:容量小的数据类型可以自动转换为容量大的数据类型. ■ 特例:可以讲整型常量直接赋给byte,short,char等类型变量,而不需要强制类型转换,只要不超出其表数范围. ■ 强制类型 ...

  6. JS基本动画

    <style type="text/css"> .color_red { background: red; } div { position: absolute; to ...

  7. web基础---->Fileupload文件的上传

    这里我们介绍文件上传的知识,使用的是apache的Commons FileUpload框架. 文件上传的使用 项目的部分结构如下: 一.使用Commons FileUpload的上传功能,我们需要引入 ...

  8. 【CSS系列】布局篇

    一.让设计居中 1.使用自动空白边让设计居中 <style type="text/css"> body{ text-align:center; min-width:76 ...

  9. mysql数据类型及存储过程

    转自:http://www.cnblogs.com/mark-chan/p/5384139.html 存储过程简介 SQL语句需要先编译然后执行,而存储过程(Stored Procedure)是一组为 ...

  10. 编程中,static的用法详解

    C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用.一.面向过程设计中的sta ...