Hdu 2492 tree-like array Ping pong

Source: Internet
Author: User


Welcome to the--bestcoder Anniversary (High quality topic + multiple Rewards)
Ping Pong

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4589 Accepted Submission (s): 1681


Problem Descriptionn (3<=n<=20000) Ping pong players live along a West-east street (consider the street as a line segm ENT).

Each player has a unique skill rank. To improve their skill rank, they often compete with each other. If-Players want to compete, they must choose a referee among other ping pong players and hold the game in the referee ' S house. For some reason, the contestants can ' t choose a referee whose skill rank is higher or lower than both of theirs.

The contestants has to walk to the referee's house, and because they is lazy, they want to make their total walking dist Ance no more than the distance between their houses. Of course all players live in different houses and the position of their houses is all different. If the referee or any of the contestants are different, we call both games different. Now are the problem:how many different games can being held in this ping Pong street?

Inputthe first line of the input contains a integer t (1<=t<=20), indicating the number of test cases, followed by T Lines each of the which describes a test case.


Every test case consists of N + 1 integers. The first integer is N, the number of players. Then N distinct integers a1, A2 ... an follow, indicating the skill rank of all player, in the order of West to east. (1 <= AI <= 100000, i = 1 ... N).

Outputfor each test case, output a single line contains an integer, and the total number of different games.

Sample Input13 1 2 3

Sample OUTPUT1

Source-Asia Regional Beijing

Recommendgaojie | We have carefully selected several similar problems for you:2485 2491 2490 2489 2488
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;structnode{intU,v,m,h;} que[100005];BOOLcmpstructNode T1,structnode T2) {     if(t1.m==t2.m)returnt1.u<t2.u; Else        returnt1.m<t2.m;}intMain () {intN;  while(SCANF ("%d", &n)! =EOF) {            if(n==0)             Break;  for(intI=0; i<n;i++) {scanf ("%d%d",&que[i].u,&que[i].v); Que[i].h= (QUE[I].V-QUE[I].U)/2+1; QUE[I].M=que[i].u+que[i].h; } sort (Que,que+n,cmp); intflag=0;  for(intI=0; i<n-1; i++){            if(que[i].m>=que[i+1].m) {flag=1;  Break; }        if(que[i].m<que[i+1].u)Continue; Doubletemp=que[i].m-que[i+1].u; Que[i+1].m=temp+que[i+1].h+que[i+1].u; }    if(flag) printf ("no\n"); Elseprintf ("yes\n"); }   return 0;}

Hdu 2492 tree-like array Ping pong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.