• 7.24每日总结《我能怎么办我也很绝望啊》


    今天又被布置了三道题。
    100342D 100342F 100342G
    只做了100342D,高精度居然还能写错。。。然而还没调对。。。
    这题就是高精度+简单dp
    错误代码,仅作记录。。。

    using namespace std;
    const int maxn=410;
    struct bign
    {
        int siz,s[maxn],f;
        bign ()
        {memset(s, 0, sizeof(s));siz=1;}
        bign (int num)
        { *this = num; }
        bign (const char *num)
        { *this = num; }
        bign operator = (const char *num)
        {
            siz=int(strlen(num));
            for(int i=0;num[i]=='0';num++);
            for(int i=0;i<siz;i++)
            {
                s[i]=num[siz-i-1]-'0';
            }
            return *this;
        }
        bign operator = (const int num)
        {
            char s[maxn];
            sprintf(s,"%d",num);
            *this=s;
            return *this;
        }
        bool operator < (const bign &b)
        {
            if(siz!=b.siz)
                return siz<b.siz;
            for(int i=siz-1;i>=0;i--)
            {
                if(s[i]!=b.s[i])
                    return s[i]<b.s[i];
            }
            return false;
        }
        bool operator > (const bign &b)
        {
            if(siz!=b.siz)
                return siz>b.siz;
            for(int i=siz-1;i>=0;i--)
            {
                if(s[i]!=b.s[i])
                    return s[i]>b.s[i];
            }
            return false;
        }
        bool operator == (const bign num)
        {
            return !(*this>num) && !(*this<num);
        }
        bool operator != (const bign num)
        {
            return !(*this==num);
        }
        bign operator + (const bign &b)
        {
            bign c;
            c.siz=0;
            int j=0;
            for(int i=0;(j || i<max(siz,b.siz));i++)
            {
                int x=j;
                if(i<siz)
                    x+=s[i];
                if(i<b.siz)
                    x+=b.s[i];
                c.s[c.siz++]=x%10;
                j=x/10;
            }
            return c;
        }
        bign operator * (const bign &b)
        {
            bign c;
            c.siz=siz+b.siz;
            for(int i=0;i<siz;i++)
            {
                for(int j=0;j<b.siz;j++)
                {
                    c.s[i+j]+=s[i]*b.s[j];
                }
            }
            for(int i=0;i<c.siz;i++)
            {
                c.s[i+1]+=c.s[i]/10;
                c.s[i]%=10;
            }
            return c;
        }
        void begi()
        {
            f=-1;
        }
        void str()
        {
            for(int i=0;i<siz;i++)
                cout<<s[i];
            cout<<endl;
        }
    };
    bign dp[105][105];
    int n,k;
    bign dfs(int i,int j)
    {
        if(dp[i][j]!=-1)
            return dp[i][j];
        else
        if(i>j)
        {
            dp[i][j]=0;
            return 0;
        }
        else
        {
            if(i==0 && j==0)
            {
                dp[i][j]=1;
                return 1;
            }
            else
            {
                if(i==0)
                {
                    dp[i][j]=dfs(i,j-1)*k;
                    return dp[i][j];
                }
                else
                {
                    dp[i][j]=dfs(i-1,j-1)*i+dfs(i,j-1)*(k-i);
                    return dp[i][j];
                }
            }
        }
    }
    int main()
    {
        cin>>n>>k;
        for(int i=0;i<=100;i++)
            for(int j=0;j<=100;j++)
                dp[i][j]=-1;
        dp[0][0]=1;
        bign ans=dfs(k,n);
        ans.str();
        return 0;
    }

    然后是昨天atcoder grand contest018的b,a的话已经对了,然而b还没有改对,这题是个“感性”的贪心,就是要做到每一步操作都是最优的。依旧是错误代码。。。

    using namespace std;
    int n,m,tot;
    int a[305][305];
    int ma[305];
    bool f=1;
    bool used[305];
    vector<pair<int,bool> > tr;
    int main()
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cin>>a[i][j];
            }
        }
        int sum=0,spo=0;
        for(int i=1;i<=n;i++)
        {
            ma[a[i][1]]++;
        }
        for(int i=1;i<=m;i++)
        {
            if(ma[i]>0)
                tr.pb(mp(i,0));
            if(sum<ma[i])
            {
                sum=ma[i];
                spo=i;
            }
        }
        int i=spo;
        //cout<<"-------"<<endl;
        //cout<<spo<<":"<<sum<<endl;
        //cout<<"-------"<<endl;
        while(f)
            for(int p=0;p<tr.size();p++)
            {
                memset(ma,0,sizeof(ma));
                tr[p].se=1;
                tot++;
                used[i]=1;
                for(int k=1;k<=n;k++)
                {
                    for(int j=1;j<=m;j++)
                    {
                        if(!used[a[k][j]])
                        {
                            ma[a[k][j]]++;
                            break;
                        }
                    }
                }
                used[i]=0;
                int sum1=0,spo1=0;
                //cout<<"-------"<<endl;
                vector<pair<int,bool> > tr1;
                for(int j=1;j<=m;j++)
                {
                    if(ma[j]>0)
                        tr1.pb(mp(j,0));
                    if(sum1<ma[j])
                    {
                        sum1=ma[j];
                        spo1=j;
                    }
                    //cout<<ma[j]<<" ";
                }
                //cout<<endl;
                //cout<<"-------"<<endl;
                //cout<<spo1<<":"<<sum1<<endl;
                if(sum1<=sum && !used[spo1])
                {
                    used[spo]=1;
                    sum=sum1;
                    spo=spo1;
                    i=spo;
                    tr=tr1;
                    //cout<<"-------"<<endl;
                    //cout<<spo<<":"<<sum<<endl;
                }
                else
                {
                    if(tot<tr.size())
                        i=tr[tot+1].fi;
                }
                if(tot==tr.size())
                {
                    f=false;
                }
            }
        cout<<sum<<endl;
        return 0;
    }

    还有一道是85d,这题一直超时,打算看一下题解再写,就不贴代码了。。。

  • 相关阅读:
    Zabbix监控MySQL免密码设置
    NFS文件服务器搭建
    Glufster挂载失败Mount failed. Please check the log file for more details解决办法
    CentOS和Redhat救援模式
    CentOS和Redhat单用户模式
    EXSI中Linux安装tools
    Redhat7.5安装glusterfs4
    思科交换机根据mac地址限制主机
    怎么关闭win10防火墙
    [0] WCF开发下,提示HTTP 无法注册 URL 进程不具有此命名空间的访问权限
  • 原文地址:https://www.cnblogs.com/NightRaven/p/9333249.html
Copyright © 2020-2023  润新知