Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water
题目链接:B、New Theatre Square
题意:
你要把所有“.” 都变成“*”,你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一行一次铺两个(1*2)。第一种花费x,第二种花费y。问最少花费多少能把所有铺完
题解:
如果y>=2*x,那么就直接找到所有“.”,然后乘于x就行
否则就找俩俩一对就行了
代码:

1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string>
5 #include<queue>
6 #include<deque>
7 #include<string.h>
8 #include<map>
9 #include <iostream>
10 #include <math.h>
11 #define Mem(a,b) memset(a,b,sizeof(a))
12 const double II = acos(-1);
13 const double PP = (II*1.0)/(180.00);
14 using namespace std;
15 typedef long long ll;
16 const int INF=0x3f3f3f3f;
17 const int maxn=1000+10;
18 char s[maxn][maxn];
19 int main()
20 {
21 int t;
22 scanf("%d",&t);
23 while(t--)
24 {
25 int n,m,x,y;
26 scanf("%d%d%d%d",&n,&m,&x,&y);
27 for(int i=1; i<=n; ++i)
28 scanf("%s",s[i]+1);
29 int sum_white=0,sum=0;
30 for(int i=1; i<=n; ++i)
31 {
32 for(int j=1; j<=m; j++)
33 {
34 if(s[i][j]=='*') continue;
35 if(s[i][j]=='.' && s[i][j+1]=='.')
36 {
37 sum_white+=2;
38 sum+=y;
39 j++;
40 continue;
41 }
42 else
43 {
44 sum_white++;
45 sum+=x;
46 j++;
47 }
48 }
49 }
50 if(2*x<=y)
51 printf("%d\n",sum_white*x);
52 else
53 {
54 printf("%d\n",sum);
55 }
56 }
57 return 0;
58 }
题目链接:C、Mixing Water
题意:
往一个无限深的桶里面倒水,先倒入热水再倒入凉水,热水温度h,凉水温度c。给你一个温度n,问你倒多少次水才可以是水桶内温度最接近n
题解:
如果倒入水的次数是偶数,那么温度一直是 (h+c)/2
如果倒入水次数是奇数,会得到水桶内温度 y=((x+1)*h+c*x)/(2*x+1) (x是倒入凉水次数)
可见如果将x只取奇数(1,3,5,7...)那么这就是一个单调递减函数。所以二分求解就可以了
也可以这样理解,你倒入x杯凉水和x杯热水之后温度是(h+c)/2,那么你有多倒入一杯热水,那么这杯热水的温度肯定被所有杯水平分,那么x越大,每单独一杯分配到的水温越小
代码:
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string>
#include<queue>
#include<deque>
#include<string.h>
#include<map>
#include <iostream>
#include <math.h>
#define Mem(a,b) memset(a,b,sizeof(a))
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1000+10;
const double eps=1e-6;
const double PI=acos(-1);
ll h,c,t;
int main()
{
ll tt;
cin>>tt;
while(tt--)
{
cin>>h>>c>>t;
if(h+c>>1>=t)
{
cout<<2<<endl;
}
else
{
//ll x=(h-t)*1.0/(2*t-h-c);
//cout<<(fabs(t-get(x))<=fabs(t-get(x+1))?2*x+1:2*x+3)<<endl;
ll l=0,r=1e9,ans=0;
while(l+1<r)
{
//printf("%I64d %I64d**\n",l,r);
ll mid=l+r>>1;
//if(mid%2!=0) mid--;
double temp=((h+c)*mid*1.0+h)/(mid*2.0+1.0);
if(temp>=t)
{
ans=mid;
l=mid;
}
else
{
r=mid;
}
}
double temp1=((h+c)*ans*1.0+h)/(ans*2.0+1.0);
ans++;
double temp2=((h+c)*ans*1.0+h)/(ans*2.0+1.0);
if(fabs(temp1-t)<=fabs(t-temp2))
{
printf("%I64d\n",(ans-1)*2+1);
}
else printf("%I64d\n",ans*2+1);
}
}
return 0;
}
Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water的更多相关文章
- Educational Codeforces Round 88 (Rated for Div. 2) B. New Theatre Square(贪心)
题目链接:https://codeforces.com/contest/1359/problem/B 题意 有一块 $n \times m$ 的地板和两种瓷砖: $1 \times 1$,每块花费为 ...
- Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task(枚举/最大连续子序列)
题目链接:https://codeforces.com/contest/1359/problem/D 题意 有一个大小为 $n$ 的数组,可以选取一段连续区间去掉其中的最大值求和,问求和的最大值为多少 ...
- Educational Codeforces Round 88 (Rated for Div. 2) A. Berland Poker(数学)
题目链接:https://codeforces.com/contest/1359/problem/A 题意 $n$ 张牌可以刚好被平分给 $k$ 个人,其中有 $m$ 张 joker,当一个人手中的 ...
- Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)
题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数 ...
- Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)
题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...
- Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维
题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...
- Educational Codeforces Round 88 (Rated for Div. 2) D、Yet Another Yet Another Task
题意: 给你一个含n个数a1,a2...an的数组,你要找到一个区间[l,r],使得al+a(l+1)+...+a(r-1)+ar减去max(al,a(l+1),...,a(r-1),ar)的值尽可能 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- 【MySQL】CentOS7中使用systemctl工具管理启动和停止MySQL
centos7以前版本,可以使用这个/etc/init.d/mysqld start 来启动mysql 但是centos7之后,通过systemctl start mysqld.service 这个要 ...
- 【Oracle】oracle pctfree和pctused详解
oracle pctfree和pctused详解 一.建立表时候,注意PCTFREE参数的作用 PCTFREE:为一个块保留的空间百分比,表示数据块在什么情况下可以被insert,默认是10,表示当数 ...
- cursor pin s和cursor pin s wait on x
1.cursor pin s是一个共享锁,一般情况下是因为发生在SQL短时间内大量执行 案例:在生产库中,突然出现大量的cursor pin s的等待,询问是否有动作后,同事说有编译存储过程(被误导了 ...
- 低功耗降线性稳压器,24V转5V降压芯片
PW2330开发了一种高效率的同步降压DC-DC变换器3A输出电流.PW2330在4.5V到30V的宽输入电压范围内工作集成主开关和同步开关,具有非常低的RDS(ON)以最小化传导 损失.PW2330 ...
- Python设计模式面向对象编程
前言 本篇文章是基于极客时间王争的<设计模式之美>做的总结和自己的理解. 说到面向对象编程,作为一个合格的Pythoner,可以说信手拈来.毕竟在Python里"万物都是对 ...
- 探索微软开源Python自动化神器Playwright
相信玩过爬虫的朋友都知道selenium,一个自动化测试的神器工具.写个Python自动化脚本解放双手基本上是常规的操作了,爬虫爬不了的,就用自动化测试凑一凑. 虽然selenium有完备的文档,但也 ...
- js 前端词典对象的属性和值读取
通常服务端返回比较奇葩的数据对象,不知道该怎么将这个对象转换为可用实体,想了很久,突发奇想想到了这么个方法. 需求是这样:企业有多个产品,产品有分为很几个种类.服务端有获取产品的接口,和单独获取产品种 ...
- Jmeter-插件扩展及性能监控插件的安装
需要对http服务进行大数据量的传值测试:看看产品中的http服务,能支持传多少字符:目标值是希望能到10w+: 上次测试中,服务器总是内存满导致服务不响应,因此想增加对服务端的性能监控:查阅了smi ...
- php artisan db:seed 报错
在laravel 5中执行,要执行数据填充时报如下错误 php artisan db:seed 错误: [ReflectionException] Cla ...
- Property attribute.
class property(object): """ Property attribute. fget function to be used for getting ...