C Gerrymandering(读题)

链接:https://ac.nowcoder.com/acm/contest/13168/C
来源:牛客网

示例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<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
	ll x=0,y=0;
}v[11000];
int n,m,t;
ll tx,ty,ttx,tty;
double x=0,y=0;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    while(n--)
    {
    	cin>>t>>tx>>ty;
    	y+=tx+ty;
    	v[t].x+=tx;v[t].y+=ty;
	}
	for(int i=1;i<=m;i++)
	{
		if(v[i].x>v[i].y)
		{
			ttx=v[i].x-(v[i].x+v[i].y)/2-1;
			tty=v[i].y;
			x+=ttx-tty;
			cout<<'A'<<" ";
			cout<<ttx<<" "<<tty;
		}
		else if(v[i].x<v[i].y)
		{
			ttx=v[i].x;
			tty=v[i].y-(v[i].x+v[i].y)/2-1;
			x+=ttx-tty;
			cout<<'B'<<" ";
			cout<<ttx<<" "<<tty;
		}
		cout<<endl;
	}
	if(x<0) x*=-1;
	cout<<fixed<<setprecision(10)<<x/y;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值