• HDU1541star


    今天早上郁闷了,有种被骗的感觉,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;  
    }  
     

     

  • 相关阅读:
    计算相邻字段 四至
    eclipse+terminal
    10 行 Python 代码实现模糊查询/智能提示
    Sublime Text 3,有了Anaconda就会如虎添翼
    Visual Studio上开发Python六大功能
    11 Python Libraries You Might Not Know
    linux安装PyCharm,PyCharm常用快捷键及调试模式,pycharm里面对文件夹或者文件进行重命名
    mysql mac客户端: sequel,mysql-workbench
    ImageMagick convert多张照片JPG转成pdf格式,pdfunite合并PDF文件
    互联网金融ABS为何遭遇急刹车?
  • 原文地址:https://www.cnblogs.com/cchun/p/2520093.html
Copyright © 2020-2023  润新知