站队(test05)
来源:互联网 发布:2016淘宝刷单被降权 编辑:程序博客网 时间:2024/05/16 01:19
Problem:
给定一个长度为n的队列,求它是第几种站队方式(从矮到高认为是第一种,从高到矮认为是最后一种)
下面是代码(树状数组):
#include <stdio.h>#include <algorithm>using namespace std;typedef long long LL;#define mod 1000000007#define lowbit(x) ((x)&(-x))LL n,t[100001],ans,fac[100001],res;struct data{ double val; int pos,id;}person[100001];bool cmp(data x,data y){ return x.val<y.val;}bool cmp1(data x,data y){ return x.pos<y.pos;}void Update(int x,int c){ for(int i=x; i<=100000; i+=lowbit(i)) t[i]+=c;}LL getpos(LL x){ LL pos=0; for(int i=x; i; i-=lowbit(i)) pos+=t[i]; return pos;}LL getans(LL x){ LL ans=(getpos(person[x].id)-1)%mod*fac[n-x]%mod; return ans;}int main(){ scanf("%I64d",&n); for(int i=1; i<=n; i++) { scanf("%lf",&person[i].val); person[i].pos=i; } fac[0]=1; for(int i=1; i<=n; i++) fac[i]=fac[i-1]%mod*i%mod; sort(person+1,person+n+1,cmp); for(int i=1; i<=n; i++) person[i].id=i; sort(person+1,person+n+1,cmp1); for(int i=1; i<=n; i++) Update(i,1); for(int i=1; i<=n; i++) { (res+=getans(i))%=mod; Update(person[i].id,-1); } printf("%I64d",res+1); return 0;}
0 0
- 站队(test05)
- 士兵站队(pku1723)
- day2 test05
- day3 test05
- day4 test05
- day5 test05
- day6 test05
- day7 test05
- 站队(京东2017实习生真题)
- 13test05:亲密数
- 站队编程题(京东2017实习生真题)
- 士兵站队
- 士兵站队
- 合唱队站队
- 站队问题
- 大机构里站队忙——北漂18年(22)
- 【排序专训】练习题 士兵站队(中位数应用) 解题报告
- 2017京东春招C/C++编程题(1)——站队
- 立体视觉:算法和应用(七)
- C Primer Plus学习 二
- Docke 1.12 基础篇:48条命令(6)
- 第5周项目2-建立链栈算法库
- 文章标题
- 站队(test05)
- HDU 1114 Piggy-Bank 完全背包 .
- 数据库与表的操作之SQL Server 2012中的数据类型
- Android 逆向调用so(一)
- 夏普(SHARP) LS050T1SX01 液晶屏接口定义
- Android使用Socket进行通信
- android 的 service远程运用
- Java学习总结第十天Java第一讲试讲总结
- C语言,day03