sdut 3251 Nias and Tug-of-War 模拟

来源:互联网 发布:医院感染管理三级网络 编辑:程序博客网 时间:2024/06/07 06:36

Nias and Tug-of-War

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

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.
 

输入

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.
 

输出

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".

示例输入

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

示例输出

blue

提示

 

来源

 

示例程序

 

  • 提交 
  • 状态 
  • 讨论
    • 省赛水题
      #pragma warning(disable:4786)//使命名长度不受限制#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈#include <map>#include <set>#include <queue>#include <cmath>#include <stack>#include <cctype>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d,&x,&y,&z)#define rdl(x) scanf("%I64d,&x);#define rds(x) scanf("%s",x)#define rdc(x) scanf("%c",&x)#define ll long long int#define ull unsigned long long#define maxn 1005#define mod 1000000007#define INF 0x3f3f3f3f //int 最大值#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define MT(x,i) memset(x,i,sizeof(x))#define PI  acos(-1.0)#define E  exp(1)#define eps 1e-8ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}ll mul(ll a,ll b,ll p){ll sum=0;for(;b;a=(a+a)%p,b>>=1)if(b&1)sum=(sum+a)%p;return sum;}inline void Scan(int &x) {      char c;while((c=getchar())<'0' || c>'9');x=c-'0';      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';}using namespace std;struct N{    double x,y;    void in(){cin>>x>>y;}    bool operator <(const N &b)const{return this->x<b.x;}}my[maxn];int main(){    int n,loop,cnt=1;    scanf("%d",&loop);    while(loop--){        scanf("%d",&n);        for(int i=0;i<n;++i)my[i].in();        sort(my,my+n);        double a=0,b=0;        for(int i=0;i<n;i+=2){            a+=my[i].y;            b+=my[i+1].y;        }        if(fabs(a-b)<eps)puts("fair");        else if(a>b)puts("red");        else puts("blue");    }    return 0;}


0 0
原创粉丝点击