hdu2429Ping pong
Each player has
a unique skill rank. To improve their skill rank, they often compete with each
other. If two 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 have to walk to the referee’s house, and
because they are lazy, they want to make their total walking distance no more
than the distance between their houses. Of course all players live in different
houses and the position of their houses are all different. If the referee or any
of the two contestants is different, we call two games different. Now is the
problem: how many different games can be held in this ping pong street?
T(1<=T<=20), indicating the number of test cases, followed by T lines each
of 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 each player, in the
order of west to east. (1 <= ai <= 100000, i = 1 … N).
integer, the total number of different games.
3 1 2 3
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; int an[];
int s[];
const int N = ;
int lb(int x)
{
return x&(-x);
}
void add(int i)
{
if(i>N) return;
s[i]++;
add(i+lb(i));
}
int get(int i)
{
if(i == )return ;
return s[i]+get(i-lb(i));
}
int taa[],tab[],tba[],tbb[]; int main()
{
int z;
cin>>z;
while(z--)
{
int n,i,j,k;
cin>>n;
memset(s,,sizeof(s));
memset(taa,,sizeof(taa));
memset(tab,,sizeof(tab));
for(i = ;i<=n;i++)
scanf("%d",&an[i]);
for(i = ;i<=n;i++)
{
taa[i] = get(an[i]-);
tab[i] = i--get(an[i]);
add(an[i]);
}
memset(s,,sizeof(s));
memset(tba,,sizeof(tba));
memset(tbb,,sizeof(tbb));
for(i = n;i>=;i--)
{
tba[i] = get(an[i]-);
tbb[i] = n-i-get(an[i]);
add(an[i]);
}
long long ans = ;
for(i = ;i<=n;i++)
{
ans += taa[i]*tbb[i]+tab[i]*tba[i];
ans += (i--taa[i]-tab[i])*(n-i)+(taa[i]+tab[i])*(n-i-tba[i]-tbb[i]);
}
cout<<ans<<endl;
}
return ;
}
hdu2429Ping pong的更多相关文章
- HDU 2492 Ping pong (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...
- POJ3928Ping pong[树状数组 仿逆序对]
Ping pong Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3109 Accepted: 1148 Descrip ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...
- Mini projects #4 ---- Pong
课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- (转) Deep Reinforcement Learning: Pong from Pixels
Andrej Karpathy blog About Hacker's guide to Neural Networks Deep Reinforcement Learning: Pong from ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
随机推荐
- Flex 扩展combobox 实现复选功能
前段时间,老大召唤,给个任务,研究一下flex的combobox控件 实现复选功能(flex自带的combobox控件不可以复选),小兵能力有限,哪里可以扩展呀,网上看了别人写的,发现总是有点瑕疵(关 ...
- OpenCV——Rect矩阵类
成员变量x.y.width.height,分别为左上角点的坐标和矩形的宽和高. 常用的成员函数有: Size()返回值为一个Size area()返回矩形的面积 contains(Point)用来判断 ...
- js继承模式
组合继承是js常用的继承模式,指的是将原型链和借用构造函数的技术结合在一起.其中的思想是使用原型链实现原型属性和方法的继承, 而通过借用构造函数实现对属性的继承. 例子: <script> ...
- Jquery网页选项卡应用
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- PHP怎么实现网站中,同一个用户不能同时在线?
先上图,看个大概: 一般的原则就是,后一个用户登录时会把前一个用户踢下线. 在用户首次登录时,我们会把用户的sessionid保存到数据库,这个是用户的唯一标识.方便后边操作. 用户只有在登录时才会和 ...
- 数字转化为人民币大写(PHP)
<?php function numTrmb($num) { $d = array("零", "壹", "贰", "叁&qu ...
- python 连接操作数据库(一)
一.下面我们所说的就是连接mysql的应用: 1.其实在python中连接操作mysql的模块有多个,在这里我只给大家演示pymysql这一个模块(其实我是感觉它比较好用而已): pymysql是第三 ...
- python笔记之bisect模块
python笔记之bisect模块 当你决定使用二分搜索时,这个模块会给你带来很大的帮助. 例子 import bisect L = [1,3,3,6,8,12,15] x = 3 #在L中查找x,x ...
- C语言之预处理命令
/**************************************************************************** Title:C之预处理命令 Time:201 ...
- Effective Java2读书笔记-创建和销毁对象(一)
第1条:考虑用静态工厂方法代替构造器 通常情况下,我们创建一个对象采取new的形式,但是还有一种方法也是经常使用到的,它的名称叫做静态工厂方法. 例如,java中基本类型boolean的包装类Bool ...