hdu 4036 暴力二分 高精度 Rolling Hongshu
2012-08-29 13:54
316 查看
题意:http://acm.hdu.edu.cn/showproblem.php?pid=4036
神一般的二分。一个sweet potato想要去约会,从起点滚到终点,途经一个mountain,有m个峰顶,第一个峰顶,第m个峰顶分别为起点和终点,忽略摩擦力,在每一个斜坡上分布着bitter potatoes,每经过一个bitter potato,bitter potato就会以一定的初速度追赶sweet potato,问,sweet potato应该以最小多大的初速度滚动,保证不被bitter potato追到,完成约会;
解:
不仅要考虑到苦patato的时候速度要大,而且要考虑过山峰的时候速度要大于等于0.因为这个wa了甚久。然后全删了,本来还以为是我以前写过,于是就把以前代码贴过来改。改。但是事实是那是昨天朱老板用我的账号交的。。。不管怎样,题意以及解法是懂了的。
还有,尽量少开方。
网上还有代码是直接求的,不二分。求出到每个山峰需要多少速度,求出不被苦potato追到需要多少速度,取最大的。
转/article/6683775.html
神一般的二分。一个sweet potato想要去约会,从起点滚到终点,途经一个mountain,有m个峰顶,第一个峰顶,第m个峰顶分别为起点和终点,忽略摩擦力,在每一个斜坡上分布着bitter potatoes,每经过一个bitter potato,bitter potato就会以一定的初速度追赶sweet potato,问,sweet potato应该以最小多大的初速度滚动,保证不被bitter potato追到,完成约会;
解:
不仅要考虑到苦patato的时候速度要大,而且要考虑过山峰的时候速度要大于等于0.因为这个wa了甚久。然后全删了,本来还以为是我以前写过,于是就把以前代码贴过来改。改。但是事实是那是昨天朱老板用我的账号交的。。。不管怎样,题意以及解法是懂了的。
还有,尽量少开方。
网上还有代码是直接求的,不二分。求出到每个山峰需要多少速度,求出不被苦potato追到需要多少速度,取最大的。
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <iostream> #define eps 1.0e-8 using namespace std; struct node{ double x,y,w,v; bool flag; }point[5555]; struct line{ double k,b; }; line getl(node a,node b){ line ans; ans.k = (b.y - a.y)/(b.x - a.x); ans.b = a.y - a.x*ans.k; return ans; } bool cmp(node a,node b){ if(a.x != b.x) return a.x < b.x; return a.y < b.y; } int main(){ int T,n,m,w; scanf("%d",&T); int id = 1; double g = 20.0; while(T--){ scanf("%d%d%d",&n,&m,&w); for(int i = 0 ; i < n ; i ++){ scanf("%lf%lf",&point[i].x,&point[i].y); point[i].flag = 0; } for(int i = n ; i < n + m ; i ++){ point[i].y = -1000000000; scanf("%lf%lf%lf",&point[i].x,&point[i].v,&point[i].w); point[i].flag = 1; } sort(point,point+n+m,cmp); for(int i = 0 ; i < n + m ; i ++){ if(point[i].flag == 1){ int j = i; while(j--){ if(point[j].flag == 0) break; } int k = i; while(k++){ if(point[k].flag == 0) break; } line tp = getl(point[j],point[k]); point[i].y = point[i].x*tp.k + tp.b; } } double u,d,mid; u = 999999999999LL; d = 0.00; while(d <= u){ mid = (u+d)/2; bool flag = 1; node s = point[0]; s.v = mid*mid; for(int i = 1 ; i < n + m ; i ++){ s.v = 2*(g*(s.y - point[i].y) + s.v/2); s.y = point[i].y; s.x = point[i].x; if(s.v < 0){ flag = 0; break; } if(point[i].flag){ if(s.v <= point[i].v*point[i].v){ flag = 0; break; } } } if(flag){ u = mid - eps; } else d = mid + eps; } printf("Case %d: %.2f\n",id++,fabs((u + d) / 2.0)); } return 0; }
转/article/6683775.html
#include<stdio.h> #include<math.h> #include<string.h> struct PEAK { double x,h; }p[1100]; struct bit { double x,v; }pat[1100]; int main() { int G=20; double h,weight; int t,cases=1,i,j,n,m,w; scanf("%d",&t); while(t--) { double v0=0,temp; scanf("%d%d%d",&n,&m,&w); for(i=1;i<=n;i++) //求出到达任意一个峰顶需要的最小速度 { scanf("%lf%lf",&p[i].x,&p[i].h); if(p[i].h-p[1].h<=0) //峰顶在起始点一下,初速度可以为零 temp=0; else temp=sqrt(2*G*(p[i].h-p[1].h)); if(temp>v0) v0=temp; } double vx,v=0; for(i=1;i<=m;i++) //根据能量守恒,求出到达每一个bitter potato需要的最小速度 { scanf("%lf%lf%lf",&pat[i].x,&pat[i].v,&weight); pat[i].x+=p[1].x; //将bitter potato的坐标改为相对于原点 for(j=1;j<n;j++) { if(pat[i].x>=p[j].x&&pat[i].x<=p[j+1].x) //找出当前bitter potato所在的斜坡 { h=(1.0*(p[j+1].h-p[j].h)/(p[j+1].x-p[j].x))*(pat[i].x-p[j].x) + p[j].h; //bitter potatoe相对于原点的高度 break; } } vx=sqrt(1.0*pat[i].v*pat[i].v+1.0*2*G*(h-p[1].h)); //求出到达当前bitter potato需要的速度 if(vx>v) v=vx; } if(v>v0) printf("Case %d: %.2lf\n",cases++,v); else printf("Case %d: %.2lf\n",cases++,v0); } return 0; }
相关文章推荐
- HDU 4898 The Revenge of the Princess’ Knight(后缀数组+二分+暴力)(2014 Multi-University Training Contest 4)
- HDU 2141 Can you find it?(暴力+二分)
- hdu 4036 - Rolling Hongshu
- 【HDU】5930 GCD【暴力+线段树二分】
- hdu 2199 Can you solve this equation?(高精度二分)
- hdu 4737 二分或暴力
- hdu 4608 I - I-number()(高精度+暴力)
- HDU - 5875 Function 二分+RMQ||线段树||暴力
- HDU 5726 GCD [ST表+暴力二分]【数据结构|杂类】
- HDU 4265 Science! 最大流 二分 暴力
- HDU 1496 Equations 等式(二分+暴力,技巧)
- HDU 4151 The Special Number【二分+暴力枚举】
- HDU 1248 寒冰王座 完全背包 || 暴力 + 二分
- hdu 1056 HangOver(暴力||打表二分)
- hdu 1281 棋盘游戏【二分匹配+暴力枚举】
- HDU 2289 Cup【高精度,二分】
- HDU 3156 Repair Depots DLX 计算几何 二分 暴力
- HDU_4036 Rolling Hongshu
- HDU 4033 Regular Polygon(二分+高精度)
- HDU 5101 Select(暴力二分)