A    Tobaku Mokushiroku Kaiji

水。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[], b[];
  5.  
  6. void Run()
  7. {
  8. while (scanf("%d", a) != EOF)
  9. {
  10. for (int i = ; i < ; ++i) scanf("%d", a + i);
  11. for (int i = ; i < ; ++i) scanf("%d", b + i);
  12. printf("%d\n", min(a[], b[]) + min(a[], b[]) + min(a[], b[]));
  13. }
  14. }
  15.  
  16. int main()
  17. {
  18. #ifdef LOCAL
  19. freopen("Test.in", "r", stdin);
  20. #endif
  21.  
  22. Run();
  23. return ;
  24. }

B    Attack on Titan

留坑。

C    Utawarerumono

思路:好像暴力就能过。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. ll a, b, c, p1, p2, q1, q2;
  6.  
  7. int main()
  8. {
  9. while (scanf("%lld%lld%lld", &a, &b, &c) != EOF)
  10. {
  11. scanf("%lld%lld", &p1, &p2);
  12. scanf("%lld%lld", &q1, &q2);
  13. ll res = 0x3f3f3f3f3f3f3f3f;
  14. for (ll x = -; x <= ; ++x)
  15. {
  16. if ((c - a * x) % b) continue;
  17. ll y = (c - a * x) / b;
  18. res = min(res, p2 * x * x + p1 * x + q2 * y * y + q1 * y);
  19. }
  20. if (res == 0x3f3f3f3f3f3f3f3f)
  21. {
  22. puts("Kuon");
  23. continue;
  24. }
  25. printf("%lld\n", res);
  26. }
  27. return ;
  28. }

D    Love Live!

思路:将边按权值从小到大排序,一条一条往里加,每加入一条边要合并两个联通块,用并查集维护,然后开n棵trie树维护异或最大,简单路径上的异或和可以理解为两个点到根节点的前缀异或再异或,合并的时候启发式合并,查询的时候一定要经过那条边,那就是用一个联通块里的元素查找在另一个联通块对应的trie树里面查找,启发式查找

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 100010
  5.  
  6. struct Edge
  7. {
  8. int u, v, nx, w;
  9. Edge() {}
  10. Edge(int u, int v, int nx, int w) : u(u), v(v), nx(nx), w(w) {}
  11. Edge(int u, int v, int w) : u(u), v(v), w(w) {}
  12. bool operator < (const Edge &r) const
  13. {
  14. return w < r.w;
  15. }
  16. }edge[N << ], G[N];
  17.  
  18. int n;
  19. int head[N], pos;
  20. int prefix[N], fa[N], sz[N];
  21. vector <int> v[N];
  22.  
  23. void addedge(int u, int v, int w)
  24. {
  25. edge[++pos] = Edge(u, v, head[u], w); head[u] = pos;
  26. }
  27.  
  28. void DFS(int u, int fa)
  29. {
  30. for (int it = head[u]; ~it; it = edge[it].nx)
  31. {
  32. int v = edge[it].v;
  33. if (v == fa) continue;
  34. prefix[v] = prefix[u] ^ edge[it].w;
  35. DFS(v, u);
  36. }
  37. }
  38.  
  39. struct TRIE
  40. {
  41. int cnt;
  42. int T[N];
  43. struct node
  44. {
  45. int son[];
  46. node()
  47. {
  48. memset(son, , sizeof son);
  49. }
  50. }a[N * ];
  51.  
  52. void Init()
  53. {
  54. cnt = n + ;
  55. }
  56.  
  57. void Insert(int root, int x)
  58. {
  59. bitset <> b; b = x;
  60. for (int i = ; i >= ; --i)
  61. {
  62. if (!a[root].son[b[i]])
  63. a[root].son[b[i]] = ++cnt;
  64. root = a[root].son[b[i]];
  65. }
  66. }
  67.  
  68. int query(int root, int x)
  69. {
  70. bitset <> b; b = x;
  71. int res = ;
  72. for (int i = ; i >= ; --i)
  73. {
  74. int id = b[i] ^ ;
  75. bool flag = true;
  76. if (!a[root].son[id])
  77. {
  78. flag = false;
  79. id ^= ;
  80. }
  81. if (flag) res += << i;
  82. root = a[root].son[id];
  83. }
  84. return res;
  85. }
  86. }trie;
  87.  
  88. int find(int x)
  89. {
  90. if (x != fa[x])
  91. fa[x] = find(fa[x]);
  92. return fa[x];
  93. }
  94.  
  95. void Init()
  96. {
  97. memset(head, -, sizeof head); pos = ;
  98. prefix[] = ;
  99. trie.Init();
  100. }
  101.  
  102. void Run()
  103. {
  104. while (scanf("%d", &n) != EOF)
  105. {
  106. Init();
  107. for (int i = , u, v, w; i < n; ++i)
  108. {
  109. scanf("%d%d%d", &u, &v, &w);
  110. addedge(u, v, w);
  111. addedge(v, u, w);
  112. G[i] = Edge(u, v, w);
  113. }
  114. DFS(, );
  115. for (int i = ; i <= n; ++i)
  116. {
  117. fa[i] = i;
  118. sz[i] = ;
  119. trie.T[i] = i;
  120. trie.Insert(trie.T[i], prefix[i]);
  121. v[i].push_back(prefix[i]);
  122. }
  123. sort(G + , G + n);
  124. for (int i = ; i < n; ++i)
  125. {
  126. int x = G[i].u, y = G[i].v;
  127. int fx = find(x), fy = find(y);
  128. if (sz[fx] > sz[fy]) swap(x, y), swap(fx, fy);
  129. int res = ;
  130. for (auto it : v[fx])
  131. {
  132. res = max(res, trie.query(trie.T[fy], it));
  133. }
  134. for (auto it : v[fx])
  135. {
  136. trie.Insert(trie.T[fy], it);
  137. v[fy].push_back(it);
  138. }
  139. printf("%d%c", res, " \n"[i == n - ]);
  140. fa[fx] = fy;
  141. sz[fy] += sz[fx];
  142. }
  143. }
  144. }
  145.  
  146. int main()
  147. {
  148. #ifdef LOCAL
  149. freopen("Test.in", "r", stdin);
  150. #endif
  151.  
  152. Run();
  153. return ;
  154. }

E    Eustia of the Tarnished Wings

思路:排序,然后贪心合并即可

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 1000010
  5.  
  6. int n, m;
  7. int arr[N];
  8.  
  9. void Run()
  10. {
  11. while (scanf("%d%d", &n, &m) != EOF)
  12. {
  13. for (int i = ; i <= n; ++i) scanf("%d", arr + i);
  14. sort(arr + , arr + + n);
  15. int res = ;
  16. for (int i = ; i <= n; ++i) if (arr[i] - arr[i - ] > m)
  17. ++res;
  18. printf("%d\n", res);
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. #ifdef LOCAL
  25. freopen("Test.in", "r", stdin);
  26. #endif
  27.  
  28. Run();
  29. return ;
  30. }

F    Baldr Sky

留坑。

G    Kimi to Kanojo to Kanojo no Koi

留坑。

H    One Piece

留坑。

I    Steins;Gate

留坑。

J    Princess Principal

思路:用栈维护括号序列

其实假设存在合法文档 那么每一个括号都有一个唯一的对应括号

比如说 (())  肯定是中间两个匹配,再外面两个匹配

那么我们直接用栈维护一下,找到每个左括号的右匹配,以及找到每个有括号的左匹配,然后RMQ倍增维护最括号的最大右匹配,右括号的最小左匹配,如果最大值超过r 或者 最小值小于l 那么是不合法的

还有一种情况 就是 ([)  那么这三个括号都是不合法的

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 1000010
  5. #define INF 0x3f3f3f3f
  6.  
  7. int n, m, q;
  8. int arr[N], L[N], R[N];
  9. int mm[N];
  10. stack <int> sta;
  11.  
  12. void Init()
  13. {
  14. mm[] = -;
  15. for (int i = ; i <= n; ++i)
  16. mm[i] = ((i & (i - )) == ) ? mm[i - ] + : mm[i - ];
  17. }
  18.  
  19. struct RMQ
  20. {
  21. int dp[N][]; // 1 max 0 min
  22. void Init(int n, int b[], int vis)
  23. {
  24. for (int i = ; i <= n; ++i)
  25. dp[i][] = b[i];
  26. for (int j = ; j <= mm[n]; ++j)
  27. for (int i = ; i + ( << j) - <= n; ++i)
  28. {
  29. if (vis)
  30. dp[i][j] = max(dp[i][j - ], dp[i + ( << (j - ))][j - ]);
  31. else
  32. dp[i][j] = min(dp[i][j - ], dp[i + ( << (j - ))][j - ]);
  33. }
  34. }
  35.  
  36. int query(int x, int y, int vis)
  37. {
  38. int k = mm[y - x + ];
  39. if (vis)
  40. return max(dp[x][k], dp[y - ( << k) + ][k]);
  41. else
  42. return min(dp[x][k], dp[y - ( << k) + ][k]);
  43. }
  44. }rmq[];
  45.  
  46. bool ok(int x, int y)
  47. {
  48. if (rmq[].query(x, y, ) < x) return false;
  49. if (rmq[].query(x, y, ) > y) return false;
  50. return true;
  51. }
  52.  
  53. void Run()
  54. {
  55. while (scanf("%d%d%d", &n, &m, &q) != EOF)
  56. {
  57. memset(L, -, sizeof L);
  58. memset(R, 0x3f, sizeof R);
  59. for (int i = ; i <= n; ++i) scanf("%d", arr + i);
  60. for (int i = ; i <= n; ++i)
  61. {
  62. if (arr[i] & )
  63. {
  64. if (!sta.empty())
  65. {
  66. int top = sta.top(); sta.pop();
  67. if (arr[i] / == arr[top] / ) L[i] = top;
  68. }
  69. }
  70. else
  71. sta.push(i);
  72. }
  73. while (!sta.empty()) sta.pop();
  74. for (int i = n; i >= ; --i)
  75. {
  76. if (arr[i] % == )
  77. {
  78. if (!sta.empty())
  79. {
  80. int top = sta.top(); sta.pop();
  81. if (arr[i] / == arr[top] / ) R[i] = top;
  82. }
  83. }
  84. else
  85. sta.push(i);
  86. }
  87. for (int i = ; i <= n; ++i)
  88. {
  89. if (arr[i] & ) R[i] = -;
  90. else L[i] = INF;
  91. }
  92. Init();
  93. rmq[].Init(n, L, );
  94. rmq[].Init(n, R, );
  95. for (int i = , x, y; i <= q; ++i)
  96. {
  97. scanf("%d%d", &x, &y);
  98. puts(ok(x, y) ? "Yes" : "No");
  99. }
  100. }
  101. }
  102.  
  103. int main()
  104. {
  105. #ifdef LOCAL
  106. freopen("Test.in", "r", stdin);
  107. #endif
  108.  
  109. Run();
  110. return ;
  111. }

K    Tengen Toppa Gurren Lagann

留坑。

L    New Game!

思路:分别处理 直线到圆的最短距离,圆到圆的最短距离,直线到直线的最短距离,然后跑最短路即可

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 1010
  5. #define INF 0x3f3f3f3f
  6.  
  7. const double eps = 1e-;
  8.  
  9. int sgn(double x)
  10. {
  11. if (fabs(x) < eps) return ;
  12. if (x < ) return -;
  13. else return ;
  14. }
  15.  
  16. struct Point
  17. {
  18. double x, y;
  19. Point() {}
  20. Point(double _x, double _y)
  21. {
  22. x = _x; y = _y;
  23. }
  24. double operator ^(const Point &b) const { return x * b.y - y * b.x; }
  25. double distance(Point p) { return hypot(x - p.x, y - p.y); }
  26. Point operator - (const Point &b) const { return Point(x - b.x, y - b.y); }
  27. };
  28.  
  29. struct Line
  30. {
  31. Point s, e;
  32. Line() {}
  33. Line(double a, double b, double c)
  34. {
  35. if (sgn(a) == )
  36. {
  37. s = Point(, -c / b);
  38. e = Point(, -c / b);
  39. }
  40. else if (sgn(b) == )
  41. {
  42. s = Point(-c / a, );
  43. e = Point(-c / a, );
  44. }
  45. else
  46. {
  47. s = Point(, -c / b);
  48. e = Point(, (-c - a) / b);
  49. }
  50. }
  51. double length() { return s.distance(e); }
  52. double dispointtoline(Point p) { return fabs((p - s) ^ (e - s)) / length(); }
  53. }L[];
  54.  
  55. struct circle
  56. {
  57. Point p;
  58. double r;
  59. circle() {}
  60. circle(double x, double y, double _r)
  61. {
  62. p = Point(x, y);
  63. r = _r;
  64. }
  65. }arr[N];
  66.  
  67. int n, A, B, C1, C2;
  68. double x, y, r;
  69. double G[N][N];
  70.  
  71. void work0(int x, int y)
  72. {
  73. double dis = arr[x].p.distance(arr[y].p);
  74. G[x][y] = max(0.0, dis - arr[x].r - arr[y].r);
  75. G[y][x] = G[x][y];
  76. }
  77.  
  78. void work1(int x, int y)
  79. {
  80. double dis = L[x].dispointtoline(arr[y].p);
  81. G[x][y] = max(0.0, dis - arr[y].r);
  82. G[y][x] = G[x][y];
  83. }
  84.  
  85. double dis[N];
  86. bool used[N];
  87.  
  88. void Dijkstra ()
  89. {
  90. for (int i = ; i <= n + ; ++i) dis[i] = INF * 1.0, used[i] = false;
  91. dis[] = ;
  92. for (int j = ; j <= n + ; ++j)
  93. {
  94. int k = -;
  95. double Min = INF * 1.0;
  96. for (int i = ; i <= n + ; ++i)
  97. {
  98. if (!used[i] && dis[i] < Min)
  99. {
  100. Min = dis[i];
  101. k = i;
  102. }
  103. }
  104. used[k] = ;
  105. for (int i = ; i <= n + ; ++i)
  106. if (!used[i] && dis[k] + G[k][i] < dis[i])
  107. dis[i] = dis[k] + G[k][i];
  108. }
  109. }
  110.  
  111. void Run()
  112. {
  113. while (scanf("%d%d%d%d%d", &n, &A, &B, &C1, &C2) != EOF)
  114. {
  115. memset(G, 0x3f, sizeof G);
  116. L[] = Line(A, B, C1);
  117. L[] = Line(A, B, C2);
  118. for (int i = ; i <= n + ; ++i)
  119. {
  120. scanf("%lf%lf%lf", &x, &y, &r);
  121. arr[i] = circle(x, y, r);
  122. G[i][i] = ;
  123. }
  124. for (int i = ; i <= n + ; ++i)
  125. for (int j = i + ; j <= n + ; ++j)
  126. work0(i, j);
  127. for (int i = ; i < ; ++i)
  128. for (int j = ; j <= n + ; ++j)
  129. work1(i, j);
  130. G[][] = abs(C1 - C2) / sqrt(A * A + B * B);
  131. G[][] = G[][];
  132. Dijkstra();
  133. printf("%.10f\n", dis[]);
  134. }
  135. }
  136.  
  137. int main()
  138. {
  139. Run();
  140. return ;
  141. }

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

  1. 牛客国庆集训派对Day1 L-New Game!(最短路)

    链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

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

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

  3. 牛客国庆集训派对Day1 L New Game!(堆优化dijkstra+建图)

    链接:https://ac.nowcoder.com/acm/contest/201/L来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言2097 ...

  4. 牛客国庆集训派对Day1.B.Attack on Titan(思路 最短路Dijkstra)

    题目链接 \(Description\) 给定\(n,m,C\)及大小为\((n+1)(m+1)\)的矩阵\(c[i][j]\).平面上有\((n+1)(m+1)\)个点,从\((0,0)\)编号到\ ...

  5. 2019牛客国庆集训派对day1(A, B E F K)

    链接:https://ac.nowcoder.com/acm/contest/1099#question A:可知符合条件的图中间肯定存在一个由1构成的矩形,找到由1构成矩形的边界,判断出现的1的数量 ...

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

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

  7. 牛客国庆集训派对Day1 B. Attack on Titan

    B. Attack on Titan 链接 #include<cstdio> #include<algorithm> #include<cstring> #incl ...

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

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

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

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

随机推荐

  1. linux命令之scp

    两个主机之间copy数据经常用到命令 1.copy文件命令 scp /home/test/1.mp3 root@192.168.1.20:/home/test/music 2.copy文件目录命令 s ...

  2. Linux中的命令学习笔记

    Linux挂载Winodws共享文件夹 mount -t cifs -o username=xxx,password=xxxx //1.1.1.1/test /win 产生一个5位随机字符串 | md ...

  3. javascript中五种基本数据类型

    前言: JavaScript中有五种基本数据类型(也叫做简单数据类型)分别为:undefined.null.bolean.number.string:另外还含有一种复杂的数据类型:object. 深入 ...

  4. NSFileManager和NSFileHandle(附:获取文件大小 )

    本文转载至:http://www.cnblogs.com/pengyingh/articles/2350345.html 天牛 感谢原创作者的硕果 //file 文件操作 NSFileManager  ...

  5. solr删除数据的4种方便快捷的方式

    1.在solr客户端,访问你的索引库(我认为最方便的方法) 1)documents type 选择 XML  2)documents 输入下面语句 <delete><query> ...

  6. HTTP/2笔记之开篇

    前言 本系列基于HTTP/2第17个草案文档,地址就是:https://tools.ietf.org/html/draft-ietf-httpbis-http2-17. HTTP/2规范已经通过发布批 ...

  7. 河南省第七届ACM程序设计大赛总结

    省赛总结 首先说说比赛时的情况吧,刚开始的时候我的任务就是翻译英文题目,找出比较水的题目,他们两个直接找中文水题切,其实每次比赛我们都是这样配合的,由于他们的判题系统一开始存在问题,交的正确的代码给判 ...

  8. Mybatis 搭配 阿里druid连接池 连接 oracle 或 mysql

    DRUID介绍 DRUID是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针 ...

  9. 170804、使用Joda-Time优雅的处理日期时间

    简介 在Java中处理日期和时间是很常见的需求,基础的工具类就是我们熟悉的Date和Calendar,然而这些工具类的api使用并不是很方便和强大,于是就诞生了Joda-Time这个专门处理日期时间的 ...

  10. HDU_5521_Meeting

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...