题目链接: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. 【C++】《C++ Primer 》第十八章

    第十八章 用于大型程序的工具 大规模应用程序的特殊要求包括: 在独立开发的子系统之间协同处理错误的能力. 使用各种库进行协同开发的能力. 对比较复杂的应用概念建模的能力. 一.异常处理 异常处理(ex ...

  2. 从一次生产消费者的bug看看线程池如何增加线程

    0 背景 某个闲来无事的下午,看到旧有的项目中,有个任务调度的地方都是同步的操作,就是流程A的完成依赖流程B,流程B的完成依赖流程C,按此类推. 作为一名垃圾代码生产者,QA的噩梦.故障报告枪手的我来 ...

  3. 【Linux】实现端口转发的rinetd

    Linux下端口转发一般都使用iptables来实现,使用iptables可以很容易将TCP和UDP端口从防火墙转发到内部主机上.但是如果需要将流量从专用地址转发到不在您当前网络上的机器上,可尝试另一 ...

  4. 关于cin, cin.get(), getchar(),getline()的字符问题

    一.getchar()和cin.get() getchar()会将开头的空格或者回车作为输入 1 #include<iostream> 2 using namespace std; 3 i ...

  5. 浅入深出了解XXE漏洞

    环境搭建 https://github.com/c0ny1/xxe-lab 为了更深入的理解,我准备理论和实际相结合的了解XXE! 浅谈XML 初识XML 一个好的代码基础能帮助你更好理解一类漏洞,所 ...

  6. PAT练习num3-跟奥巴马一起学编程

    美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014 年底,为庆祝"计算机科学教育周"正式启动,奥巴马编写了很简单的计算机 ...

  7. mysql(连接查询和数据库设计)

    --创建学生表 create table students ( id int unsigned not null auto_increment primary key, name varchar(20 ...

  8. 【Windows】Win10家庭版启用组策略gpedit.msc

    [前言] 大家都认为,Windows 10家庭版中并不包含组策略,其实不然,它是有相关文件的,只是不让你使用而已.那么我们让系统允许你使用就好了. [操作步骤] 1.首先你需要在桌面上新建一个txt文 ...

  9. 2021年Web开发的7大趋势

    技术发展日新月异,所以 Web 开发人员也需要及时了解行业最新的发展趋势. 全球有超过 17.4 亿个网站.在每一个细分领域都有无数企业争夺搜索引擎的排名前列位置.开发人员应该了解和发现更多创新的 W ...

  10. 洛谷 P1401 城市

    写在前面 今天来水主题库里的有水分的紫题,随便一翻竟然找到宝了. 小清新二分 + 网络流. 算法思路 考虑到题目中限制的是最大边权,要求最大边权最小,那么很容易想到二分答案. 单调性的证明:最大边权是 ...