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 ...
随机推荐
- 基于nginx实现protobuf RPC
老婆一起来上海工作,每个月消费立马上来了,做了一个android记账应用,把每笔帐都实时记录进去.开始是单机版的,只能两个人分别记,月底再merge一下.刚好有一台阿里云的ECS,于是准备升级为带服务 ...
- Android之与当前连接的wifi进行文件夹的浏览与传输
先上传jar文件:ConnectWifi.jar.zip 上传源文件:org.zip 使用实例及相应的注释: import java.io.File; import java.net.InetAddr ...
- easyui datagrid 计算
转载,至高吴上(Alfa.wu) !谢谢! /******************************************************** 主要用于 明细表格 字段间的计算 Sta ...
- Glusterfs初试
Gluster的模式及介绍在此不表,这里只记录安装及配置过程. 1.整体环境 server1 : gfs1.cluster.com server2 : gfs2.cluster.com Client: ...
- 线程池的corePoolSize、maximumPoolSize和poolSize
什么是线程池: 为了避免系统频繁的创建和销毁线程,我们可以将创建的线程进行复用.在线程池中总有那么几个活跃的线程,也有一定的最大值限制,一个业务使用完线程之后,不是立即销毁而是将其放入到线程池中,从而 ...
- 数据库实例: STOREBOOK > 用户 > 编辑 用户: MGMT_VIEW
ylbtech-Oracle:数据库实例: STOREBOOK > 用户 > 编辑 用户: MGMT_VIEW 编辑 用户: MGMT_VIEW 1. 一般信息返回顶部 1.1, ...
- Adapter 适配器模式 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Android -- SlidingMenu
实现原理 在一个Activity的布局中需要有两部分,一个是菜单(menu)的布局,一个是内容(content)的布局.两个布局横向排列,菜单布局在左,内容布局在右.初始化的时候将菜单布局向左偏移,以 ...
- Linux系统多网卡绑定实战
导读 对于服务器来说,网络设备的稳定也是比较重要的,特别是网卡.在生产型的系统中,网卡的可靠性就更为重要了. 多块网卡绑定到一个IP地址,当一块网卡发生物理性损坏的情况下,另一块网卡自动启用,并提供正 ...
- [转] SSH免密码登陆以及穿越跳板机
原文链接:http://www.cnblogs.com/lucantang/p/3315329.html SSH免密码登陆以及穿越跳板机 1. 免密码直连 [user@hostA ~] $ssh ...