TOJ 2870 ZOJ 3221 lich/Guang Search

Source: Internet
Author: User
Tags time limit dota
Lich time limit (normal/java): 1000ms/3000ms Run memory limit: 65536KByte


Description






Dota is a kind of maps in the famous game Warcraft 3. It's so interesting that many zjuers is 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 of 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 would release a jumping breath of frost that can bounce for a few times. Frost'll randomly bounce back and forth between units that is 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 and I am not good at programing. So I turn to you, the talented ACM player.



Suppose the lich and the enemy hero (only one) stand in a and 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 would first hit the one which have a distance no more thanr from the lich and cause D damage. Then the frost would randomly bounce back and forth between alive units (but not lich himself) that is Withinr range and CA Use D damage per hit. The frost won't bounce more thanK times.



Notice that the frost must bounce from one unit to the other, or it'll 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 is Tween A and B must is no more than R, or it'll stop too.



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






input






The first line is the num of cases T (0 <=t <= 300). Each test case is starts with a line, which contains 4 positive integers,n R K D (3 <= N <=, 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 are his health point.



There is a blank after each case.






Output






For each case, just the 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.






Sample Input





3
3 1 6 0 0 0 1 0 2 3 1 5
0 0

0 1 0 2 3 1 6 1000 0
0 1
0 2 300











Sample Output





YES

No

No





First, wide search from 1 to n the shortest number of steps



Then you might think that the first time to n should be updated to go through the point of HP and then K (number of times) minus the shortest steps should attack n the number of times it's too much trouble to think about bombs.



Do not go to update the HP assumptions passed or no less blood from n this point again to eject K number of times plus 2 (a bit difficult to explain) the special situation is a step to this situation k-1 and then should attack the number of times minus one



The ability to express needs to be improved


#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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.