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 ...
随机推荐
- Java JDBC的 url 配置信息和Mybatis核心配置文件(MySQL 的配置信息)
JDBC 连接数据库的 url driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/smbms?uesSSL=true&u ...
- linux网络工具nc命令
nc是netcat的简写,有着网络界的瑞士军刀美誉.因为它短小精悍.功能实用,被设计为一个简单.可靠的网络工具. nc命令的作用 (1)实现任意TCP/UDP端口的侦听,nc可以作为server以TC ...
- 【ORA】ORA-27101快速处理方法
今天朋友的数据库出了问题,报错如下: 这个问题主要是是spfile和pfile文件不一致导致的, 生成一个pfile,完了用pfile启动数据库即可 SQL> create pfile '/ho ...
- mysql—if函数
在mysql中if()函数的具体语法如下:IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,则返回expr3的值. 开始实 ...
- 关于BAPI_GOODSMVT_CREATE中货物移动相关事务代码说明
BAPI_GOODSMVT_CREATE参数 goodsmvt_code中的GM_CODE是为 BAPI 货物移动分配事务代码 其取值为下面对应的事务代码: 01 MB0102 MB3103 MB1A ...
- CSS3+JS完美实现放大镜模式
最近看到一篇讲放大镜的文章,实践后感觉效果非常好,这里分享给大家. 效果如下: 其实现核心: CSS函数,如:calc() -- 动态计算:var() -- 使用自定义变量 CSS伪元素:::befo ...
- 使用Python的pandas模块、mplfinance模块、matplotlib模块绘制K线图
目录 pandas模块.mplfinance模块和matplotlib模块介绍 pandas模块 mplfinance模块和matplotlib模块 安装mplfinance模块.pandas模块和m ...
- cookie加密 当浏览器全面禁用三方 Cookie
cookie加密 cookie localstorage 区别 https://mp.weixin.qq.com/s/vHeRStcCUarwqsY7Y1rpGg 当浏览器全面禁用三方 ...
- 长连接开发踩坑之netty OOM问题排查实践
https://mp.weixin.qq.com/s/jbXs7spUCbseMX-Vf43lPw 原创: 林健 51NB技术 2018-07-13
- centos7+python+selenium+chrome
1.安装chrome yum install google-chrome 2.安装chromedriver所有版本的下载地址:https://sites.google.com/a/chromium.o ...