ZCMU—A

A - Nias and Tug-of-War
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Nias is fond of tug-of-war. One day, he organized a tug-of-war game and invited a group of friends to take part in.

Nias will divide them into two groups. The strategy is simple, sorting them into a row according to their height from short to tall, then let them say one and two alternately (i.e. one, two, one, two...). The people who say one are the members of the red team while others are the members of the blue team.

We know that the team which has a larger sum of weight has advantages in the tug-of-war. Now give you the guys' heights and weights, please tell us which team has advantages.

Input

The first line of input contains an integer T, indicating the number of test cases.

The first line of each test case contains an integer N (N is even and 6 ≤ N ≤ 100). 

Each of the next N lines contains two real numbers X and Y, representing the height and weight of a friend respectively.

Output

One line for each test case. If the red team is more likely to win, output "red", if the blue team is more likely to win, output "blue". If both teams have the same weight, output "fair".

Sample Input

1
6 
170 55 
165.3 52.5 
180.2 60.3 
173.3 62.3 
175 57 
162.2 50

Sample Output

blue

【分析】

题意:一群人按身高排序,然后奇数去blue偶数去red,两边的人体重加起来重的一方赢,问哪边能赢....

排个序....比较

【代码】

#include <stdio.h>
#include <algorithm>
using namespace std;
struct xx{
	double x,y;
}a[100000];

int cmp(const xx &q,const xx &w)
{
	return q.x<w.x;
}


int main()
{
	int pp;scanf("%d",&pp);
	while (pp--)
	{
		int n;scanf("%d",&n);
		for (int i=0;i<n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
		sort(a,a+n,cmp);
		double ans1=0;
		double ans2=0;
		for (int i=0;i<n;i++)
			if (i%2)
				ans1+=a[i].y;
			else
				ans2+=a[i].y; 
		if (ans1==ans2) printf("fair\n");
		if (ans1<ans2) printf("red\n");
		if (ans1>ans2) printf("blue\n");
	}
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值