BNUOJ 26228 Juggler
Juggler
This problem will be judged on HDU. Original ID: 4262
64-bit integer IO format: %I64d Java class name: Main
Input
Output
Sample Input
3
3
2
1
0
Sample Output
5
Explanation of the sample input: The first ball is in the juggler’s hand and should be dropped third; the second ball is immediately clockwise from the first ball and should be dropped second; the third ball is immediately clockwise from the second ball and should be dropped last.
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
LL d[maxn];
int pos[maxn],n;
int lowbit(int x){
return x&-x;
}
void add(int x,int val){
for(; x < maxn; x += lowbit(x)){
d[x] += val;
}
}
LL sum(int x){
LL temp = ;
for(; x > ; x -= lowbit(x))
temp += d[x];
return temp;
}
int main(){
int i,j,temp,cnt;
LL ans;
while(scanf("%d",&n),n){
memset(d,,sizeof(d));
memset(pos,,sizeof(pos));
for(i = ; i <= n; i++){
scanf("%d",&temp);
pos[temp] = i;
add(i,);
}
cnt = ;
ans = ;
for(i = ; i <= n; i++){
ans++;
if(cnt != pos[i]){
LL df = abs(sum(cnt-)-sum(pos[i]-));
ans += min(df,n-i-df+);
}
cnt = pos[i];
add(pos[i],-);
}
printf("%I64d\n",ans);
}
return ;
}
BNUOJ 26228 Juggler的更多相关文章
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- bnuoj 44359 快来买肉松饼
http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms Case Time Lim ...
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
- bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...
- bnuoj 25662 A Famous Grid (构图+BFS)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...
- bnuoj 4207 台风(模拟题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4207 [题意]:中文题,略 [题解]:模拟 [code]: #include <iostrea ...
- bnuoj 4208 Bubble sort
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4208 [题意]:如题,求冒泡排序遍历趟数 [题解]:这题开始2B了,先模拟TLE,然后想了一下,能不 ...
随机推荐
- [Usaco2005 Jan]Muddy Fields泥泞的牧场
Description 雨连续不断的击打了放牛的牧场,一个R行C列的格子(1<=R<=50,1<=C<=50).虽然这对草来说是件好事,但这却使得一些没有草遮盖的土地变得很泥泞 ...
- vijos1846 [NOIP2013] 华容道【最短路】
传送门:https://vijos.org/p/1983 (其实noip的题各个oj都会有的,就不贴其它传送门了) 这道题真的是,怎么说,我都不知道怎么评价了= =.果然数据量小的题怎么暴力都可以过. ...
- Optimizing Downloads for Efficient Network Access
Optimizing Downloads for Efficient Network Access Previous Next 1.This lesson teaches you to Unders ...
- shell脚本中定义路径变量出现的BUG
=========================================================================== if 语句中的定义路径变量 引发命令的PATH路 ...
- 移动端UI自动化Appium测试——获取APK的Package及Activity属性值
1.如果有代码环境,直接在AndroidManifest.xml中查找: package值: Activity值: 2.如果没有开发代码,直接用命令获取: cmd进入到 android-sdk-win ...
- $.extend(x,y); 函数用法介绍。
第一篇资料: 转自: https://www.cnblogs.com/yuqingfamily/p/5813650.html 语法:jQuery.extend( [deep ], target, o ...
- HTML5 File API的应用
HTML5 File API简介 HTML5File API协议族 Directories and System 文件系统和目录读取 FileWriter 写入文件 FileReader ...
- 仿陌陌的ios客户端+服务端源码
软件功能:模仿陌陌客户端,功能很相似,注册.登陆.上传照片.浏览照片.浏览查找附近会员.关注.取消关注.聊天.语音和文字聊天,还有拼车和搭车的功能,支持微博分享和查找好友. 后台是php+mysql, ...
- PostgreSQL 数据库错误状态编号解释[附带列表
PostgreSQL 服务器发出的所有消息都赋予了五个字符的错误代码, 这些代码遵循 SQL 的 "SQLSTATE" 代码的习惯.需要知道发生了什么错误条件的应用通常应该测试错误 ...
- vultr系统重建
vultr服务器重启后ssh连接不上,view console只能guest登录,遍寻方法,无解,无奈重装系统. 服务器地址:Los Angeles 系统: Ubuntu 14.04 x64 用户:r ...