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

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

Ping pong

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4094    Accepted Submission(s): 1522

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
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 using namespace std;17 typedef long long LL;18 const int INF=0x5fffffff;19 const double EXP=1e-6;20 const int MS=20005;21 int c[MS];22 int n;23 24 struct node25 {26 int rank;27 int id;28 bool operator <(const node &a)const29 { // rank unique30 return rank>a.rank||(rank==a.rank&&id
0)52 {53 ret+=c[x];54 x-=lowbit(x);55 }56 return ret;57 }58 59 int main()60 {61 int T;62 scanf("%d",&T);63 while(T--)64 {65 scanf("%d",&n);66 memset(c,0,sizeof(c));67 for(int i=1;i<=n;i++)68 {69 scanf("%d",&nodes[i].rank);70 nodes[i].id=i;71 }72 sort(nodes+1,nodes+n+1);73 LL ans=0; // 一定要 LL 不然WA74 for(int i=1;i<=n;i++)75 {76 int id=nodes[i].id;77 int x=getsum(id); // 值比它大,坐标比它小的数量78 int y=i-1-x; // 值比它大的数总共有i-1,-x就是79 // 值它大,坐标比它大80 ans+=x*(n-id-y)+y*(id-1-x);81 updata(id);82 }83 printf("%lld\n",ans);84 }85 return 0;86 }

 

 

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/4099524.html

你可能感兴趣的文章
jQuery 插件开发全解析
查看>>
DEDE中 field:rel 是什么意思,起一个什么样的作用效果
查看>>
【图片】批量获取几万张图片
查看>>
Spring经常使用属性的注入及属性编辑器
查看>>
FreeRTOS系列第13篇---FreeRTOS内核控制
查看>>
python入门小记
查看>>
将逻辑卷降为物理分区
查看>>
CMake 入门实战【转】
查看>>
软硬件之共生之道——一千零一夜的启发
查看>>
redis 性能建议
查看>>
Android MaoZhuaWeiBo开发Service抓取个人信息-2
查看>>
Codefoces 436 B. Om Nom and Spiders
查看>>
流程控制------if else分支语句
查看>>
禁用Clusterware在系统启动后自己主动启动
查看>>
Storm编程入门API系列之Storm的Topology默认Workers、默认executors和默认tasks数目
查看>>
Json转java对象和List集合
查看>>
PHP操作MongoDB数据库具体样例介绍(增、删、改、查) (六)
查看>>
关于Unity中的模型描边与Shader切换(专题二)
查看>>
《淘宝技术这十年》读后感
查看>>
程序员经常加班的真正原因
查看>>