POJ 2481 Cows(树状数组)
来源:互联网 发布:淘宝服装图片拍摄技巧 编辑:程序博客网 时间:2024/06/14 10:54
题目分析
这道题真的是给我wa出血!!主要是因为数组忘了初始化,以后还是要注意这些问题。这道题我以先按E排序从大到小排序,然后按照S从小到大排序,排序完成即可以树状数组求解即可。注意前后2个S,E值相同的情况。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e5+100;int n, C[maxn];struct Node{ int x, y, id; Node() {} Node(int a, int b, int c):x(a), y(b), id(c){} bool operator < (const Node& temp)const{ if(y != temp.y) return y > temp.y; else return x < temp.x; } bool operator == (const Node& temp) const{ if(x == temp.x && y == temp.y) return true; else return false; }}node[maxn];int ans[maxn];inline int lowbit(int x){ return x&(-x);}void add(int x, int y){ while(x <= n){ C[x] += y; x += lowbit(x); }}int sum(int x){ int ret = 0; while(x > 0){ ret += C[x]; x -= lowbit(x); } return ret;}int main(){ while(scanf("%d", &n) != EOF && n){ memset(C, 0, sizeof(C)); for(int i = 1; i <= n; i++){ scanf("%d%d", &node[i].x, &node[i].y); node[i].x++, node[i].y++; node[i].id = i; } sort(node+1, node+1+n); for(int i = 1; i <= n; i++){ if(node[i] == node[i-1]) ans[node[i].id] = ans[node[i-1].id]; else ans[node[i].id] = sum(node[i].x); add(node[i].x, 1); } for(int i = 1; i < n; i++) printf("%d ", ans[i]); printf("%d\n", ans[n]); } return 0;}
0 0
- POJ 2481 Cows 树状数组
- POJ 2481 Cows【树状数组】
- POJ 2481Cows 树状数组
- POJ 2481 Cows 树状数组
- POJ 2481 Cows (树状数组)
- POJ 2481 Cows 树状数组
- poj 2481 - Cows(树状数组)
- 树状数组 POJ 2481 Cows
- POJ(2481)Cows 树状数组
- POJ 2481 Cows(树状数组)
- POJ-2481 Cows 树状数组
- Cows - POJ 2481 树状数组
- Poj 2481 Cows 树状数组
- POJ - 2481 Cows(树状数组)
- poj 2481 Cows(树状数组)
- POJ 2481 Cows(树状数组)
- poj 2481 Cows 树状数组
- poj 2481 Cows 树状数组
- Linux GCC常用命令
- Redis 数据结构
- 开发过程中遇到图片加载之后只有一部分的情况
- 01 什么是webgl
- zebra线程管理源码简析
- POJ 2481 Cows(树状数组)
- 9个PHP魔术方法总结
- 剑指offer-15.反转链表
- Android--Parcelable接口的用法
- 欢迎使用CSDN-markdown编辑器
- HTTP Status 400 – Bad Request
- iOS预编译文件添加
- 20个代码生成框架
- CF#798 A. Mike and palindrome(水题)