3.21牛客2021年度训练联盟热身训练赛第三场C.Gerrymandering[模拟]

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 131072K,其他语言262144K
Special Judge, 64bit IO Format: %lld

题目描述 

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⌊V/2⌋+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 AA and BB) 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 AA receives 100100 votes and the candidate for party BB receives 200200 votes. All 100100 votes for party AA are wasted (lost votes for AA), and 4949 votes for party BB are wasted (excess votes for BB). This is because BB needs 151151 (⌊(100+200)/2⌋+1⌊(100+200)/2⌋+1) votes to win (over AA), 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 wAwA​ total wasted votes for party AA and wBwB​ total wasted votes for party BB. Then the efficiency gap is: 

    E(V,wA,wB)=∣wA−wB∣V    E(V,wA​,wB​)=V∣wA​−wB​∣​. 

 

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 1≤P≤100001≤P≤10000 and 1≤D≤min(1000,P)1≤D≤min(1000,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 didi​ that precinct ii is assigned to (1≤di≤D)(1≤di​≤D), the number of votes for the candidate from party A(0≤ai≤100000)A(0≤ai​≤100000), and the number of votes for the candidate from party B(0≤bi≤100000)B(0≤bi​≤100000). It is guaranteed that:

 

1. for each precinct i,0<ai+bii,0<ai​+bi​,

 

2. each district is assigned at least one precinct, and

 

3. there are no ties within any district.

输出描述:

For each of the districts from 11 to DD, print which party wins (a single character, either AA or BB). Then print the number of wasted votes for party AA and for party BB, 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 10−610−6.

示例1

输入

复制

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

输出

复制

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

输出

复制

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

输出

复制

A 0 99
B 99 0
A 0 99
B 99 0
0.0000000000
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define Inf 0xfffffff
#define N 1100
#define eps 1e-7
using namespace std;

pair<int,int>pi[N];

int main()
{
    int p,d;
    cin>>p>>d;
    int wa=0,wb=0;
    ll v=0;
    while(p--)
    {
        int di,a,b;
        cin>>di>>a>>b;
        v+=a;
        v+=b;
        pi[di].first+=a;
        pi[di].second+=b;
    }
    for(int i=1;i<=d;i++)
    {
        int a=pi[i].first;
        int b=pi[i].second;
        int wwa=0,wwb=0;
        if(a>b)
        {
            cout<<"A ";
            wwb=b;
            wwa=(a-((a+b)/2+1));
        }
        else
        {
            cout<<"B ";
            wwa=a;
            wwb=(b-((a+b)/2+1));
        }
        wa+=wwa;
        wb+=wwb;
        cout<<wwa<<" "<<wwb<<endl;
    }
    double ans=(double)abs(wa-wb)/(double)v;
    printf("%.10f",ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值