8.9 Day6

2018.8.9 Test

时间:2.5h(实际)
期望得分:60+30+0
实际得分:40+30+0

比赛链接

待改

为什么A死活40分。。这个咋就能150+ms过呢。。http://www.zhengruioi.com/submission/26647

A

题目链接

B

题目链接

C

题目链接

考试代码

A

#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define gc() getchar()
typedef long long LL;
const int N=17,M=205;

int n,lim,K,Atk,Def,Mdf,dgr[N],Enum,H[N],nxt[M],to[M];
LL Hp,Ans,mx[(1<<15)+2];
struct Monster
{
    int H,A,D,S,ap,dp,mp,hp;
}A[N];

inline int read()
{
    int now=0;register char c=gc();
    for(;!isdigit(c);c=gc());
    for(;isdigit(c);now=now*10+c-'0',c=gc());
    return now;
}
inline void AddEdge(int v,int u){
    ++dgr[v], to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
}
inline bool Can(int x,int s)
{
    for(int i=H[x]; i; i=nxt[i]) if(!((s>>to[i]-1)&1)) return 0;
    return 1;
}
inline LL Kill(Monster mon,LL hp,int atk,int def,int mdf)
{
    if(mon.S>>3&1) mon.A=atk, mon.D=def;
    if(mon.S>>1&1) def=0;
    if(atk<=mon.D) return 0ll;

    int dps=atk-mon.D, mon_dps=mon.A<=def?0:mon.A-def;
    int tm=(mon.S>>2&1)?2:1;
    LL hpbef=hp; hp+=mdf;
    if(mon.S&1) hp-=mon_dps*tm;

    hp-=1ll*mon_dps*tm*((mon.H+dps-1)/dps-1);
    return hp>hpbef?hpbef:hp;
}
void DFS(int s,LL hp,int atk,int def,int mdf)
{
    if(mx[s]>=hp) return;
    if(s==lim) {mx[s]=hp, Ans=std::max(Ans,hp); return;}

    LL tmp=hp;
    for(int i=0; i<n; ++i) if(!(s>>i&1)) tmp+=A[i+1].hp;
    if(tmp<=mx[s]) return;

    for(int i=n; i; --i)
        if(!((s>>i-1)&1) && !dgr[i] && (tmp=Kill(A[i],hp,atk,def,mdf))>0)
        {
            for(int j=H[i]; j; j=nxt[j]) --dgr[to[j]];
            DFS(s|(1<<i-1),tmp+A[i].hp,atk+A[i].ap,def+A[i].dp,mdf+A[i].mp);
            for(int j=H[i]; j; j=nxt[j]) ++dgr[to[j]];
        }
}

int main()
{
//  freopen("A.in","r",stdin);
//  freopen(".out","w",stdout);

    for(int T=read(); T--; )
    {
        Ans=-1ll, Enum=1, memset(H,0,sizeof H), memset(mx,0,sizeof mx), memset(dgr,0,sizeof dgr);
        Hp=read(), Atk=read(), Def=read(), Mdf=read();
        n=read(), lim=(1<<n)-1;
        for(int i=1; i<=n; ++i) A[i]=(Monster){read(),read(),read(),read(),read(),read(),read(),read()};
        K=read();
        for(int i=1; i<=K; ++i) AddEdge(read(),read());
        DFS(0,Hp,Atk,Def,Mdf);
        printf("%lld\n",Ans);
    }
    return 0;
}

B

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
typedef long long LL;
const int N=101;

int n,m,c;
LL Ans;
struct Event
{
    int l,r,x,y;
}A[N];

inline int read()
{
    int now=0;register char c=gc();
    for(;!isdigit(c);c=gc());
    for(;isdigit(c);now=now*10+c-'0',c=gc());
    return now;
}
void DFS(int now,int rest,LL w)
{
    if(!rest||now>n) {Ans=std::max(Ans,w); return;}
    int X[6]; LL tmp;
    for(int i=1; i<=m; ++i) X[i]=A[i].x;
    DFS(now+1,rest,w);
    for(int x=1; x<=rest; ++x)
    {
        tmp=0;
        for(int i=1; i<=m; ++i)
            if(A[i].l<=now&&A[i].r>=now&&A[i].x>0)
                tmp+=std::min(A[i].x,x)*A[i].y, A[i].x-=x;
        DFS(now+1,rest-x,w+tmp);
        for(int i=1; i<=m; ++i) A[i].x=X[i];
    }
}
void DFS2(int now,int rest,LL w)
{
    if(!rest||now>n) {Ans=std::max(Ans,w); return;}
    int X[N]; LL tmp;
    for(int i=1; i<=m; ++i) X[i]=A[i].x;
    DFS2(now+1,rest,w);
    for(int x=1; x<=rest; ++x)
    {
        tmp=0;
        for(int i=1; i<=m; ++i)
            if(A[i].l<=now&&A[i].r>=now&&A[i].x>0)
                tmp+=std::min(A[i].x,x)*A[i].y, A[i].x-=x;
        DFS2(now+1,rest-x,w+tmp);
        for(int i=1; i<=m; ++i) A[i].x=X[i];
    }
}

int main()
{
//  freopen("B2.in","r",stdin);
//  freopen(".out","w",stdout);

    n=read(), m=read(), c=read();
    for(int i=1; i<=m; ++i) A[i]=(Event){read(),read(),read(),read()};
    if(n<=5) DFS(1,c,0);
    else DFS2(1,c,0);
    printf("%lld\n",Ans);

    return 0;
}

C

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define INF (1e6)
#define mod (1000000007)
typedef long long LL;
const int N=12;

int n,Sum,p[N],Q,c[N],have[N],Max,tot;

struct Fraction
{
    LL x,y;
    Fraction() {x=0, y=1;}
    Fraction(LL x,LL y):x(x),y(y) {}

    void Debug() {printf("%lld/%lld\n",x,y);}
    LL Gcd(LL x,LL y) {return y?Gcd(y,x%y):x;}
    inline void Fix() {LL g=Gcd(x,y); x/=g,y/=g;}
    void Exgcd(LL a,LL b,LL &x,LL &y)
    {
        if(!b) x=1, y=0;
        else Exgcd(b,a%b,y,x), y-=a/b*x;
    }
    void Output()
    {
        if(y==1) {printf("%lld\n",x); return;}
        LL inv,b;
        Exgcd(y,mod,inv,b);
        printf("%lld\n",inv*x%mod);
    }
    friend bool operator <(const Fraction &f,const Fraction &g)
    {
        return f.x*g.y<g.x*f.y;
    }
    friend Fraction operator +(const Fraction &f,int num)
    {
        Fraction res=Fraction(f.x+f.y*num,f.y);
        res.Fix();
        return res;
    }
    friend Fraction operator +(const Fraction &f,const Fraction &g)
    {
        Fraction res=Fraction(f.x*g.y+g.x*f.y,f.y*g.y);
        res.Fix();
        return res;
    }
    friend Fraction operator *(const Fraction &f,int num)
    {
        Fraction res=Fraction(f.x*num,f.y);
        res.Fix();
        return res;
    }
    friend Fraction operator *(const Fraction &f,const Fraction &g)
    {
        Fraction res=Fraction(f.x*g.x,f.y*g.y);
        res.Fix();
        return res;
    }
}Ans,f[1000003];

inline int read()
{
    int now=0;register char c=gc();
    for(;!isdigit(c);c=gc());
    for(;isdigit(c);now=now*10+c-'0',c=gc());
    return now;
}
inline LL FP(LL x,int k)
{
    LL t=1;
    for(; k; k>>=1, x=x*x%mod)
        if(k&1) t=t*x%mod;
    return t;
}
bool Check(int now,Fraction res)
{
    int rest=0;
    for(int i=1; i<=n; ++i)
        if(have[i]>=c[i]) rest+=have[i]-c[i];
    for(int i=1; i<=n; ++i)
        if(have[i]<c[i])
            if(rest>=4*(c[i]-have[i])) rest-=(c[i]-have[i]<<2);
            else return 0;
    if(rest) return 1;
    putchar('\n'); Ans.Debug();puts("+=");res.Debug();
    printf("Number: "); for(int i=1; i<=n; ++i) printf("%d ",have[i]); putchar('\n');putchar('\n');
    Ans=Ans+res, ++tot;
    return 1;
}
void DFS(int now,Fraction res)
{
//  printf("now:%d ",now), res.Debug();
    if(Check(now,res)||now>n) return;
    int mx=(Sum-c[now])*4+c[now];
//  printf("mx:%d\n",mx);
    Fraction tmp=Fraction(Q,p[now]);
    for(int i=0; i<=mx; ++i)
        have[now]=i, printf("%d Chose %d:",now,i), (tmp*i).Debug(), DFS(now+1,std::max(tmp*i,res)), have[now]=0;
}

int main()
{
    freopen("C1.in","r",stdin);
//  freopen(".out","w",stdout);

    n=read();
    for(int i=1; i<=n; ++i) Q+=(p[i]=read());
    for(int i=1; i<=n; ++i) Sum+=(c[i]=read());
    DFS(1,Fraction(0,1));
    (Ans*Fraction(1,tot)).Output();

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/SovietPower/p/9448244.html
8.9