首页 > 代码库 > 【题解】NOIP201601&02

【题解】NOIP201601&02

NOIP201601

#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>using namespace std;inline int read(){    int x=0,f=1;char ch=getchar();    for(;!isdigit(ch);ch=getchar()) if(ch==-) f=-1;    for(;isdigit(ch);ch=getchar()) x=x*10+ch-0;    return x*f;}int n,ans=1000000;int main(){    n=read();    for(int i=0;i<3;i++)    {        int a=read(),b=read();        if( n % a == 0) ans=min(ans,(n/a)*b);        else ans=min(ans,(n/a+1)*b);    }    printf("%d\n",ans);}

NOIP201602

#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>using namespace std;inline int read(){    int x=0,f=1;char ch=getchar();    for(;!isdigit(ch);ch=getchar()) if(ch==-) f=-1;    for(;isdigit(ch);ch=getchar()) x=x*10+ch-0;    return x*f;}int n,m,a[8],b[8],now,ans;bool rn(int year){    if( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ) return true;    return false;}int main(){    n=read(),m=read();    while(n > 0)    {        a[now++]=n%10;        n/=10;    }    now=0;    while(m > 0 )    {        b[now++]=m%10;        m/=10;    }        for(int i=0;i<4;i++) swap(a[i],a[7-i]),swap(b[i],b[7-i]);        int             nyear=a[0]*1000+a[1]*100+a[2]*10+a[3],        nmonth=a[4]*10+a[5]-1,        nday=a[6]*10+a[7],                myear=b[0]*1000+b[1]*100+b[2]*10+b[3],        mmonth=b[4]*10+b[5]-1,        mday=b[6]*10+b[7],                month[12]={31,0,31,30,31,30,31,31,30,31,30,31};        for(int i=nyear;i<=myear;i++)    {        if( rn(i)) month[1]=29;        else month[1]=28;                int nowy[4],tmp=i;now=0;        while( tmp > 0)        {            nowy[now++]=tmp%10;            tmp/=10;        }        for(int j=0;j<2;j++) swap(nowy[j],nowy[3-j]);                                int             dd=nowy[0]+nowy[1]*10,            mm=nowy[2]+nowy[3]*10-1;                if( dd > month[mm] || dd <= 0 || mm >= 12 || mm < 0 ) continue;                if( i == nyear )        {            if( mm < nmonth || mm > 13 ) continue;            if( dd < nday || dd > month[nmonth] ) continue;        }        else if( i == myear )        {            if( mm > mmonth) continue;            if( dd < nday || dd > month[mmonth] ) continue;        }                ans++;        month[1]=0;    }        printf("%d\n",ans);}

 

【题解】NOIP201601&02