NOIP2017 D2T1 奶酪
来源:互联网 发布:文本相似算法 编辑:程序博客网 时间:2024/04/29 12:03
奶酪
题目背景:
NOIP2017 D2T1
分析:搜索
代码刚刚下来的时候,测试这道题,我差点还T了······不过事实证明还是没有卡正确复杂度的······比较简单,直接O(n2)判断一下,两个球是否联通,如果联通,则连边,然后在判断和上下底面相切的位置有哪些,将上下底面抽象成两个点,一样连边,然后从下底所代表的点,开始dfs,看是否能够到上底即可。
当时学军数据,最后两个点会爆掉long long,但是最后官方没有,感觉出题人的那个中间·····的确有逻辑漏洞······
Source:
/*created by scarlyw*/#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cctype>#include <cmath>#include <iostream>#include <queue>#include <set>#include <vector>template<class T>inline void R(T &x) {static char c;static bool iosig;for (c = getchar(), iosig = false; !isdigit(c); c = getchar()) {if (c == -1) return ;if (c == '-') iosig = true;}for (x = 0; isdigit(c); c = getchar())x = ((x << 2) + x << 1) + (c ^ '0');if (iosig) x = -x;}const int MAXN = 1000 + 10;std::vector<int> edge[MAXN];int n, h, r, t;bool vis[MAXN];struct ball {int x, y, z;} b[MAXN];inline void add_edge(int x, int y) {edge[x].push_back(y), edge[y].push_back(x);}inline bool able(int i, int j) {long long temp = (long long)(b[i].x - b[j].x) * (b[i].x - b[j].x) + (long long)(b[i].y - b[j].y) * (b[i].y - b[j].y) + (long long)(b[i].z - b[j].z) * (b[i].z - b[j].z);if ((long long)r * r * 4LL >= temp) return true;else return false;}inline void dfs(int cur) {vis[cur] = true;for (int p = 0; p < edge[cur].size(); ++p) {int v = edge[cur][p];if (!vis[v]) dfs(v);}}inline void solve() {R(n), R(h), R(r);memset(vis, 0, sizeof(bool) * (n + 5));for (int i = 0; i <= n + 1; ++i) edge[i].clear();for (int i = 1; i <= n; ++i) R(b[i].x), R(b[i].y), R(b[i].z);for (int i = 1; i <= n; ++i) if (b[i].z <= r) add_edge(0, i);for (int i = 1; i <= n; ++i) if (b[i].z >= h - r) add_edge(i, n + 1);for (int i = 1; i <= n; ++i)for (int j = i + 1; j <= n; ++j) if (able(i, j)) add_edge(i, j);dfs(0);vis[n + 1] ? (std::cout << "Yes\n") : (std::cout << "No\n");}int main() {freopen("cheese.in", "r", stdin);freopen("cheese.out", "w", stdout);R(t);while (t--) solve();return 0;}
阅读全文
0 0
- NOIP2017 D2T1 奶酪
- NOIP2017提高组D2T1[奶酪]
- NOIP 2017 D2T1 奶酪
- JZOJsenior5476.【NOIP2017提高组】day2T1奶酪
- 5476. 【NOIP2017提高组正式赛】奶酪
- NOIP2017提高组day2T1题解(奶酪)
- JZOJ 5476. 【NOIP2017提高组正式赛】奶酪
- noip2017 Day2 T1 奶酪cheese(并查集)
- 奶酪
- 奶酪
- NOIP2012 D2T1
- noip2017
- NOIP2017
- noip2017
- NOIP2017
- NOIP2017
- NOIP2017
- NOIP2017
- [Leetcode][python]Max Points on a Line
- linux-线程/进程通信eventfd
- Spring和Mybatis整合-mapper开发
- 基本数据类型
- 一个完整的Java Web项目需要掌握哪些技术
- NOIP2017 D2T1 奶酪
- classpath路径浅谈
- SpringMVC入门程序-以注解方式
- AI当歌唱比赛评委,黑幕将越来越少
- Django框架全面讲解 -- 序列化
- mybatis逆向工程利用mybatis-generator-core自动生成代码
- 【机器学习】主成分(PCA)算法分析
- bugly
- 人工智能将占领华尔街