牛客国庆集训派对Day1 Solution
A Tobaku Mokushiroku Kaiji
水。
- #include <bits/stdc++.h>
- using namespace std;
- int a[], b[];
- void Run()
- {
- while (scanf("%d", a) != EOF)
- {
- for (int i = ; i < ; ++i) scanf("%d", a + i);
- for (int i = ; i < ; ++i) scanf("%d", b + i);
- printf("%d\n", min(a[], b[]) + min(a[], b[]) + min(a[], b[]));
- }
- }
- int main()
- {
- #ifdef LOCAL
- freopen("Test.in", "r", stdin);
- #endif
- Run();
- return ;
- }
B Attack on Titan
留坑。
C Utawarerumono
思路:好像暴力就能过。
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- ll a, b, c, p1, p2, q1, q2;
- int main()
- {
- while (scanf("%lld%lld%lld", &a, &b, &c) != EOF)
- {
- scanf("%lld%lld", &p1, &p2);
- scanf("%lld%lld", &q1, &q2);
- ll res = 0x3f3f3f3f3f3f3f3f;
- for (ll x = -; x <= ; ++x)
- {
- if ((c - a * x) % b) continue;
- ll y = (c - a * x) / b;
- res = min(res, p2 * x * x + p1 * x + q2 * y * y + q1 * y);
- }
- if (res == 0x3f3f3f3f3f3f3f3f)
- {
- puts("Kuon");
- continue;
- }
- printf("%lld\n", res);
- }
- return ;
- }
D Love Live!
思路:将边按权值从小到大排序,一条一条往里加,每加入一条边要合并两个联通块,用并查集维护,然后开n棵trie树维护异或最大,简单路径上的异或和可以理解为两个点到根节点的前缀异或再异或,合并的时候启发式合并,查询的时候一定要经过那条边,那就是用一个联通块里的元素查找在另一个联通块对应的trie树里面查找,启发式查找
- #include <bits/stdc++.h>
- using namespace std;
- #define N 100010
- struct Edge
- {
- int u, v, nx, w;
- Edge() {}
- Edge(int u, int v, int nx, int w) : u(u), v(v), nx(nx), w(w) {}
- Edge(int u, int v, int w) : u(u), v(v), w(w) {}
- bool operator < (const Edge &r) const
- {
- return w < r.w;
- }
- }edge[N << ], G[N];
- int n;
- int head[N], pos;
- int prefix[N], fa[N], sz[N];
- vector <int> v[N];
- void addedge(int u, int v, int w)
- {
- edge[++pos] = Edge(u, v, head[u], w); head[u] = pos;
- }
- void DFS(int u, int fa)
- {
- for (int it = head[u]; ~it; it = edge[it].nx)
- {
- int v = edge[it].v;
- if (v == fa) continue;
- prefix[v] = prefix[u] ^ edge[it].w;
- DFS(v, u);
- }
- }
- struct TRIE
- {
- int cnt;
- int T[N];
- struct node
- {
- int son[];
- node()
- {
- memset(son, , sizeof son);
- }
- }a[N * ];
- void Init()
- {
- cnt = n + ;
- }
- void Insert(int root, int x)
- {
- bitset <> b; b = x;
- for (int i = ; i >= ; --i)
- {
- if (!a[root].son[b[i]])
- a[root].son[b[i]] = ++cnt;
- root = a[root].son[b[i]];
- }
- }
- int query(int root, int x)
- {
- bitset <> b; b = x;
- int res = ;
- for (int i = ; i >= ; --i)
- {
- int id = b[i] ^ ;
- bool flag = true;
- if (!a[root].son[id])
- {
- flag = false;
- id ^= ;
- }
- if (flag) res += << i;
- root = a[root].son[id];
- }
- return res;
- }
- }trie;
- int find(int x)
- {
- if (x != fa[x])
- fa[x] = find(fa[x]);
- return fa[x];
- }
- void Init()
- {
- memset(head, -, sizeof head); pos = ;
- prefix[] = ;
- trie.Init();
- }
- void Run()
- {
- while (scanf("%d", &n) != EOF)
- {
- Init();
- for (int i = , u, v, w; i < n; ++i)
- {
- scanf("%d%d%d", &u, &v, &w);
- addedge(u, v, w);
- addedge(v, u, w);
- G[i] = Edge(u, v, w);
- }
- DFS(, );
- for (int i = ; i <= n; ++i)
- {
- fa[i] = i;
- sz[i] = ;
- trie.T[i] = i;
- trie.Insert(trie.T[i], prefix[i]);
- v[i].push_back(prefix[i]);
- }
- sort(G + , G + n);
- for (int i = ; i < n; ++i)
- {
- int x = G[i].u, y = G[i].v;
- int fx = find(x), fy = find(y);
- if (sz[fx] > sz[fy]) swap(x, y), swap(fx, fy);
- int res = ;
- for (auto it : v[fx])
- {
- res = max(res, trie.query(trie.T[fy], it));
- }
- for (auto it : v[fx])
- {
- trie.Insert(trie.T[fy], it);
- v[fy].push_back(it);
- }
- printf("%d%c", res, " \n"[i == n - ]);
- fa[fx] = fy;
- sz[fy] += sz[fx];
- }
- }
- }
- int main()
- {
- #ifdef LOCAL
- freopen("Test.in", "r", stdin);
- #endif
- Run();
- return ;
- }
E Eustia of the Tarnished Wings
思路:排序,然后贪心合并即可
- #include <bits/stdc++.h>
- using namespace std;
- #define N 1000010
- int n, m;
- int arr[N];
- void Run()
- {
- while (scanf("%d%d", &n, &m) != EOF)
- {
- for (int i = ; i <= n; ++i) scanf("%d", arr + i);
- sort(arr + , arr + + n);
- int res = ;
- for (int i = ; i <= n; ++i) if (arr[i] - arr[i - ] > m)
- ++res;
- printf("%d\n", res);
- }
- }
- int main()
- {
- #ifdef LOCAL
- freopen("Test.in", "r", stdin);
- #endif
- Run();
- return ;
- }
F Baldr Sky
留坑。
G Kimi to Kanojo to Kanojo no Koi
留坑。
H One Piece
留坑。
I Steins;Gate
留坑。
J Princess Principal
思路:用栈维护括号序列
其实假设存在合法文档 那么每一个括号都有一个唯一的对应括号
比如说 (()) 肯定是中间两个匹配,再外面两个匹配
那么我们直接用栈维护一下,找到每个左括号的右匹配,以及找到每个有括号的左匹配,然后RMQ倍增维护最括号的最大右匹配,右括号的最小左匹配,如果最大值超过r 或者 最小值小于l 那么是不合法的
还有一种情况 就是 ([) 那么这三个括号都是不合法的
- #include <bits/stdc++.h>
- using namespace std;
- #define N 1000010
- #define INF 0x3f3f3f3f
- int n, m, q;
- int arr[N], L[N], R[N];
- int mm[N];
- stack <int> sta;
- void Init()
- {
- mm[] = -;
- for (int i = ; i <= n; ++i)
- mm[i] = ((i & (i - )) == ) ? mm[i - ] + : mm[i - ];
- }
- struct RMQ
- {
- int dp[N][]; // 1 max 0 min
- void Init(int n, int b[], int vis)
- {
- for (int i = ; i <= n; ++i)
- dp[i][] = b[i];
- for (int j = ; j <= mm[n]; ++j)
- for (int i = ; i + ( << j) - <= n; ++i)
- {
- if (vis)
- dp[i][j] = max(dp[i][j - ], dp[i + ( << (j - ))][j - ]);
- else
- dp[i][j] = min(dp[i][j - ], dp[i + ( << (j - ))][j - ]);
- }
- }
- int query(int x, int y, int vis)
- {
- int k = mm[y - x + ];
- if (vis)
- return max(dp[x][k], dp[y - ( << k) + ][k]);
- else
- return min(dp[x][k], dp[y - ( << k) + ][k]);
- }
- }rmq[];
- bool ok(int x, int y)
- {
- if (rmq[].query(x, y, ) < x) return false;
- if (rmq[].query(x, y, ) > y) return false;
- return true;
- }
- void Run()
- {
- while (scanf("%d%d%d", &n, &m, &q) != EOF)
- {
- memset(L, -, sizeof L);
- memset(R, 0x3f, sizeof R);
- for (int i = ; i <= n; ++i) scanf("%d", arr + i);
- for (int i = ; i <= n; ++i)
- {
- if (arr[i] & )
- {
- if (!sta.empty())
- {
- int top = sta.top(); sta.pop();
- if (arr[i] / == arr[top] / ) L[i] = top;
- }
- }
- else
- sta.push(i);
- }
- while (!sta.empty()) sta.pop();
- for (int i = n; i >= ; --i)
- {
- if (arr[i] % == )
- {
- if (!sta.empty())
- {
- int top = sta.top(); sta.pop();
- if (arr[i] / == arr[top] / ) R[i] = top;
- }
- }
- else
- sta.push(i);
- }
- for (int i = ; i <= n; ++i)
- {
- if (arr[i] & ) R[i] = -;
- else L[i] = INF;
- }
- Init();
- rmq[].Init(n, L, );
- rmq[].Init(n, R, );
- for (int i = , x, y; i <= q; ++i)
- {
- scanf("%d%d", &x, &y);
- puts(ok(x, y) ? "Yes" : "No");
- }
- }
- }
- int main()
- {
- #ifdef LOCAL
- freopen("Test.in", "r", stdin);
- #endif
- Run();
- return ;
- }
K Tengen Toppa Gurren Lagann
留坑。
L New Game!
思路:分别处理 直线到圆的最短距离,圆到圆的最短距离,直线到直线的最短距离,然后跑最短路即可
- #include <bits/stdc++.h>
- using namespace std;
- #define N 1010
- #define INF 0x3f3f3f3f
- const double eps = 1e-;
- int sgn(double x)
- {
- if (fabs(x) < eps) return ;
- if (x < ) return -;
- else return ;
- }
- struct Point
- {
- double x, y;
- Point() {}
- Point(double _x, double _y)
- {
- x = _x; y = _y;
- }
- double operator ^(const Point &b) const { return x * b.y - y * b.x; }
- double distance(Point p) { return hypot(x - p.x, y - p.y); }
- Point operator - (const Point &b) const { return Point(x - b.x, y - b.y); }
- };
- struct Line
- {
- Point s, e;
- Line() {}
- Line(double a, double b, double c)
- {
- if (sgn(a) == )
- {
- s = Point(, -c / b);
- e = Point(, -c / b);
- }
- else if (sgn(b) == )
- {
- s = Point(-c / a, );
- e = Point(-c / a, );
- }
- else
- {
- s = Point(, -c / b);
- e = Point(, (-c - a) / b);
- }
- }
- double length() { return s.distance(e); }
- double dispointtoline(Point p) { return fabs((p - s) ^ (e - s)) / length(); }
- }L[];
- struct circle
- {
- Point p;
- double r;
- circle() {}
- circle(double x, double y, double _r)
- {
- p = Point(x, y);
- r = _r;
- }
- }arr[N];
- int n, A, B, C1, C2;
- double x, y, r;
- double G[N][N];
- void work0(int x, int y)
- {
- double dis = arr[x].p.distance(arr[y].p);
- G[x][y] = max(0.0, dis - arr[x].r - arr[y].r);
- G[y][x] = G[x][y];
- }
- void work1(int x, int y)
- {
- double dis = L[x].dispointtoline(arr[y].p);
- G[x][y] = max(0.0, dis - arr[y].r);
- G[y][x] = G[x][y];
- }
- double dis[N];
- bool used[N];
- void Dijkstra ()
- {
- for (int i = ; i <= n + ; ++i) dis[i] = INF * 1.0, used[i] = false;
- dis[] = ;
- for (int j = ; j <= n + ; ++j)
- {
- int k = -;
- double Min = INF * 1.0;
- for (int i = ; i <= n + ; ++i)
- {
- if (!used[i] && dis[i] < Min)
- {
- Min = dis[i];
- k = i;
- }
- }
- used[k] = ;
- for (int i = ; i <= n + ; ++i)
- if (!used[i] && dis[k] + G[k][i] < dis[i])
- dis[i] = dis[k] + G[k][i];
- }
- }
- void Run()
- {
- while (scanf("%d%d%d%d%d", &n, &A, &B, &C1, &C2) != EOF)
- {
- memset(G, 0x3f, sizeof G);
- L[] = Line(A, B, C1);
- L[] = Line(A, B, C2);
- for (int i = ; i <= n + ; ++i)
- {
- scanf("%lf%lf%lf", &x, &y, &r);
- arr[i] = circle(x, y, r);
- G[i][i] = ;
- }
- for (int i = ; i <= n + ; ++i)
- for (int j = i + ; j <= n + ; ++j)
- work0(i, j);
- for (int i = ; i < ; ++i)
- for (int j = ; j <= n + ; ++j)
- work1(i, j);
- G[][] = abs(C1 - C2) / sqrt(A * A + B * B);
- G[][] = G[][];
- Dijkstra();
- printf("%.10f\n", dis[]);
- }
- }
- int main()
- {
- Run();
- return ;
- }
牛客国庆集训派对Day1 Solution的更多相关文章
- 牛客国庆集训派对Day1 L-New Game!(最短路)
链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day2 Solution
A 矩阵乘法 思路: 1° 牛客机器太快了,暴力能过. #include <bits/stdc++.h> using namespace std; #define N 5000 in ...
- 牛客国庆集训派对Day1 L New Game!(堆优化dijkstra+建图)
链接:https://ac.nowcoder.com/acm/contest/201/L来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言2097 ...
- 牛客国庆集训派对Day1.B.Attack on Titan(思路 最短路Dijkstra)
题目链接 \(Description\) 给定\(n,m,C\)及大小为\((n+1)(m+1)\)的矩阵\(c[i][j]\).平面上有\((n+1)(m+1)\)个点,从\((0,0)\)编号到\ ...
- 2019牛客国庆集训派对day1(A, B E F K)
链接:https://ac.nowcoder.com/acm/contest/1099#question A:可知符合条件的图中间肯定存在一个由1构成的矩形,找到由1构成矩形的边界,判断出现的1的数量 ...
- 牛客国庆集训派对Day4 Solution
A 深度学习 puts(n) #include <bits/stdc++.h> using namespace std; int main() { double n; while ( ...
- 牛客国庆集训派对Day1 B. Attack on Titan
B. Attack on Titan 链接 #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- 牛客国庆集训派对Day3 Solution
A Knight 留坑. B Tree 思路:两次树形DP,但是要考虑0没有逆元 可以用前缀后缀做 #include <bits/stdc++.h> using namespa ...
- 牛客国庆集训派对Day5 Solution
A 璀璨光滑 留坑. B 电音之王 蒙特马利大数乘模运算 #include <bits/stdc++.h> using namespace std; typedef long ...
随机推荐
- linux命令之scp
两个主机之间copy数据经常用到命令 1.copy文件命令 scp /home/test/1.mp3 root@192.168.1.20:/home/test/music 2.copy文件目录命令 s ...
- Linux中的命令学习笔记
Linux挂载Winodws共享文件夹 mount -t cifs -o username=xxx,password=xxxx //1.1.1.1/test /win 产生一个5位随机字符串 | md ...
- javascript中五种基本数据类型
前言: JavaScript中有五种基本数据类型(也叫做简单数据类型)分别为:undefined.null.bolean.number.string:另外还含有一种复杂的数据类型:object. 深入 ...
- NSFileManager和NSFileHandle(附:获取文件大小 )
本文转载至:http://www.cnblogs.com/pengyingh/articles/2350345.html 天牛 感谢原创作者的硕果 //file 文件操作 NSFileManager ...
- solr删除数据的4种方便快捷的方式
1.在solr客户端,访问你的索引库(我认为最方便的方法) 1)documents type 选择 XML 2)documents 输入下面语句 <delete><query> ...
- HTTP/2笔记之开篇
前言 本系列基于HTTP/2第17个草案文档,地址就是:https://tools.ietf.org/html/draft-ietf-httpbis-http2-17. HTTP/2规范已经通过发布批 ...
- 河南省第七届ACM程序设计大赛总结
省赛总结 首先说说比赛时的情况吧,刚开始的时候我的任务就是翻译英文题目,找出比较水的题目,他们两个直接找中文水题切,其实每次比赛我们都是这样配合的,由于他们的判题系统一开始存在问题,交的正确的代码给判 ...
- Mybatis 搭配 阿里druid连接池 连接 oracle 或 mysql
DRUID介绍 DRUID是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针 ...
- 170804、使用Joda-Time优雅的处理日期时间
简介 在Java中处理日期和时间是很常见的需求,基础的工具类就是我们熟悉的Date和Calendar,然而这些工具类的api使用并不是很方便和强大,于是就诞生了Joda-Time这个专门处理日期时间的 ...
- HDU_5521_Meeting
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...