HDU5122(树状数组)
来源:互联网 发布:数据库基础面试题 编辑:程序博客网 时间:2024/05/01 09:54
水水的树状数组,求冒泡排序以后所有需要冒泡的数的个数。
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <vector>#include <queue>using namespace std;#define maxn 1111111#define maxm 121111#define INF 1000000000struct node { int num, pos;} a[maxn];int n, c[maxn];bool cmp1 (const node &a, const node &b) { return a.num < b.num;}int lowbit (int x) { return x&(-x);}void update (int pos) { if (pos <= 0) return ; for (int i = pos; i > 0; i -= lowbit (i)) { c[i] += 1; }}int sum (int pos) { int ans = 0; for (int i = pos; i <= n; i += lowbit (i)) { ans += c[i]; } return ans;}int main () { int t, kase = 0; scanf ("%d", &t); while (t--) { scanf ("%d", &n); memset (c, 0, sizeof c); for (int i = 1; i <= n; i++) { scanf ("%d", &a[i].num); a[i].pos = i; } sort (a+1, a+1+n, cmp1); int ans = 0; for (int i = 1; i <= n; i++) { if (sum (a[i].pos)) ans++; update (a[i].pos); } printf ("Case #%d: %d\n", ++kase, ans); } return 0;}
0 0
- HDU5122(树状数组)
- HDU5122 K.Bro Sorting 【树状数组】
- HDU5122 K.Bro Sorting 树状数组
- HDU5122 K.Bro Sorting 树状数组类逆序数应用
- hdu5122
- hdu5122
- HDU5122【水】
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- Java中的静态分派与动态分派
- 项目33.2 求阶乘
- 思维导图
- JS手机触摸屏的事件用法详解
- redis部署使用
- HDU5122(树状数组)
- undefined reference to 'pthread_create'问题解决
- 对于大学生应该如何选择软件测试方面的企业?
- 数字在排序数组中出现的次数
- Java泛型T的应用 获取T类型
- Redis内存使用优化和存储
- svn 使用配置详解
- vim打开文件时显示行号
- 心情