解析:
因为每次先加热水,再加凉水,所以温度的范围肯定在 [ ( h+c ) / 2 , h ]
所以当 t 为 h时,结果为 1
当 t 小于( h+c ) / 2时,肯定为2 (一杯热水和一杯冷水)
当 t 属于 ( ( h+c ) / 2 , h )时,越加热水越靠近 ( h+c ) / 2,所以二分或者数学推导公式。
- #include
- using namespace std;
- #define int long long
- int n,h,c,t;
- double f(int x){
- return ((x+1)*h+x*c)*1.0/(2*x+1);
- }
- signed main(){
- scanf("%lld",&n);
- while(n--){
- scanf("%lld%lld%lld",&h,&c,&t);
- if(t==h) printf("1\n");
- else if(t*2<=(h+c)) printf("2\n");
- else{
- int x=(h-t)/(2*t-h-c);
- if(fabs(t-f(x))<=fabs(t-f(x+1))) cout<<2*x+1<
- else cout<<2*x+3<
- }
- }
- return 0;
- }
-
相关阅读:
状态机-状态规划(309. 买卖股票的最佳时机含冷冻期)
[论文精读]Semi-Supervised Classification with Graph Convolutional Networks
深度解析链动2+1模式,颠覆传统卖货思维?
java培训之SpringMVC错误消息的显示及国际化
PDF转Word怎么转?教你三招快速实现PDF转Word
大数据Hadoop入门教程 | (一)概论
MySQL45讲(第40~44讲)
css媒体查询新特性
SpringBoot SpringBoot 开发实用篇 4 数据层解决方案 4.1 内置数据源
线程同步
-
原文地址:https://blog.csdn.net/JungleZRD/article/details/133748291