HDU1541-star

今天早上郁闷了,有种被骗的感觉,wa了N次,看了别人的解题报告才知道,输入有多组数据。what?输入有多组数据,题目有说明么?

Input
The first line of the input file contains a number of stars N (1<=N<=15000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0<=X,Y<=32000). There can be only one star at one point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate.

明明一开始就input file contains a number of stars N.是不是我太笨了,还是题目表达的不好?

浮云浮云,还是切入正题吧。

又是一道稍显简单的树状数组,题目说给了你N个坐标,题目都帮你排好序了,所以自己不用排,果断把y坐标给忽略掉.直接比较x,比x小的就算进去,最后用另一数组count[]来计算level的数量。

不过一上来,数组就开错,runing error.鸭梨真的好大。

 

#include<stdio.h>  
#include<string.h>  
//#include<iostream>  
#define M 33000  
#define lowbit(x) x&(-x)  
  
struct C  
{  
 int x;  
 int y;  
}coord[M];  
  
int flag[M],count[M];  
  
//using namespace std;  
  
int add(int n)  
{  
 while(n<M)  
 {  
  flag[n]++;  
  n+=lowbit(n);  
 }  
 return 0;  
}  
  
int subsum(int n)  
{  
 int sum=0;  
 while(n>=1)  
 {  
  sum+=flag[n];  
  n-=lowbit(n);  
 }  
 return sum;  
}  
  
int main(void)  
{  
 int n,i;  
 while(scanf("%d",&n)==1)  
 {  
   
  memset(count,0,sizeof(count));  
  memset(flag,0,sizeof(flag));  
  for(i=1;i<=n;i++)  
   scanf("%d%d",&coord[i].x,&coord[i].y);  
  for(i=1;i<=n;i++)  
  {  
   // cout<<subsum(coord[i].x+1)<<"   ";  
   count[subsum(coord[i].x+1)]++;//不同level计数  
   add(coord[i].x+1);//这里的coord[i].x都要加1,因为树状数组总是从1开始计数,而坐标可以是0的  
  }  
  // cout<<endl;  
  for(i=0;i<n;i++)  
   printf("%d\n",count[i]);  
 }  
 return 0;  
}  
 

 

转载于:https://www.cnblogs.com/cchun/archive/2011/04/24/2520093.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值