Codeforces 127C Hot Bath
来源:互联网 发布:科比生涯场均数据 编辑:程序博客网 时间:2024/04/30 19:10
题意:
给出整数t1,t2,x1,x2,t0,和公式,(1 ≤ t1 ≤ t0 ≤ t2 ≤ 106, 1 ≤ x1, x2 ≤ 106).求满足(0 ≤ y1 ≤ x1, 0 ≤ y2 ≤ x2)此条件的y1,y2使得t最接近t0,但要保证t>t0.输出y1,y2.多种方案时输出最大的y1,y2.
题解:不4个特判必WA。不过这4个特判不太容易想全。
case 1:t1==t0 && t2!=t0 => y1=x1,y2=0
case 2:t2==t0 && t1!=t0 => y1=0,y2=x2
case 3:t1==t2 =>y1=x1,y2=x2
做法:
枚举y1,然后t2可以解出来。在选最小的,不过也有坑!见程序吧
case 4:非常难想到的是,当y1==0,方程解出y2=0此时显然不对,所以此种情况仍需处理。
#include<iostream>#include<cstring>using namespace std;long long t1,t2,x1,x2,t0,f1,f2;long long cal(long long t1,long long y1,long long t2,long long y2){ return t1*y1+t2*y2-t0*(y1+y2);}void solve(long long y1,long long y2){ if(y2<0)y2=0;else if(y2>x2)y2=x2;//溢出 if(y1==0 && y2==0)return;//WA if(t1*y1+t2*y2<t0*(y1+y2))return;//不满足t>=t0的条件 if(cal(t1,y1,t2,y2)*(f1+f2)<cal(t1,f1,t2,f2)*(y1+y2)||(f1<0 && f2<0)) { f1=y1;f2=y2; } else if(cal(t1,y1,t2,y2)*(f1+f2)==cal(t1,f1,t2,f2)*(y1+y2)&&y1+y2>f1+f2) { f1=y1;f2=y2; }}int main(){ long long y2; while(cin>>t1>>t2>>x1>>x2>>t0) { f1=-1,f2=-1; if(t1==t2)//case { f1=x1;f2=x2; } else if(t1==t0)//case { f1=x1;f2=0; } else if(t2==t0)//case { f1=0;f2=x2; } else for(long long y1=1;y1<=x1;y1++) { if(t0>t2) { y2=(t1*y1-t0*y1)/(t0-t2); solve(y1,y2); } else if(t0<t2) { y2=(t1*y1-t0*y1)%(t0-t2)==0?(t1*y1-t0*y1)/(t0-t2):1+(t1*y1-t0*y1)/(t0-t2); solve(y1,y2); } } //y1=0 case 4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if(t2>=t0)solve(0,x2); cout<<f1<<" "<<f2<<endl; } return 0;}
- Codeforces 127C Hot Bath
- codeforces 126A Hot Bath
- Hot Bath
- Hot Bath
- CF—Hot Bath
- CodeForces 28c Bath Queue(概率dp)
- CodeForces 28 C.Bath Queue(概率DP+组合数学)
- (翻译)2016美国数学建模MCM A题(连续型)翻译:A Hot Bath 一个热水澡
- C++/MFC-Hot Key
- CodeForces 215D Hot Days(贪心)
- HOT
- HOT!!!!
- Hot
- Codeforces Round #132 (Div. 2) D. Hot Days
- Hot Days Codeforces Round #132 (Div. 2) D(贪心)
- Codeforces Round #132 (Div. 2) D. Hot Days
- 【堆/优先队列】洗澡 bath
- ssh定时bath的配置
- 筛法求素数
- prime算法 poj1789
- 新版hpple使用注意点
- labManage项目小结2
- ECMAScript 和 dom
- Codeforces 127C Hot Bath
- java基础知识
- 一名程序员的自我修养
- 返回引用
- 混淆矩阵
- 开源 免费 java CMS - FreeCMS-数据对象-channel
- 嵌入式linux安装sz/rz工具包
- MySQL自动关闭连接导致DBCP报错
- linux时间管理