zoukankan      html  css  js  c++  java
  • [Luogu] P3958 奶酪

    Luogu P3958 奶酪


    传送门

    这个题暴力可过【手动微笑】。好像据我知道的有BFS啦,DFS啦,还有并查集。不管你怎么写,反正我写的DFS【再次手动微笑】。首先读入数据,遍历每一个未访问的空洞进行DFS,再按距离判断哪个空洞可以继续到达,最后判断圆心高度加半径是否大于等于奶酪高度即可(即(hole[i].z + r geqslant h))。哎,可怜一个水题,我竟然考场上爆炸,还是太水啦

    #include <algorithm>
    #include <cstdio>
    #include <cmath>
    typedef long long ll;
    int T, n, h, r, stp, vis[1001];
    bool fnd;
    double tmp;
    struct che{
    	int x, y, z;
    	bool operator < (const che &chi)const{return z < chi.z;}
    }c[1001];
    inline double dist(int now, int i) {
    	return sqrt(double(c[now].x - c[i].x) * (c[now].x - c[i].x) + 
    	double(c[now].y - c[i].y) * (c[now].y - c[i].y) +
    	double(c[now].z - c[i].z) * (c[now].z - c[i].z));
    }
    void dfs(int now) {
    	if(c[now].z + r >= h) {
    		fnd = true;
    		return ;
    	}
    	vis[now] = stp;
    	for (int i = 1; i <= n; ++i) {
    		tmp = dist(now, i);
    		if(tmp <= r * 2 && vis[i] != stp && !fnd)
    			dfs(i);
    	}
    	return ;
    }
    void solve() {
    	fnd = false;
    	scanf("%d%d%d", &n, &h, &r);
    	for (int i = 1; i <= n; ++i)
    		scanf("%d%d%d", &c[i].x, &c[i].y, &c[i].z);
    	std::sort(c + 1, c + n + 1);
    	for (int i = 1; i <= n; ++i) 
    		if(!fnd && std::abs(c[i].z) - r <= 0 && vis[i] != stp)
    			dfs(i);
    	if(fnd) printf("Yes
    ");
    	else printf("No
    ");
    	return ;
    }
    int main() {
    	scanf("%d", &T);
    	while(T--) {
    		stp++;
    		solve();
    	}
    	return 0;
    } 
    
  • 相关阅读:
    君の知らない物語
    2.OSI各层概述
    [ unittest ] 使用初体验
    1.分层结构、协议、接口、服务
    [flask] jinja自定义filter来过滤html标签
    [Flask] Flask问题集(后端模板渲染项目)
    [服务器部署] Flask + virtualenv + uWSGI + Nginx 遇到的问题
    android控件的对齐方式(转)
    AIDL
    歌词的获取
  • 原文地址:https://www.cnblogs.com/manziqi/p/8515817.html
Copyright © 2011-2022 走看看