题目链接: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的更多相关文章

  1. 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$,每块花费为 ...

  2. Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task(枚举/最大连续子序列)

    题目链接:https://codeforces.com/contest/1359/problem/D 题意 有一个大小为 $n$ 的数组,可以选取一段连续区间去掉其中的最大值求和,问求和的最大值为多少 ...

  3. Educational Codeforces Round 88 (Rated for Div. 2) A. Berland Poker(数学)

    题目链接:https://codeforces.com/contest/1359/problem/A 题意 $n$ 张牌可以刚好被平分给 $k$ 个人,其中有 $m$ 张 joker,当一个人手中的 ...

  4. Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)

    题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数 ...

  5. Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)

    题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...

  6. Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维

    题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...

  7. 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)的值尽可能 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【剑指 Offer】08.二叉树的下一个节点

    题目描述 给定一颗二叉树和其中的一个节点,找出中序遍历序列的下一个节点.树中的节点除了有两个分别指向左右节点的指针,还有一个指向父节点的指针. Java public class Solution08 ...

  2. IntelliJ IDEA启动界面的秘密:当编程遇到艺术

    细心的同学会发现Intellij IDEA每次发版本的时候都会有不同的启动界面背景,都很比较抽象的艺术图像. JetBrains的其它产品也有自己独特的设计. 但是这背后是怎么实现的.有什么寓意却很少 ...

  3. 求素数个数的优化-LeetCode204

    问题 计数质数 统计所有小于非负整数 n 的质数的数量. 示例: 输入: 10 输出: 4 解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 . 第一种解法容易想到但是会 超时 ...

  4. 那些最全面的Windows10安装pytorch踩过的坑以及如何应用

    那些最全面的Windows10安装pytorch踩过的坑以及如何应用 一.pytorch简介 2017年1月,由Facebook人工智能研究院(FAIR)基于Torch推出了PyTorch.它是一个基 ...

  5. kali中安装漏洞靶场Vulhub

    一.什么是vulhub? Vulhub是一个基于docker和docker-compose的漏洞环境集合,进入对应目录并执行一条语句即可启动一个全新的漏洞环境,让漏洞复现变得更加简单,让安全研究者更加 ...

  6. 【EXPDP】指定导出,只导出函数,导出的时候加上where条件过滤

    expdp导出的时候可以使用parfile这个参数,在parfile中添加想要的导出信息: 这里简单写了几句: vim test.par include=function     --导出函数 inc ...

  7. oracle优化求生指南脚本记录

    1.查找未使用索引 /* Formatted on 2020/5/12 下午 03:32:39 (QP5 v5.163.1008.3004) */ WITH IN_PLAN_OBJECTS AS (S ...

  8. 我为什么不鼓吹 WireGuard

    原文链接:https://fuckcloudnative.io/posts/why-not-wireguard/ 最近有一款新型 VPN 工具备受瞩目,相信很多人已经听说过了,没错就是 WireGua ...

  9. MySQL高可用HA——keepalived配置

    0. Keepalived介绍   Keepalived是基于VRRP(Virtual Router Redundancy Protocol,虚拟路由器冗余协议)协议的一款高可用软件.Keepaili ...

  10. Centos7 Nginx 安装

    下载地址:http://nginx.org/download/nginx-1.18.0.tar.gz 1.准备工作 #安装gcc yum install gcc-c++ #安装pcre pcre-de ...