hdu2492 Ping pong
题意:一群乒乓爱好者居住在一条直线上,如果两个人想打比赛需要一个裁判,裁判的 位置 必须在两者之间 ,裁判的能力也必须不大于 参赛者最大的,不小于参赛者最小的
白皮的题解:考虑 第 i 个 为裁判 的情况 如果 左边 比 a[i] 小的 人数 为 c[i],则 有 i-c[i]-1 个人 比 a[i] 大,同样 右边 比 a[i] 小 的人数为 d[i] ,则比a[i]大的人为 n - i - d[i];
则方案 为 d[i]*( i - c[i] - 1 ) + c[i] * (n - i - d[i])
用 x[ a[i] ] 表示 比 a[i] 小的个数,这就涉及到了 树状数组
代码……
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const double ESP = 10e-;
const int MOD = ;
typedef long long LL;
const int MAXN = + ;
const int MAXA = + ;
int bit[MAXA];
int c[MAXN];
int d[MAXN];
int arr[MAXN]; int sum(int i){
int s = ;
while(i > ){
s += bit[i];
i -= i&-i;
}
return s;
} void add(int i,int x){
while(i < MAXA){
bit[i] += x;
i += i&-i;
}
}
int main(){
// freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
memset(bit,,sizeof(bit));
memset(c,,sizeof(c));
memset(d,,sizeof(d));
for(int i = ;i <= n;i++){
scanf("%d",&arr[i]);
c[i] = sum(arr[i]);
add(arr[i],);
}
memset(bit,,sizeof(bit));
for(int i = n;i > ;i--){
d[i] = sum(arr[i]-);
add(arr[i],);
}
LL ans = ;
for(int i = ;i <= n;i++){
ans += c[i]*(n-i-d[i]) + d[i]*(i-c[i]-);
}
printf("%I64d\n",ans);
}
return ;
}
hdu2492 Ping pong的更多相关文章
- HDU 2492 Ping pong (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
- Frequent values && Ping pong
Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ...
- Ping pong(树状数组经典)
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Eclipse中DTD验证导致无法进行代码提示的问题(转)
eclipse的xml插件进行dtd验证的时候由于找不到dtd或请求主机相应超时,会出现黄色的警告 The file cannot be validated as the host "www ...
- Week14(12月11日):路由
Part I:提问 =========================== 1.Visual Studio 2013自带ASP.NET MVC最高版本为(). A.3 B.4 C.5 D.6 2 ...
- GSAP学习笔记
GSAP(Green Sock Animation Platform)是一个十分好用的js动画库,据说是as的精简版 以下是学习GSAP的一些笔记:貌似中文的文档不是很多 GSAP notes: tl ...
- Windows Azure 社区新闻综述(#77 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 · 文章: Windows Azure 表存储简 ...
- centos安装vim7.4
转载于:http://www.cnblogs.com/nhlinkin/p/3545509.html 系统版本centos6.4; root权限 su - root 卸载 $ rpm - ...
- window下如何搭建linux环境
1.使用虚拟机 使用VMware虚拟机,下载linux内核系统,加载运行. 2.cygwin 安装cygwin,设置环境变量. 第二种方法还是比较简便的.优先考虑.
- 移动端rem,scale动态设置
pt:物理像素(电容屏上像素块个数) px:逻辑像素.设备独立像素 高清屏:1px = 4pt 普通屏:1px = 1pt dpr:设备像素比:(某一方向上)物理像素/逻辑像素 通常设置1rem=屏幕 ...
- iOS UISearchBar UISearchController
搜索栏的重要性我们就不说了,狼厂就是靠搜索起家的,现在越来越像一匹没有节操的狼,UC浏览器搜索栏现在默认自家的神马搜索,现在不管是社 交,O2O还是在线教育等都会有一个搜索栏的实现,不过彼此实现效果是 ...
- 一个人的旅行(Dijkstra算法)
这道题可用Dijkstra算法,好像还有floyd等算法,慢慢研究 Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途 ...
- java -- 轻量级锁
在了解轻量级锁之前,首先要知道什么是CAS CAS--Compare And Swap 比较并交换--通过比较传入的旧值和原内存位置中的值比较,来决定是不是要更新数据. CAS的语义是“我认为V的值应 ...