博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu2429Ping pong
阅读量:5306 次
发布时间:2019-06-14

本文共 2791 字,大约阅读时间需要 9 分钟。

Problem Description
N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment).
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?
 

 

Input
The first line of the input contains an integer 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).
 

 

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

 

Sample Input
1 3 1 2 3
 

 

Sample Output
1
 

 

Source
 
#include
#include
#include
#include
using namespace std;int an[51000];int s[110000];const int N = 109999;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 == 0)return 0; return s[i]+get(i-lb(i));}int taa[51000],tab[51000],tba[51000],tbb[51000];int main(){ int z; cin>>z; while(z--) { int n,i,j,k; cin>>n; memset(s,0,sizeof(s)); memset(taa,0,sizeof(taa)); memset(tab,0,sizeof(tab)); for(i = 1;i<=n;i++) scanf("%d",&an[i]); for(i = 1;i<=n;i++) { taa[i] = get(an[i]-1); tab[i] = i-1-get(an[i]); add(an[i]); } memset(s,0,sizeof(s)); memset(tba,0,sizeof(tba)); memset(tbb,0,sizeof(tbb)); for(i = n;i>=1;i--) { tba[i] = get(an[i]-1); tbb[i] = n-i-get(an[i]); add(an[i]); } long long ans = 0; for(i = 1;i<=n;i++) { ans += taa[i]*tbb[i]+tab[i]*tba[i]; ans += (i-1-taa[i]-tab[i])*(n-i)+(taa[i]+tab[i])*(n-i-tba[i]-tbb[i]); } cout<
<

 

转载于:https://www.cnblogs.com/wos1239/p/4564554.html

你可能感兴趣的文章
创新课程管理系统数据库设计心得
查看>>
Hallo wolrd!
查看>>
16下学期进度条2
查看>>
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
Chapter 3 Phenomenon——12
查看>>
C语言中求最大最小值的库函数
查看>>
和小哥哥一起刷洛谷(1)
查看>>
jquery对id中含有特殊字符的转义处理
查看>>
遇麻烦,Win7+Ubuntu12.10+Archlinux12.10 +grub
查看>>
SqlBulkCopy大批量导入数据
查看>>
pandas 修改指定列中所有内容
查看>>
「 Luogu P2285 」打鼹鼠
查看>>
lua语言入门之Sublime Text设置lua的Build System
查看>>
vue.js基础
查看>>
电脑的自带图标的显示
查看>>
[转载] redis 的两种持久化方式及原理
查看>>
C++ 删除字符串的两种实现方式
查看>>
ORA-01502: 索引'P_ABCD.PK_WEB_BASE'或这类索引的分区处于不可用状态
查看>>
Java抽象类和接口的比较
查看>>
开发进度一
查看>>