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 ...
随机推荐
- iOS抽屉效果
源代码下载 抽屉效果第三方类库下载 所需第三方类库下载 側拉栏抽屉效果图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTUhUaW9z/font/5a6L ...
- Spring9 : Autowire(自动装配)机制
原文出处: 五月的仓颉 为什么Spring要支持Autowire(自动装配) 先写几个类,首先定义一个Animal接口表示动物: 1 2 3 4 5 public interface Animal { ...
- org-mode入门教程
org-mode 入门教程By Z.H. Fu 切问录 www.fuzihao.org org-mode 入门教程 org-mode是Emacs提供的一个强大的编辑模式,可以用于做会议笔记以及制作各种 ...
- JDBC结合JSP使用(1)
1. 添加数据 在jsp页面中添加数据,和在serv中添加数据相似.获得页面中提交的数据以后,把数据保存到数据库表中,JSP的代码如下: add.jsp <%@ page language=&q ...
- C 语言:返回两个数组中第一个相同元素的指针(我用了loop 、goto loop标签)
// // main.c // Pointer_search // // Created by ma c on 15/8/2. // 要求:通过指针查找,实现比较两个有序数组中的元素,输出两个 ...
- Tengine zabbix 监控
Tengine 配置 在http 段下新增以下配置 req_status_zone server_stat "$host" 3M; server { listen 9008; lo ...
- javascript基础知识梳理-Number与String之间的互相转换【转】
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 10个步骤让你成为高效的Web开发者
要成为高产.高效的Web开发者,这需要我们做很多工作,来提高我们的工作方式,以及改善我们的劳动成果. 下面是10个提高效率的步骤,虽然不能保证解决你在开发中的所有问题,但至少是非常实用的,可以简化你的 ...
- python 分词计算文档TF-IDF值并排序
文章来自于我的个人博客:python 分词计算文档TF-IDF值并排序 该程序实现的功能是:首先读取一些文档,然后通过jieba来分词,将分词存入文件,然后通过sklearn计算每一个分词文档中的tf ...
- HDU 2825 Wireless Password【AC自动机+DP】
给m个单词,由这m个单词组成的一个新单词(两个单词可以重叠包含)长度为n,且新单词中包含的基本单词数目不少于k个.问这样的新单词共有多少个? m很小,用二进制表示新单词中包含基本单词的情况. 用m个单 ...