HDU4252 A Famous City

题解:

set

此题关键是理解题意

题意链接:http://blog.csdn.net/luyuncheng/article/details/8053971

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define ll long long
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define ls o<<1
#define rs o<<1|1
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=100100;
const int N=1e9;
const int mod=1e9+7;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

set<int> s;
int n,a;
set<int>::iterator it;

int main(){
    int Kase=1;
    while(~scanf("%d",&n)){
        s.clear();
        int num=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a);
            if(a==0) s.clear();
            else{
                if(!s.count(a)){
                    s.insert(a);
                    num++;
                }
                for(it=s.upper_bound(a);it!=s.end();)s.erase(it++);
            }
        }
        printf("Case %d: %d\n",Kase++,num);
    }
    return 0;
}
时间: 2024-07-28 19:23:08

HDU4252 A Famous City的相关文章

HDOJ 4252 A Famous City 单调栈

单调栈: 维护一个单调栈 A Famous City Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1671    Accepted Submission(s): 644 Problem Description After Mr. B arrived in Warsaw, he was shocked by the skyscrap

HDU 4252 A Famous City

A Famous City Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 425264-bit integer IO format: %I64d      Java class name: Main After Mr. B arrived in Warsaw, he was shocked by the skyscrapers and took several p

A Famous City

                               Time Limit:7000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu After Mr. B arrived in Warsaw, he was shocked by the skyscrapers and took several photos. But now when he looks at these photos, he finds in surpris

单调栈3_水到极致的题 HDOJ4252

A Famous City 题目大意 给出正视图  每一列为楼的高度 最少有几座楼 坑点 楼高度可以为0 代表没有楼 贡献了两发RE 原因 if(!s.empty()&&tem){s.push(tem); continue;}并不能筛去 空栈且 tem为0的情况 改为 if(!s.empty()){if(tem) s.push(tem); continue;} 后AC 题目思路 维护一个单调递增的栈  假如新加入的楼高度小于top元素 那我们知道top元素一定是单独的一栋楼 我们就pop掉

考研英语复试

一.复试中的口试要求 1.评价标准: (1)语言准确性(语法和用词的准确性.语法结构的复杂性.词汇的丰富程度.发音的准确性) (2)话语的长短和连贯性(内容的连贯性.寻找合适词语而造成的停顿频率及长短.表达思想的语言长短等) (3)语言的灵活性和适合性(语言表达是否灵活.自然,话语是否得体,语言能否与语境.动能和目的相适应) 2.口语测试一般包含如下两部分: 第一部分:考查学生理解并回答有关日常生活.家庭.工作.学习等问题的能力(3--5分钟). 第二部分:考查学生连续表达的能力.考生从所给的问

hdu 3624 City Planning(暴力,也可扫描线)

City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 503    Accepted Submission(s): 213 Problem Description After many years, the buildings in HDU has become very old. It need to rebui

HDU 3634 City Planning (离散化)

题意  给你n个矩形  每个矩形都有自己的value  你可以任意改变矩形的表里关系   被覆盖的地方的value取最表层的   求总value的最大值 刚看了扫描线  感觉这个可以用扫描线做就直接写了  其实直接离散化就行了  因为最多也就20个矩形  那坐标最多也就40个  那我们对坐标进行离散化  然后将矩形按value从小到大一个个的放  暴力更新覆盖格子的value  最后直接将2n * 2n个小格子的value加起来就行了 #include <cstdio> #include &l

Textile City Textile World of loss and rebirth

From Zhejiang keqiao " China Textile City" buy, to Zhengzhou to sell, then radiation towards the surrounding provinces , when the enterprise is extremely, really superb cash each day tired . Dengsanlun enable people today shipping laborer , some

City Upgrades

City Upgrades Time limit: 1000 msMemory limit: 128 MB There are N cities placed in a line. For each city ii you know its coodinate x??. You can upgrade exactly K of these cities. Your goal is to choose what cities to upgrade in a way the minimizes th