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. 安装了linux系统的设备上不了网怎么办

    玩了一阵子的树莓派,曾经计划将其作成一台小小无线路由,但是时间和精力关系始终未成功做成. 同时也有在进行一些arm开发板的学习,突然一天发现arm板直接插上网线不能是不能上网的,又想起之前玩树莓派的时 ...

  2. day6 - 面向对象学习

    面向对象介绍 特性 class object 封装 继承 https://segmentfault.com/a/1190000002685939 python2 经典类是按照深度优先来继承的:新式类是 ...

  3. MongoDB安装及shell简介

    MongoDB安装 MongoDB具有跨平台的优良特性,提供了对主流的操作系统支持,我们可以根据自己使用的操作系统,选择下载对应的安装包. 图 1. MongoDB支持各个版本的操作系统 MongoD ...

  4. 在sqlServer中把数据导出为insert脚本

    有时候为了把数据导出为insert脚本,不得不用一些小工具,或者通过自己写存储过程来完成这一操作.其实SqlServer本身就有这种功能.以下是详细步骤:

  5. 关于mvc中@Html.DropDownListFor和@Html.DropDownList默认值无法选中问题简单总结

    当我们在做类似编辑功能的时候,会给定select选中默认值,然而mvc中偶尔这个功能不能用,或者是强类型的@Html.DropDownListFor不能用.凑巧今天遇到问题,解决问题时发现了mvc的一 ...

  6. 基于OWIN WebAPI 使用OAuth授权服务【客户端验证授权(Resource Owner Password Credentials Grant)】

    适用范围 前面介绍了Client Credentials Grant ,只适合客户端的模式来使用,不涉及用户相关.而Resource Owner Password Credentials Grant模 ...

  7. Atitit.信息论原理概论attilax总结

    Atitit.信息论原理概论attilax总结 1. <信息论基础(原书第2版)>((美)科弗(Cover...)[简介_书评_在线阅读] - 当当图书.html1 2. <信息论- ...

  8. Atitit.guice3 ioc 最佳实践 o9o

    Atitit.guice3 ioc  最佳实践 o9o 1. Guice的优点and跟个spring的比较 1 2. 两个部分:::绑定and注入@Inject 1 3. 绑定所有的方法总结 2 3. ...

  9. MYSQL操作数据表中的记录

    36:操作数据表中的记录插入记录   INSERT INTO 表名  VALUES();   或者INSERT 表名  VALUES();  UPDATE更新记录(单表更新)  DELETE删除记录( ...

  10. IOS开发之进阶篇第一章 - 姿势识别器UIPanGestureRecognizer

    今天讲一下姿势识别器,UIGestureRecognizer这个是抽象类 1.拍击UITapGestureRecognizer (任意次数的拍击) 2.向里或向外捏UIPinchGestureReco ...