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和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
随机推荐
- 系统简单的UIImagePickerController
1.从系统相册中读取 /* 判断选择的读取类型是否支持 UIImagePickerControllerSourceTypePhotoLibrary,普通相册 UIImagePickerControll ...
- iOS开发-单例模式的解读
现在网上的有很多人写单例模式,一个很基本的东西但是版本也有很多,新人看了难免有些眼花缭乱的感觉.自己最新比较闲,也过来写一些自己的心得. 在往下看之前,我们要明白一点,那就是在什么情况下我们才要用到单 ...
- java基础知识2
58.线程的基本概念.线程的基本状态以及状态之间的关系线程指在程序执行过程中,能够执行程序代码的一个执行单位,每个程序至少都有一个线程,也就是程序本身.Java中的线程有四种状态分别是:运行.就绪.挂 ...
- [Javascript]史上最短的IE浏览器判断代码
今天发现个很有趣的js判断全世界最短的代码,想想之前自己写的判断ie浏览器的,这个实在简单多了 var ie = !+"\v1"; 仅仅需要7bytes!参见这篇文章,<32 ...
- base64自定义编码表 php版本
在一次接口对接中,要用到base64自定义编码表来进行编码和解码,从网上搜索了一下,讲原理的比较多也比较透彻,提供的编码的例子但是没有解码的,以下是自己实现的一个base64自定义字典解码的例子,比较 ...
- ubuntu 新建zend framework 项目
1. sudo apt-get install zend-framework /usr/share/php/libzend-framework-php 2. 配置include_path /etc/p ...
- 【python学习笔记01】python的数据类型
python的基本数据类型 整型 int 浮点型 float 真值 bool 字符串 str 列表 list #[1,2,3] 元组 tuple #(1,2,3) 字典 dict ...
- servlet示例
当用户向客户端发送一个请求,如: [plain] view plaincopy http://localhost:8088/ServApp/myreq.cg?param1=param 当Soc ...
- 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
python IO操作的时候出现这种错误,检查一些url的目录 这个时候需要注意一下一般的dir举例是:“F:\DOCUMENT\4.7” 需要修改成为:F:/DOCUMENT/4.7
- KEIL CRACK及 0xFD Bug修正方法
0xFD Bug是keil编译器中始终存在,而又从未得到官方修复的一个BUG!!! BUG描述:当C源代码中使用了汉字等非ASCII字符,而此字符的编码又恰好包含了大于或等于0xFD的字节时,这个字节 ...