HDUOJ------2492Ping pong
Ping pong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3518 Accepted Submission(s): 1299
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?
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).
本题是2008年北京赛区的H题,大致题意为两个乒乓选手a和b想提升排名,但是通过比赛来提升自己的名次,于是他们找来一个同样也是乒乓选手的c作为裁判来抉择,
题目规定c必须在a和b之间,问对于所有的n个人,总共有多少中不同的可能....
思路:如果改变a和b,那么需要三个循环才能解决,显然会超时...
但是考虑c然后统计出小于c的有多少种可能x,大于c有多少种可能y..
很容易知道结果为x*y....
于是就可以推得公式: sum=Σi=0(xi*yi);
剩下的便是统计了...
这里我用的是BIT即树状数组
代码如下:
//@coder Gxjun
//BIT algorithm
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 20000
#define val 100000
int bb[val+],aa[maxn];
//低位技术
int lowbit(int k)
{
return k&(-k);
// return k&(k&(k-1));
// return k&!(k-1);
}
void ope(int x)
{
while(x<=val)
{
bb[x]++;
x+=lowbit(x);
}
} int sum(int x)
{
int ans=;
while(x>)
{
ans+=bb[x];
x-=lowbit(x);
}
return ans;
}
int xx[maxn],yy[maxn];
int main()
{
int tt,nn,i;
scanf("%d",&tt);
while(tt--)
{
scanf("%d",&nn);
for(i=;i<nn;i++)
scanf("%d",&aa[i]);
//求小于aa[i] 的个数在aa[0]~~aa[i-1]
memset(bb,,sizeof(bb));
for(i=;i<nn;i++)
{
xx[i]=sum(aa[i]-);
ope(aa[i]);
}
memset(bb,,sizeof(bb));
for(i=nn-; i>=;i--)
{
yy[i]=sum(aa[i]-);
ope(aa[i]);
}
__int64 res=;
for(i=;i<nn ;i++)
{
res+=(i-xx[i])*yy[i]+xx[i]*(nn-i--yy[i]);
}
printf("%I64d\n",res);
}
return ;
}
HDUOJ------2492Ping 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 ...
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- Mini projects #4 ---- Pong
课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- 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 ...
随机推荐
- JQuery文件上传及以Base64字符串形式呈现图片
一:上传之 首先,你必然得有一个 file input,如下: <td> <img id="imgGif" style="display: no ...
- 批处理bat一键安装APK
批处理bat一键安装APK 2018年10月11日 10:48:28 xyzshenxiang 阅读数:77 在安装apk时,每次都得拷贝到手机内存中,然后在手机上操作安装这样做非常不方便,下面介 ...
- 深入分析JavaWeb Item7 -- HttpServletResponse详解
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...
- vue路由使用踩坑点:当动态路由再使用路由name去匹配跳转时总是跳转到根路由的问题
闲话少说,直接问题: 之前我的路由时这么写的 { path:'/serverInfo/:id', name:'serverInfo', component:() => import('@/vie ...
- Java基础(十二):包(package)
一.Java 包(package): 为了更好地组织类,Java 提供了包机制,用于区别类名的命名空间.包的作用: 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2.如同文件夹 ...
- C++数据结构面试题
原文:http://1527zhaobin.iteye.com/blog/1537110 一.判断链表是否存在环型链表问题: 说明:判断一个链表是否存在环,例如下面这个链表就存在环,n1--> ...
- [Node.js] Gzip + crypto in stream
We can using gzip and crypto with stream: const fs = require('fs') const zlib = require('zlib') cons ...
- Vector 多字段排序的Java实现
要求实现: Vector 多字段排序,其中首元素不参与排序,第一二三字段升序,空排到前面. //这里是Vector的元素定义 public class AVectorElement { private ...
- 多个桌面Deskspace如何使用
1 给Deskspace设置背景.在DeskSpace选项中设置显示背景为天空箱体图像(软件自带的图像效果,也可以使用静态图像,即自己的图片) 2 给六个桌面各设置一个背景(也可以使用同一个背景)右击 ...
- STL - 容器 - UnorderedSet(一)
一些简单操作 UnorderedSetTest.cpp #include <unordered_set> #include <numeric> #include ". ...