#P40013. 2019 ICPC NA Qualifier Contest C - Gerrymandering

2019 ICPC NA Qualifier Contest C - Gerrymandering

题目描述

Electoral systems across the world can vary widely. In some systems, such as winner-take-all, the winner is determined by the plurality of votes—the candidate that receives the most votes wins, and the loser(s) do not get a position.

Such elections can have “wasted votes.” Conceptually, a wasted vote is a vote that did not affect the election outcome. While the exact definition of a wasted vote varies, we’ll adopt the following definition: in an election with VV voters, every vote for a losing candidate is wasted (these are called lost votes), and every vote for a winning candidate beyond the strict majority of V/2+1\lfloor V/2\rfloor + 1 votes the candidate needs to win is wasted (these are called excess votes). For this problem we’ll consider a two-party system (let’s call the parties A and B) with elections that always involve one candidate from each party.

Let’s illustrate wasted votes with a simple example between two candidates in a district. Suppose that the candidate for party A receives 100100 votes and the candidate for party B receives 200200 votes. All 100100 votes for party A are wasted (lost votes for A), and 4949 votes for party B are wasted (excess votes for B). This is because B needs 151151 ((100+200)/2+1\lfloor (100 + 200) / 2 \rfloor + 1) votes to win (over A), so the remaining 4949 are wasted.

Political scientists use wasted votes to compute the efficiency gap, a single number that summarizes wasted votes. Suppose we have a number of races in different districts, where each district elects one person. Across all districts there are VV total votes cast, with wAw_ A total wasted votes for party A and wBw_ B total wasted votes for party B. Then the efficiency gap is:

E(V,wA,wB)=wAwBV.E(V, w_ A, w_ B) = \frac{|w_ A - w_ B|}{V}.

A low efficiency gap indicates that the elections are competitive, and that the number of candidates elected from each party is representative of the total voting share for each party. When the efficiency gap is high, this can be an indication of gerrymandering. Gerrymandering refers to organizing voting districts in a way that favors a particular political outcome. Two common ways of doing this are to “pack” similar voters into districts, or “crack” them across multiple districts; both ways tend to diminish those voters’ influence in electing candidates they would like to win.

In an election, districts are made up of precincts. A precinct is an indivisible group of voters. The votes for all precincts in a district are added together to find the results for that district. In this problem you are given a description of a number of precincts: the party vote totals for each precinct, and how those precincts have been grouped into districts. For each district, determine the party that wins and the wasted votes for each party. Then determine the efficiency gap between the two parties over all the districts.

输入格式

The input describes one election. The first line contains two integers PP and DD, where 1P100001 \le P \le 10\, 000 and 1Dmin(1000,P)1 \le D \le \min (1\, 000, P). These indicate, respectively, the number of voting precincts and districts. Following this are PP lines describing the precincts. Line ii contains 33 numbers: the district did_ i that precinct ii is assigned to (1diD1 \le d_ i \le D), the number of votes for the candidate from party A (0ai1000000 \le a_ i \le 100\, 000), and the number of votes for the candidate from party B (0bi1000000 \le b_ i \le 100\, 000). It is guaranteed that:

  • for each precinct ii,0ai+bi0 \le a_ i + b_ i,
  • each district is assigned at least one precinct, and
  • there are no ties within any district.

输出格式

For each of the districts from 11 to DD, print which party wins (a single character, either A or B). Then print the number of wasted votes for party A and for party B, in order. Finally, after reporting on all the districts, print the efficiency gap as measured over all the districts. The efficiency gap should be accurate to within an absolute error of 10610^{-6}.

样例

输入样例1

5 3
1 100 200
2 100 99
3 100 50
3 100 50
2 100 98

输出样例1

B 100 49
A 1 197
A 49 100
0.1965897693

输入样例2

4 4
3 100 99
2 100 99
1 100 99
4 100 99

输出样例2

A 0 99
A 0 99
A 0 99
A 0 99
0.4974874372

输入样例3

4 4
4 99 100
1 100 99
3 100 99
2 99 100

输出样例3

A 0 99
B 99 0
A 0 99
B 99 0
0.0000000000