hdoj4000Fruit Ninja【树状数组】
来源:互联网 发布:拷贝文件 linux 编辑:程序博客网 时间:2024/05/17 06:02
Fruit Ninja
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2227 Accepted Submission(s): 862
Problem Description
Recently, dobby is addicted in the Fruit Ninja. As you know, dobby is a free elf, so unlike other elves, he could do whatever he wants.But the hands of the elves are somehow strange, so when he cuts the fruit, he can only make specific move of his hands. Moreover, he can only start his hand in point A, and then move to point B,then move to point C,and he must make sure that point A is the lowest, point B is the highest, and point C is in the middle. Another elf, Kreacher, is not interested in cutting fruits, but he is very interested in numbers.Now, he wonders, give you a permutation of 1 to N, how many triples that makes such a relationship can you find ? That is , how many (x,y,z) can you find such that x < z < y ?
Input
The first line contains a positive integer T(T <= 10), indicates the number of test cases.For each test case, the first line of input is a positive integer N(N <= 100,000), and the second line is a permutation of 1 to N.
Output
For each test case, ouput the number of triples as the sample below, you just need to output the result mod 100000007.
Sample Input
261 3 2 6 5 45 3 5 2 4 1
Sample Output
Case #1: 10Case #2: 1
Source
2011 Multi-University Training Contest 16 - Host by TJU
题意: 给出一列1-n,n个数求满足对下标 i,j,k满足i<j<k且num[i]<num[k]<num[j]的三元组数量
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#define MOD 100000007using namespace std;const int maxn=100010;int c[maxn];int low(int x){ return x&(-x);}int sum(int n){ int value=0; while(n>0){ value+=c[n]; n-=low(n); } return value;}void add(int pos,int n){ while(pos<=n){ c[pos]+=1; pos+=low(pos); }}int main(){ int n,i,j,k=1,t,num; scanf("%d",&t); while(t--){ scanf("%d",&n); memset(c,0,sizeof(c)); long long ans=0; for(i=1;i<=n;++i){ scanf("%d",&num); long long num1=sum(num);//num前比num小的数 long long num2=(n-num)-(i-1-num1);//比num大的数 ans=ans+num2*(num2-1)/2;//从num后面大于num数中任选两个 ans=ans-num1*num2;//满足i<j<k,且num[i]<[j]<[k] 的数的数量 ans=(ans+MOD)%MOD; add(num,n); } printf("Case #%d: %lld\n",k++,ans); } return 0;}
0 0
- hdoj4000Fruit Ninja【树状数组】
- hdu4000 Fruit Ninja(树状数组)
- hdu 4000 Fruit Ninja 树状数组+统计
- HDU 4000 Fruit Ninja 树状数组
- hdu 4000 - Fruit Ninja(树状数组)
- HDU 4000 Fruit Ninja 【树状数组】
- HDU4000 Fruit Ninja(树状数组)
- Fruit Ninja - HUD 4000 树状数组
- HDU4000Fruit Ninja【树状数组+组合数】
- hdu4000 Fruit Ninja(树状数组)
- hdu 4000 Fruit Ninja(树状数组)
- hdu 4000 Fruit Ninja(树状数组)
- hdoj 4000 Fruit Ninja 【树状数组 + 思维】
- HDU 4000 Fruit Ninja(树状数组)
- HDU 4000 Fruit Ninja(树状数组)
- HDU 4000 Fruit Ninja (树状数组+组合问题)
- HDOJ 题目4000 Fruit Ninja(树状数组)
- HDU 4000 Fruit Ninja && HLG 1625 ikki的数字 (树状数组)
- 设计模式(3)--适配器模式
- SpringMVC+Mybatis框架整合源码 项目
- HDU 1114(完全背包)
- RunLoop
- 批量下载豆瓣相册图片python脚本
- hdoj4000Fruit Ninja【树状数组】
- c++ 特性: 右值引用与移动语义
- 引用指向的真正类名 getClass( ).getName( )
- Linux cmake 编译安装
- Sample Size Determination
- OC中通知使用浅析
- ios 9 网络适配
- 外部js书写规则
- Nginx增加PHP脚本的执行时间