Ignatius and the Princess IV HDU - 1029 基础dp

Posted qingyuyyyyy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ignatius and the Princess IV HDU - 1029 基础dp相关的知识,希望对你有一定的参考价值。

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
const int N = 1000005;
int a[N];
int main()
{
    int n;
    while(cin>>n&&n)
    {
        int num=0;
        int ans=-1;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(num==0)
            {
                ++num;
                ans=a[i];
            }
            else
            {
                if(ans!=a[i])
                    num--;
                else
                    num++;
            }
        }
        cout<<ans<<endl;
    }
}

 

以上是关于Ignatius and the Princess IV HDU - 1029 基础dp的主要内容,如果未能解决你的问题,请参考以下文章

hdu 1027 Ignatius and the Princess II

hdu1029 Ignatius and the Princess IV

Ignatius and the Princess II(全排列)

Ignatius and the Princess I

hdu 1028 Ignatius and the Princess III

J - Ignatius and the Princess II