栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2887 Server Relocation

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2887 Server Relocation

#include <stdio.h>#include <stdlib.h>int mind[1000];int q[1000];int pos[1000][2];double dist(int i, int j){    double x = abs(pos[i][0] - pos[j][0]);    double y = abs(pos[i][1] - pos[j][1]);    return x * x + y * y;}int main(){    int kase, re;    int i, n, f, t, p, e;    double l, ll;    scanf("%d", &kase);    while(kase--) {        scanf("%d", &re);        while(re--) { scanf("%d", &n); scanf("%d%d", &f, &t); f--; t--; scanf("%lf%lf", &l, &ll); l += ll; l *= l; for (i = 0; i < n; i++) {     scanf("%d%d", &pos[i][0], &pos[i][1]);     mind[i] = -1; } q[0] = f; mind[f] = 0; p = 0; e = 1; while(mind[t] == -1 && p < e) {     f = q[p++];     for (i = 0; i < n; i++) {         if(mind[i] == -1 && dist(f, i) <= l) {  mind[i] = mind[f] + 1;  q[e++] = i;         }     } } if(mind[t] == -1) puts("Impossible"); else printf("%dn", mind[t]);        }    }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368243.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号