题目网址链接:https://ac.nowcoder.com/acm/contest/1107#question

A.Easy h-index

题意:

仔细阅读题目,题目意思是给个数组ai,求最大的h,使得至少有h个数大于等于h,输出最大的h

solution:

从后枚举i


F.Sorting

题意:

给出n个a b c,让你排序,遵循(a+b/a+b+c)小的在前,下标小的在前

solution:

排序或者优先队列,cmp一下(c*(a+b+c))的大小,因为是16 * 1e18< unsigned long long 2^64(18446744073709551615)

#include <bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
const int maxx = 1005;
struct node{
    ll a,b,c;
    int i;
    friend bool operator <(node p1,node p2){
        if((p1.c)*(p2.a+p2.b+p2.c) == (p1.a+p1.b+p1.c)*(p2.c))
            return p1.i > p2.i;
        return (p1.c)*(p2.a+p2.b+p2.c) < (p1.a+p1.b+p1.c)*(p2.c) ;
    }
};
priority_queue<node> q;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q.empty())
            q.pop();
        for(int i=1;i<=n;i++)
        {
            node now;
            cin>>now.a>>now.b>>now.c;
            now.i = i;
            q.push(now);
        }
        node now = q.top();
        q.pop();
        cout<<now.i;
        while(!q.empty()){
            node now = q.top();
            q.pop();
            cout<<" "<<now.i;
        }
        cout<<endl;
    }
    return 0;
}

G:

题意:

给你俩个字符串s和t,问你是否能将s增加,删除字符得到t,可以删除或者增加(aa,bb,abab)

solution:

我们可以发现可以将ab变成ba(ab-> abaa -> ababba -> ba).那么我们只需要记录每个相隔c之间的a和b的个数,如果相差a或者b的个数是奇数,那么肯定不能,如果c的个数不相同,也肯定不行

#include <bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
char s1[10005],s2[10005];
int main()
{
    while(~scanf("%s %s",s1,s2))
    {
        int len1 = strlen(s1),len2 = strlen(s2);
        int l1 = 0,l2 = 0,flag = 0,c1 = 0, c2 = 0;
        s1[len1] = 'c',s2[len2] = 'c';
        s1[len1+1] = '\0',s2[len2+1] = '\0';
        len1++,len2++;

        //cout<<len1<<" "<<len2<<endl;
        while(l1 < len1 && l2 < len2)
        {
            int a = 0 ,b = 0;
            while(s1[l1] != 'c' && l1 < len1){
                if(s1[l1] == 'a') a++;
                if(s1[l1] == 'b') b++;
                l1++;
            }
            if(s1[l1] != '\0')
                l1++;
            while(s2[l2] != 'c' && l2 < len2){
                if(s2[l2] == 'a') a++;
                if(s2[l2] == 'b') b++;
                l2++;
            }
            if(s2[l2] != '\0')
                l2++;
            if(a%2 != 0 || b%2 !=0 ){
                flag = 1;
                break;
            }
        }
        if(l1 != len1 || l2 != len2 || flag){
            printf("No\n");
            continue ;
        }
        printf("Yes\n");
    }
    return 0;
}

K.2018

题意:

给出区间[a,b] , [c,d]询问你总共有多少对(x,y)满足 a<=x<=b ,c<=y<=d且x*y = 2018

solution:

2018的因子只有1,2,1009,2018,所以我们可以4*4枚举答案,记得容斥

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans[10];
int main()
{
    ll a,b,c,d;
    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d))
    {
        ll cnt = 0;
        ans[1] = (b/2018) - ((a-1)/2018);//2018倍数
        ans[2] = ((b/1009)-((a-1)/1009)-ans[1]);//1009倍数
        ans[3] = ((b/2) - ((a-1)/2) - ans[1]);//2的倍数
        ans[4] = (b-a+1 - ans[1] - ans[2] - ans[3]);//其他

        ans[5] = d-c+1;//1的倍数
        ans[6] = (d/2 - (c-1)/2);//2的倍数
        ans[7] = (d/1009 - (c-1)/1009);//1009的倍数
        ans[8] = (d/2018 - (c-1)/2018);//2018的倍数
        for(int i=1;i<=4;i++){
            cnt += 1ll*ans[i]*ans[i+4];
        }
        cout<<cnt<<endl;
    }
    return 0;
}