首页 > 代码库 > HDU4252 A Famous City

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