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\n",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\n",solve(1,0));
}
}
}

Codeforces Beta Round #62 题解【ABCD】的更多相关文章

  1. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  2. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  3. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  4. Codeforces Beta Round 84 (Div. 2 Only)

    layout: post title: Codeforces Beta Round 84 (Div. 2 Only) author: "luowentaoaa" catalog: ...

  5. Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)

    Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...

  6. Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)

    Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...

  7. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  8. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  9. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

随机推荐

  1. Unity5 如何做资源管理和增量更新

    工具 Unity 中的资源来源有三个途径:一个是Unity自动打包资源,一个是Resources,一个是AssetBundle. Unity自动打包资源是指在Unity场景中直接使用到的资源会随着场景 ...

  2. Bank homework 10 2016 4 25

    #include<iostream>#include<string>using namespace std;class Bank { public: Bank(string _ ...

  3. 使用Nexus搭建本地Maven私服

    搭建了好几天这个还是不大好使,今天看了一篇文章是讲这个的,然后根据其情况,加上自己的更改最后搭建成功了 1.下载nexus, 下载地址:http://www.sonatype.org/nexus/go ...

  4. NumberFormat usage

    NumberFormat 是所有数值格式的抽象基类. 该类提供了格式化和分析数值的接口. NumberFormat 也提供了确定 哪个语言环境具有数值格式以及它们名字的方法. import java. ...

  5. git flow的安装和使用

    确保安装了git 1.windows系统下安装 进入cmd clone github上的gitflow到一个文件夹下 我这里clone到 c:\gitflow git clone git://gith ...

  6. log4net详细配置说明

    原文地址:http://blog.sina.com.cn/s/blog_671486bc01011rdj.html 1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记 ...

  7. (状压) Marriage Ceremonies (lightOJ 1011)

    http://www.lightoj.com/volume_showproblem.php?problem=1011 You work in a company which organizes mar ...

  8. SQL Server锁分区特性引发死锁解析

    锁分区技术使得SQL Server可以更好地应对并发情形,但也有可能带来负面影响,这里通过实例为大家介绍,分析由于锁分区造成的死锁情形. 前段时间园友@JentleWang在我的博客锁分区提升并发,以 ...

  9. AIX之ASM存储扩容

    ASM存储扩容操作其实很简单,无非就是向DiskGroup(简称DG)里添加物理磁盘,增加DG的存储空间.说来简单,其实操作过程中有很多小细节要注意,否则,带来的后果是灾难性的. ASM扩容操作步骤( ...

  10. 入门级:怎么使用C#进行套接字编程(一)

    翻译一篇简单的文章学习下基础,此文针对我等对socket只听说未尝试阶段的水平. How to C# Socket programming C#通过他的命名空间像System.Net和System.N ...