zoukankan      html  css  js  c++  java
  • 弱鸡儿长乐爆零旅Day1

    T1魔法照片

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    struct rec{
        int num;
        int d;
    }a[50100];
    int e[20];
    bool cmp(const rec x,const rec y)
    {
        return x.d==y.d?x.num<y.num: x.d>y.d;
    }
    int main()
    {
        //freopen("mphone.in","r",stdin);
        //freopen("mphone.out","w",stdout);
        int n,k;
        scanf("%d %d",&n,&k);
        for(int i=1;i<=10;i++)
            scanf("%d",&e[i]);
        
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].d);
            a[i].num=i;
        }
        sort(a+1,a+1+n,cmp);
        for(int i=1;i<=n;i++)
        {
            a[i].d+=e[(i-1)%10+1];
        }
        sort(a+1,a+1+n,cmp);
        for(int i=1;i<=k;i++)
            printf("%d ",a[i].num);
        return 0;
    }

     T2  个人所得税

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<string>
    #include<cstring>
    using namespace std;
    double ans=0;
    struct rec{
        int mon[13];
    }a[50002];
    void tax1(double x)
    {
        if(x<0)
            return ;
        else if(x<=500)
        {
            ans+=(x*0.05);return ;
        }
        else if(x<=2000)
        {
            ans+=25+(x-500)*0.1;return ;
        }
        else if(x<=5000)
        {
            ans+=25+150+(x-2000)*0.15;return ;
        }
        else if(x<=20000)
        {
            ans+=25+150+450+(x-5000)*0.20;return ;
        }
        else if(x<=40000)
        {
            ans+=25+150+450+3000+(x-20000)*0.25;return ;
        }
        else if(x<=60000)
        {
            ans+=25+150+450+3000+5000+(x-40000)*0.3;return ;
        }
        else if(x<=80000)
        {
            ans+=25+150+450+3000+5000+6000+(x-60000)*0.35;return ;
        }
        else if(x<=100000)
        {
            ans+=25+150+450+3000+5000+6000+7000+(x-80000)*0.4;return ;
        }
        else if(x>100000)
        {
            ans+=25+150+450+3000+5000+6000+7000+8000+(x-100000)*0.45;return ;
        }
    }
    void tax2(double x)
    {
        if(x<0)
            return ;
        else if(x<=20000)
        {
            ans+=x*0.2;
            return ;
        }
        else if(x<=50000)
        {
            ans+=4000+(x-20000)*0.3;
            return ;
        }
        else if(x>50000)
        {
            ans+=4000+9000+(x-50000)*0.4;
            return ;
        }
    }
    int main()
    {
        freopen("tax.in","r",stdin);
        freopen("tax.out","w",stdout);
        string s1,s2;
        int num;
        double mon;
        int n;
        scanf("%d",&n);
        while(cin>>s1&&s1[0]!='#')
        {
            scanf("%d",&num);
            cin>>s2;
            scanf("%lf",&mon);
            int m=0;
            //cout<<s1[0]<<" a"<<endl;
            if(s1[0]=='P')
            {
                for(int i=0;i<=s2.length();i++)
                {
                    if(s2[i]=='/')
                        break;
                    m=m*10+s2[i]-'0';
                }
                a[num].mon[m]+=mon;
            }
                
            else if(s1[0]=='I')
            {
                if(mon<=4000)
                {
                    mon-=800;
                }
                else 
                    mon=mon*0.8;
                tax2(mon);
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=12;j++)
            {
                tax1(a[i].mon[j]-800);
            }
        }
        printf("%.2lf",ans);
    }

     注意事项:第一种税收按月份算 记得当月的要累加(拿到题目一定要仔细读题分析数据qaq)

    T3  最大子段和

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #define ll long long
    using namespace std;
    const ll INF=0x3f3f3f3f3f3f3f3f,N=100005; 
    ll n,a[N],Left[N],Right[N],sum1[N],sum2[N];
    //sum用来计算前缀和、后缀和
    int main()
    {
        ll ans1=-INF,ans2=-INF,tot=0;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            tot+=a[i];
            ans1=max(ans1,tot);
            if(tot<0)
                tot=0;
        }
        memset(Left,0xcf,sizeof(Left));
        memset(Right,0xcf,sizeof(Right));
        for(int i=1;i<=n;i++)//计算前缀和 更新左子串最大值 
        {
            sum1[i]=sum1[i-1]+a[i];
            Left[i]=max(Left[i-1],sum1[i]);
        }
        for(int i=n;i>=1;i--) //计算后缀和 更新右子串最大值 
        {
            sum2[i]=sum2[i+1]+a[i];
            Right[i]=max(Right[i+1],sum2[i]);
        }
        for(int i=1;i<n;i++)//枚举断点
        {
            ans2=max(ans2,Left[i]+Right[i+1]);
        }
        printf("%lld",max(ans1,ans2));
        return 0;
    }

     T4 最小差值生成树

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    struct rec{
        int x,y,z;
    }edge[5050];
    int n,m,fa[210],ans=0x7f7f7f7f;
    void clear()
    {
        for(int i=1;i<=n;i++)
            fa[i]=i;
    }
    int get(int x)
    {
        return fa[x]==x?x:fa[x]=get(fa[x]);
    }
    bool cmp(const rec &x,const rec &y)
    {
        return x.z<y.z;
    }
    void calc()
    {
        for(int i=1;i<=m;i++)
        {
            int Max=edge[i].z;
            int cnt=1;
            clear();
            fa[edge[i].x]=edge[i].y;
            for(int j=i+1;j<=m;j++)
            {
                int f1=get(edge[j].x),f2=get(edge[j].y);
                if(f1==f2)
                    continue;
                else{
                    fa[f1]=f2;
                    cnt++;
                    Max=max(Max,edge[j].z);
                }
                if(cnt==n-1)//一棵n个节点的树有n-1条边
                {
                    break;
                }
            }
            if(cnt==n-1)
            {
                ans=min(ans,Max-edge[i].z);
            }
                
        }
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++)
        {
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            edge[i].x=x,edge[i].y=y,edge[i].z=z;
        }
        sort(edge+1,edge+1+m,cmp);//先按边的长度从小到大排列
        calc(); 
        printf("%d",ans);
        return 0;
    }

    友链 https://www.luogu.org/blog/zbwer/post-2019-boom-1

  • 相关阅读:
    c++——类 继承
    Pytorch Tensor, Variable, 自动求导
    Python-OpenCV实现二值图像孔洞填充
    神经网络手写数字识别numpy实现
    神经网络反向传播公式推导
    转:Markdown语法大全
    markdown居中对齐,左对齐,右对齐
    硬编码与软编码
    转:Markdown数学公式语法
    Python if __name__=='__main__'
  • 原文地址:https://www.cnblogs.com/WJill/p/11228046.html
Copyright © 2011-2022 走看看