POJ-2352-Stars
来源:互联网 发布:河南虫虫网络 编辑:程序博客网 时间:2024/06/05 19:43
这个题要求统计星星的个数,按x的输入进行树状数组更新即可,注意x坐标可能为0的情况,所以对所有x坐标执行加1操作
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=45001;int n,cnt[maxn],t[maxn];int lowbit(int x){ return x&(-x);}int sum(int x){ int ans=0; while(x>0) {ans+=t[x];x-=lowbit(x); } return ans;}void update(int x){ while(x<maxn) {t[x]++;x+=lowbit(x); }}int main(){ while(scanf("%d",&n)!=EOF) {memset(cnt,0,sizeof(cnt));memset(t,0,sizeof(t));for(int i=0;i<n;i++){ int ita,itb; scanf("%d%d",&ita,&itb); ita++; cnt[sum(ita)]++; update(ita);}for(int i=0;i<n;i++) printf("%d\n",cnt[i]); } return 0;}
- POJ 2352 STARS
- POJ 2352 Stars
- Poj 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- POJ 2352 Stars
- POJ 2352 Stars
- POJ-2352-Stars
- POJ 2352 Stars
- Poj 2352 Stars 题解
- poj 2352 stars
- POJ 2352 stars
- POJ 2352 - Stars
- POJ 2352 Stars
- POJ 2352 Stars
- poj 2352 Stars
- poj 2352 Stars
- poj 1611 并查集
- 小米2013年校园招聘笔试题——朋友圈
- Android IM客户端登陆Openfire 之一
- hdu4465 Candy(快速排列组合+概率)
- HDU 1024
- POJ-2352-Stars
- 最受欢迎的8位Java牛人
- 最新县及县以上行政区划代码(截止2013年1月18日) 全国省市县数据库 之县级数据
- 寻找表达式
- 不确定宽度的块级元素的水平居中
- SGU 202 The Towers of Hanoi Revisited (DP+递归)
- Cocos2D-X框架理解
- 图像处理基础知识
- linux下vim中,如何使搜索的关键字高亮