zoj 3519 Who is the Smartest Man

zoj 3519 Who is the Smartest Man


曹操如果打败一个智育比自己高的人,则曹操的智育+2,否则+1。 如果曹操按任意顺序打败对手,曹操最终智育最高是多少?


贪心,分为两类一个是智育比当前分数高的,令一类是第的;如果是第二类的话,那么直接每个对手只能+1,在第一类中贪心的选择比自己智育高的最小的那个人

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<set>

using namespace std;

multiset<int> st;
multiset<int>::iterator it;

int main()
{
    int n,ip,a;
    while(scanf("%d%d",&n,&ip)==2)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            st.insert(a);
        }
        while(!st.empty())
        {
            it=st.upper_bound(ip);
            if(it==st.end()) break;
            st.erase(it);
            ip+=2;
        }
        ip+=st.size();
        printf("%d\n",ip);
        st.clear();
    }
    return 0;
}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;
int p[510];

int main()
{
    int n,ip;
    while(scanf("%d%d",&n,&ip)==2)
    {
        for(int i=0;i<n;i++) scanf("%d",&p[i]);
        sort(p,p+n);
        int last=0;
        for(int i=0;i<n;i++)
        {
            if(p[i]>ip) ip+=2;
            else last++;
        }
        printf("%d\n",ip+last);
    }
    return 0;
}



你可能感兴趣的:(zoj 3519 Who is the Smartest Man)