zoukankan      html  css  js  c++  java
  • 贪心好题——poj3044

    题意:

    给你一个建筑物群的轮廓,求该建筑物群最少由几栋楼房组成(楼房是矩形)

    思路:贪心

    一看数据范围怎么大,搜索神马的就算了

    从后往前扫,将符合的都标记掉(注意高度为0的没有楼房)

    View Code
    #include<stdio.h>
    #include<string.h>
    const int N=50009;

    struct data
    {
    int x,y;
    }s[N];
    bool used[N];

    int main()
    {
    int n,w;
    while(scanf("%d%d",&n,&w)!=EOF)
    {
    int i,j;
    for(i=1;i<=n;i++)
    {
    scanf("%d%d",&s[i].x,&s[i].y);
    used[i]=0;
    }

    int add=0;
    for(i=n;i>=1;i--)
    {
    if(s[i].y==0)continue;
    if(used[i]==1)continue;

    for(j=i-1;j>=1;j--)
    {
    if(s[i].y<=s[j].y)
    {
    if(s[i].y==s[j].y)
    used[j]=1;
    }
    else{
    break;
    }
    }
    add++;
    }

    printf("%d\n",add);
    }
    }



  • 相关阅读:
    作业十一
    作业十
    作业九
    作业八
    作业七
    作业六
    作业五
    作业四
    eclipse+maven+web服务,实现对hdfs的目录浏览展示
    Eclipse+hadoop伪态式分布+API
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2272216.html
Copyright © 2011-2022 走看看