zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62

    A Irrational problem

    题意

    f(x) = x mod p1 mod p2 mod p3 mod p4

    问你[a,b]中有多少个数满足f(x)=x

    题解

    显然直接带进去就好了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int p1,p2,p3,p4,a,b;
        scanf("%d%d%d%d%d%d",&p1,&p2,&p3,&p4,&a,&b);
        int ans = 0;
        for(int i=a;i<=b;i++){
            if(i%p1%p2%p3%p4==i)
                ans++;
        }
        cout<<ans<<endl;
    }
    

    B - Energy exchange

    题意

    你可以把能量从一个位置转移到另外一个位置,但会损失k%能量。

    你想要所有最后的能量都是一样的,问你是多少

    题解

    二分答案就好了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e4+7;
    int n,k;
    double a[maxn];
    int main()
    {
        scanf("%d%d",&n,&k);
        for(int i=0;i<n;i++)
            scanf("%lf",&a[i]);
        double l=0,r=1e6;
        for(int i=0;i<100;i++){
            double mid=(l+r)/2.0;
            double s = 0;
            for(int j=0;j<n;j++){
                if(a[j]>mid){
                    s+=1.0*(100-k)*(a[j]-mid)/100.0;
                }else{
                    s-=(mid-a[j]);
                }
            }
            if(s<0)r=mid;
            else l=mid;
        }
        printf("%.12f
    ",l);
    }
    

    C. Synchrophasotron

    题意

    给你一些管道,必须从小的管道流到大的管道,且如果流过flow的流量的话,那么代价就是a[i]+flow^2

    每个管道还有最少流量和最大流量限制。

    现在问你一开始1号管道最少有多少水,才能使得所有水都到达n点,且最大的花费是多少

    题解

    直接暴力dfs就好了,暴力枚举最小值,然后dfs去check,暴力枚举每个水管通过多少的水。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 15;
    int l[maxn][maxn],h[maxn][maxn],a[maxn][maxn];
    int flow[maxn],n,Max,Min;
    void dfs(int x,int y,int cost){
        if(x==n){
            Max = max(cost,Max);
            return;
        }
        if(y>n){
            if(flow[x]==0)dfs(x+1,x+2,cost);
            return;
        }
        for(int i=l[x][y];i<=h[x][y];i++){
            if(flow[x]<i)return;
            int ncost = cost;
            if(i!=0)ncost+=a[x][y]+i*i;
            flow[x]-=i;flow[y]+=i;
            dfs(x,y+1,ncost);
            flow[x]+=i;flow[y]-=i;
        }
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++){
            int A,B;scanf("%d%d",&A,&B);
            scanf("%d%d%d",&l[A][B],&h[A][B],&a[A][B]);
        }
        Max = -1,Min = -1;
        for(Min=0;Min<=26;Min++){
            flow[1]=Min;
            dfs(1,2,0);
            if(Max!=-1)break;
        }
        if(Max==-1)cout<<"-1 -1"<<endl;
        else cout<<Min<<" "<<Max<<endl;
    }
    

    D. Half-decay tree

    题意

    给你一个完全二叉树,一共两种操作,第一种操作是使得某个节点的电荷增加k

    第二种操作是随机删除掉从某个叶子节点到达根节点的路径,然后输出带电量。

    带电量的定义是取所有连通块的带电量的最大值

    题解

    直接暴力dfs下去,维护子树带电量和这个节点的带电量。

    每次树形dp取左边还是取右边,维护一下就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    map<int,int>sum,cost;
    int h,n;
    double solve(int x,double ans){
        if(sum[x]<=ans)return ans;
        return (solve(x*2,max(ans,1.*cost[x]+sum[x*2+1]))+solve(x*2+1,max(ans,1.*cost[x]+sum[x*2])))/2.0;
    }
    int main()
    {
        scanf("%d%d",&h,&n);
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            if(s[0]=='a'){
                int a,b;
                scanf("%d%d",&a,&b);
                cost[a]+=b;
                while(a){
                    sum[a]+=b;
                    a/=2;
                }
            }
            else{
                printf("%.9f
    ",solve(1,0));
            }
        }
    }
  • 相关阅读:
    day05 Python
    重新理解apache解析漏洞
    PhpAdmin安装报错, php syntax error, unexpected T_STRING on line 8
    一键配置Visual Studio Code( 1.57.1)开发java
    apt-get upgarde 和dist-upgrade的差别
    解决 Python2 报错 LookupError: unknown encoding: cp65001
    文件上传漏洞随手感想
    161端口SNMP敏感信息泄露漏洞
    使用电模拟器导出微信小程序包(wxapkg)
    kali安装docker
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6152953.html
Copyright © 2011-2022 走看看