HDU 1541 Stars
来源:互联网 发布:正版办公软件要买吗 编辑:程序博客网 时间:2024/05/08 19:31
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1541
题意:给出n个坐标,先按纵坐标升序,纵坐标相同再按横坐标升序排序,在这个点左下角的个数记做这个数的level值(不严格,纵坐标和横坐标可以相同),求0到n-1的level数是多少
思路:update单点更新,query区间求值
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long LL;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn = 32010;//注意这里的大小int sum[maxn<<2],visit[maxn];using namespace std;void pushup(int rt){ sum[rt] = sum[rt<<1] + sum[rt<<1|1];}void update(int c,int l,int r,int rt)//左右的参数写反了,找了半天bug{ if(l == r) { sum[rt]++; return; } int m = (l +r)>>1; if(c <= m) update(c,lson); else update(c,rson); pushup(rt);}int query(int L,int R,int l,int r,int rt){ if(l >= L && r <= R) return sum[rt]; int m = (l+r)>>1; int ans = 0; if(L <= m) ans += query(L,R,lson); if(R > m) ans += query(L,R,rson); return ans;}int main(){ int n; while(scanf("%d",&n) != EOF) { int m = n; memset(sum,0,sizeof(sum)); memset(visit,0,sizeof(visit)); int a,b; while(n--) { scanf("%d%d",&a,&b); int sum = query(1,a+1,1,maxn,1);//注意是a+1 visit[sum]++; update(a+1,1,maxn,1);//注意是a+1 } for(int i=0; i<m; i++) printf("%d\n",visit[i]); } return 0;}
0 0
- hdu 1541 Stars
- hdu 1541 stars
- hdu 1541 Stars
- HDU 1541 Stars
- hdu 1541 Stars
- HDU 1541 Stars
- hdu 1541 Stars
- HDU 1541 Stars
- HDU - 1541 Stars
- hdu 1541 Stars
- HDU 1541 Stars
- HDU 1541 Stars
- HDU 1541 Stars
- hdu 1541 Stars
- hdu 1541 Stars
- hdu 1541 Stars
- HDU -1541-stars
- hdu 1541 Stars
- 二分查找
- 我的C++第四次作业
- commons-digester
- 转载---TCP/IP序列号和确认号详解
- 53. Maximum Subarray
- HDU 1541 Stars
- 在ROS下写Hello ROS!
- hbase等代码中kinit
- POJ 2991 Crane 线段树
- Erlang分布式编程
- Android_Back键再按一次退出程序
- 记录一下mysql的递归。。
- Java8函数式编程实现一个工厂
- activity和service之间的相互通信方法