hdu 4981 Goffi and Median(BestCoder Round #6)

Goffi and Median

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 147    Accepted Submission(s): 107


Problem Description
A median in a sequence with the length of \(n\) is an element which occupies position number \(\Large\lfloor \frac{n + 1}{2} \rfloor\) after we sort the elements in the non-decreasing order (the elements are numbered starting with 1). A median of an array (2, 6, 1, 2, 3) is the number 2, and a median of array (0, 96, 17, 23) — the number 17.

An average of a sequence is the sum of sequence divided the size of the sequence.

Goffi likes median very much and he hates average number. So if a sequence's average number is larger than or equal to the median of sequence, Goffi will hate the sequence. Otherwise, Goffi will like it.

Now, your are given a sequence. Please find whether Goffi will like it or hate it.
 

Input
Input contains multiple test cases (less than 100). For each test case, the first line contains an integer \(n\) (\(1 \le n \le 1000\)), indicating the size of the sequence. Then in the next line, there are \(n\) integers \(a_1, a_2, \dots, a_n\) (\(1 \le a_i \le 1000\)), seperated by one space.
 

Output
For each case, if Goffi like the sequence, output "YES" in a line. Otherwise, output "NO".
 

Sample Input
  
  
5 1 2 3 4 5 4 1 5 6 6
 

Sample Output
  
  
NO YES
 
水题,就不说什么了,比较中位数与平均数的大小就行了

代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int hash[1010];
int main()
{
    for(int i=1;i<=1000;i++)
    hash[i]=i*i;
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        int sign=0;
        int m=(int)sqrt(n*1.0);
        if(m*m==n)
        m--;
        for(int i=m;i>=0;i--)
        {
           int p=hash[m];
           int temp=n-p;
           int t=1;
           int xi=0;
           for(int j=1;j<k-1;j++)//开始构造k-1个数中的前k-2个
           {
               if(t==temp)//与要去掉的那个数重合跳过
               t++;
               p-=t;
               if(p<=t)
               {
                   xi=1;
                   break;
               }
               t++;
           }
           if(xi==0)//判断第k-1个数是否符合
           {
               if(p==temp)//与要去掉的那个数重合
               {
                   p--;
                   t++;
               }
               if(p<t)//第k-1个数在前面k-2个数中要没出现过
                ;
               else
               {
                   sign=1;
               }
           }
        }
        if(sign)
        printf("YES\n");
        else
        printf("NO\n");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值