HDU4252 A Famous City

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

 

以上是关于HDU4252 A Famous City的主要内容,如果未能解决你的问题,请参考以下文章

hdu4252

HDU 4256 The Famous Clock

HDU4251-The Famous ICPC Team Again(划分树)

POJ2092 LA3157 HDU1347 ZOJ2250 Grandpa is Famous排序

HDU 4849-Wow! Such City!(最短路)

HDU 4464 Browsing History(最大ASCII的和)