# TOJ 2870 ZOJ 3221 Lich / 广搜

14 篇文章 0 订阅

## Lich

Dota is a kind of map in the famous game Warcraft 3. It 's so interesting that many ZJUers are fond of it. I am one of those happy guys.

Lich is one of the heroes that I would like to choose to use in the Dota game. He has the power to use frost to cause tremendous pain to his enemy. The Lich is a murderer without a trace of warmth. His most terrified skill is Chain Frost. When using it, the lich will release a jumping breath of frost that can bounce for a few times. Frost will randomly bounce back and forth between units that are within some range and cause some damage per hit.

When I use this hero, I always want to know: can I kill the enemy heroes by using this terminal skill. Though I am a computer science student, I am not good at programing. So I turn to you, the talented ACM player.

Suppose that the lich and the enemy hero(only one) stand in a two dimension map. There areN heroes in the map. The first hero is the lich and the last hero is the enemy hero. The lich can use Chain Frost only once. The Chain Frost will first hit the one which has a distance no more thanR from the lich and cause D damage. Then the frost will randomly bounce back and forth between alive units(but not lich himself) that are withinR range and cause D damage per hit. The frost will not bounce more thanK times.

Notice that the frost must bounce from one unit to the other, or it will stop. And when the Chain Frost hits some person A, the next time it must bounce to the other person alive B, and the distance between A and B must be no more than R, or it will stop too.

Every one have a health point(HP), and when one's health point is no more than 0, he is defeated. And when one is defeated he will be removed from the map and can't be hit by the frost any more.

The first line is the num of cases T(0 <=T <= 300). Each test case starts with a line, which contains 4 positive integers,N R K D (3 <= N <= 1000, R K D <= 30000). Then N lines follow, each contain three non-negative integers:Xi, Yi, Hi (Xi Yi Hi <= 30000, Hi >= 1).Xi Yi is the horizontal coordinate and vertical coordinate and of the hero andHi is his health point.

There is a blank after each case.

For each case, just output one line. If it is possible for the lich to defeat the enemy hero, output "YES", else output "NO". Print one blank after each case.

3
3 1 6 100
0 0 1200
0 1 300
0 2 300

3 1 5 100
0 0 1200
0 1 300
0 2 300

3 1 6 100
0 0 1200
0 1 200
0 2 300



YES

NO

NO



#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("NO\n");
continue;
}
if(a[n].step == 1)
{
k--;
a[n].hp -= d;
if(a[n].hp <= 0)
{
puts("YES\n");
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("NO\n");
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("NO\n");
else
puts("YES\n");

}
return 0;
}



07-22 24
11-05 1047

03-15 446
10-28 1077
08-24 1246
11-12 1257
08-24 1219
11-12 1363
11-14 1306
11-13 1123
11-11 864
10-28 1369
11-14 1100
11-03 1092
10-24 1047
10-19 1466
11-13 1338
10-19 1122

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。