[Eleven training] Day1 (2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018))

A Altruistic Amphibians

The original title

Title effect:
n-frog the height d of the well, only every jump distance, weight and height, by means of each frog can jump back and out of the other frogs wells, each frog can withstand the maximum weight of its own weight , find the maximum number of frogs were able to go.

Solution:
Because the frog is able to withstand the weight of its own weight or less, it can not rely on heavy frog frog the light wells. Therefore, in accordance with the frog in descending order by weight, each frog can only rely on the top-ranked frog, the problem will be converted into 01 backpacks. DP [i] [j] denotes the maximum height of the i-th arrival frog weight j, namely transfer equation dp [i] [j] = max (dp [i-1] [j], dp [i-1 ] [min (j + a [ i] .w, 1e8)]).

Code:

#include<cstdio>
#include<algorithm>
#define N 100010
#define M 100000010
using namespace std;
int n,d,ans,dp[M];
struct hhh
{
    int l,w,h;
    bool operator < (const hhh &b) const
    {
        return w>b.w;
    }
}a[N];

int read()
{
    int ans=0,op=1;
    char c=getchar();
    for (;(c<'0' || c>'9') && c!='-';c=getchar()) ;
    if (c=='-') c=getchar(),op=-1;
    for (;c>='0' && c<='9';c=getchar()) ans*=10,ans+=c^48;
    return ans*op; 
}

int main()
{
    n=read();d=read();
    for (int i=1;i<=n;i++)
    {
        a[i].l=read();
        a[i].w=read();
        a[i].h=read();
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)
    {
        if (dp[a[i].w]+a[i].l>d) ans++;
        for (int j=1;j<a[i].w;j++)
            dp[j]=max(dp[j],dp[min(j+a[i].w,M-1)]+a[i].h);
    }
    printf("%d\n",ans);
    return 0;
}

B Baby Bites

The original title

Sign problem

#include<cstdio>
#include<cstring>
using namespace std;
int n,ANS=1,t;
char s[10];

int read()
{
    int ans=0,op=1;
    char c=getchar();
    for (;(c<'0' || c>'9') && c!='-';c=getchar()) ;
    if (c=='-') op=-1,c=getchar();
    for (;c>='0' && c<='9';c=getchar()) ans*=10,ans+=c^48;
    return ans*op;
}

bool isnumber()
{
    if (s[1]>='0' && s[1]<='9') return 1;
    return 0;
}

int change()
{
    int ans=0,l;
    l=strlen(s+1);
    for (int i=1;i<=l;i++)
        ans*=10,ans+=s[i]^48;
    return ans;
}

int main()
{
    n=read();
    for (int i=1,j;i<=n;i++)
    {
        ++t;
        scanf("%s",s+1);
        if (isnumber())
        {
            j=change();
            ANS&=(j==t);
        }
    }
    if (ANS) printf("makes sense");
    else printf("something is fishy");
    return 0;
}

C Code Cleanups

The original title

Subject to the effect:
the n-th date within a given year, each date will be put in a garbage, have a dirty value that increases every day, you need a total value of less than 20 dirty to clean up equal (only clean up the clean-up before, do not clean up day). At the end of the last day and must be clean. Q. least clean up a few times.

Solution:
violence Enumeration

#include<cstdio>
#define N 400
using namespace std;
int n,d,a[N],l=1,r=1,now,ans;
//[l,r)
 
int read()
{
    int ans=0,op=1;
    char c=getchar();
    for (;(c<'0' || c>'9') && c!='-';c=getchar()) ;
    if (c=='-') op=-1,c=getchar();
    for (;c>='0' && c<='9';c=getchar()) ans*=10,ans+=c^48;
    return ans*op;
}

int main()
{
    n=read();
    for (int i=1;i<=n;i++) a[i]=read();
    for (int i=1;i<=365;i++)
    {
        if (a[r]==i) r++;
        if (now+r-l>=20) ans++,now=0,l=r;
        else now+=r-l;
    }
    if (now) ans++;
    printf("%d\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/mrha/p/11621861.html