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;
    } 
    
  • 相关阅读:
    Appium环境搭建+cordova
    Appium简单测试用例
    appium常用方法整理
    JAVA+Maven+TestNG搭建接口测试框架及实例
    stm32填坑之旅一
    再度分(tu)析(cao)Egret这个年轻人
    Egret的若干局限
    egret随笔-egret浅入浅出
    一步一步实现AS3拖放组件
    react-native学习笔记——ViewStack组件
  • 原文地址:https://www.cnblogs.com/manziqi/p/8515817.html
Copyright © 2011-2022 走看看