1004

思路:

n为1时,S为“a”(26小写字母),即为26;

n为2时,S为“aa”或“ab”,即为26*26;

n为3时,S为“aaa”或“aab”或“aba”或“abc”,即为26*26*26;

n为4时,S为“abca”,即为26*25*24;

n大于4时,S的后面重复“abc”即可转化为n为4的情况(例如n为5,S为“abcab”即可)。

通过代码:

#include<iostream>

#include<vector>

using namespace std;

 

const vector<int> v{-1, 26, 26*26, 26*26*26, 26*25*24};

 

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0),cout.tie(0);

    int T, n;

    cin>>T;

    while(T--)

    {

        cin>>n;

        cout<<v[min(4,n)]<<"\n";

    }

    return 0;

}

 

1009

思路:

先把robot读入,按照加速度升序排列(加速度相同的,按照初位置升序排列)。经过排列后,如果前面的robot的初位置比后面的要小,则不可能追上后面的(因为后面的加速度大),前面的出栈;如果不是,则按照公式2ax=v^2可以判断。

用map记录x与v重复的robot,然后在最后去重。

通过代码:

#include<iostream>

#include<vector>

#include<algorithm>

#include<map>

using namespace std;

 

typedef long long ll;

typedef pair<ll,ll> pii;

 

vector<pii> g;

vector<ll> st;

 

bool cmp(pii a,pii b)

{

    if(a.second==b.second) return a.first<b.first;

    return a.second<b.second;

}

 

bool func(pii a,pii b,pii c)

{

    return (b.first-c.first)*(b.second-a.second)<=(a.first-b.first)*(c.second-b.second);

}

 

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0),cout.tie(0);

    int T;

    cin>>T;

    while(T--)

    {

        g.clear();

        ll cnt=0,n;

        cin >> n;

        g.resize(n);

        st.resize(n);

        map<pii,int> ma;

        for(ll i=0; i<n; i++)

        {

            cin>>g[i].first>>g[i].second;

            ma[g[i]]++;

        }

        sort(g.begin(),g.end(),cmp);

        st[++cnt]=0;

        for(ll i=1; i<n; i++)

        {

            while(((cnt>0&&g[st[cnt]].first<=g[i].first)||(cnt>1&&func(g[st[cnt-1]],g[st[cnt]],g[i]))))

                cnt--;

            st[++cnt]=i;

        }

        ll res=cnt;

        for(ll i=1; i<=cnt; i++)

        {

            if(ma[g[st[i]]]>1) res--;

        }

        cout<<res<<'\n';

    }

    return 0;

}