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

zoj 3221 Lich

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

zoj 3221 Lich

#include <stdio.h>#include <vector>#include <string.h>#include <queue>using namespace std;const int MAX = 1010;struct node{int x;int y;int num;int hp;int step;};int n,r,k,d;int dis[MAX];bool map[MAX];node a[MAX];vector <int> v[MAX];int dist(int x1,int y1,int x2,int y2){return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);}void bfs(){int i;memset(map,false,sizeof(map));node p;p.num = 1;p.step = 0;queue <node> q;q.push(p);map[1] = true;while(!q.empty()){p = q.front();q.pop();a[p.num].step = p.step;int len = v[p.num].size();for(i = 0;i < len; i++){int temp = v[p.num][i];if(map[temp])continue;node t;t.num = temp;map[temp] = true;t.step = p.step + 1;q.push(t);}}}int main(){int t,i,j,x,y,z;scanf("%d",&t);while(t--){scanf("%d %d %d %d",&n,&r,&k,&d);for(i = 1;i <= n; i++){a[i].step = 0;v[i].clear();}for(i = 1;i <= n; i++){scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].hp);for(j = 1;j < i; j++){if(dist(a[i].x,a[i].y,a[j].x,a[j].y) <= r*r){v[i].push_back(j);v[j].push_back(i);}}}bfs();if(a[n].step == 0){puts("NOn");continue;}if(a[n].step == 1){k--;a[n].hp -= d;if(a[n].hp <= 0){puts("YESn");continue;}}if(a[n].step >= 2)k = k - a[n].step + 2;int cnt1 = (a[n].hp + d - 1)/ d;if(cnt1 * 2 > k){puts("NOn");continue;}int cnt2 = 0;for(i = 0;i < v[n].size(); i++){if(v[n][i] == 1)continue;cnt2 += (a[v[n][i]].hp + d - 1)/ d;}if(cnt2 < cnt1)puts("NOn");elseputs("YESn");}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379629.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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