#1351. [Baltic2006]COUNTRIES

[Baltic2006]COUNTRIES

题目描述

This problem considers how mighty countries arise from humble beginnings. Consider a two-dimensional map of the area. On this map there are n cities. Each city ii is in a distinct location with coordinates (xi,yi)(x_i, y_i) on the map. The city has also a number sis_i of soldiers in it under the command of a general.

The influence city ii exerts to another location (x,y)(x,y) is computed as sis_i divided by the squared distance between it and (x,y)(x,y) . It is as if the mass of soldiers in city ii exerted a gravitational pull to all map locations around it. City ii is threatened by another city jj if the influence exerted by city jj on the location (xi,yi)(x_i, y_i) of city ii exceeds its number of soldiers sis_i : then city jj can dispatch enough soldiers to overpower all the soldiers defending city ii. If city ii is not threatened by any other city jj, then its grateful citizens elect its invincible general as their king, and turn their city into the capital of his kingdom.

On the other hand, if some city jj threatening city ii exerts strictly more influence on its location (xi,yi)(x_i, y_i) than any other city kk, then the citizens of city ii have no choice: city ii must surrender to city jj. Henceforth city ii must obey the same capital as city jj obeys; however, the sis_i soldiers in city ii do not join the army of city jj or the capital. Otherwise city ii is saved by mutual distrust of the equally threatening cities jj and kk: If one of them would attack and overpower city ii, then the other would in turn attack and overpower the battle-weary first attackers. However, the citizens of city ii can no longer elect its general as their king, because he has failed in his duty to keep the city safe from threats. Thus they must turn their city into the capital of a democracy instead.

Your task is to write a program, which takes the information about the cities on the map as inputs, and outputs for each city ii one of the three outcomes:

• It is the capital of a kindgom.

• It is the capital of a democracy.

• It obeys city jj as its capital.

输入格式

The input is read from a text file named countries.in.

The first line consists of one integer nn, the number of cities.

The following nn lines give the information on the nn cities, each city as its own line.

Line i+1i + 1 gives the information on city ii as the three integers xi,yi,six_i, y_i, s_i which are separated by single space characters.

输出格式

The output is written into a text file named countries.out.

The output consists of nn lines, where line i consists of the outcome for city ii:

• The character K if city ii is the capital of a kingdom.

• The character D if city ii is the capital of a democracy.

• The number 1jn1 ≤ j ≤ n of the city which city ii obeys as its capital if city ii had to surrender.

5
2 5 14
2 3 2
3 2 7
1 1 2
2 1 3
K
D
K
3
3

数据规模与约定

对于 100%100\% 的数据,1n1031\leq n \leq 10^30xi,yi,si1030 \leq x_i, y_i, s_i \leq 10^3