第二次组队赛之:Expanding Rods&&Aggressive cows&&Can you solve this equation?&&Strange fuction
2013-07-30 21:55
399 查看
Expanding Rodshttp://poj.org/problem?id=1905
思路;先是一定要想到数学模型!!!
从题目类型就是用二分法的:(以前应该做过的)就是一段圆的弧长
注意是对半径进行二分!!(弧长公式:半径乘对应的角度)(一定要找到进行二分的对象)
Aggressive cowshttp://poj.org/problem?id=2456
二分+贪心:思路:就是把那个距离进行二分(当全部大于这个距离时,把它放大,不然就缩小)
Can you solve this equation?http://acm.hdu.edu.cn/showproblem.php?pid=2199
一个最基础的二分题:就是从一个函数入手(一般题目最后都要找到这类的函数)
Strange fuctionhttp://acm.hdu.edu.cn/showproblem.php?pid=2899
一个基础的三分题目:(不必多说,一般此类题目的裸体就是这个样子。)
思路;先是一定要想到数学模型!!!
从题目类型就是用二分法的:(以前应该做过的)就是一段圆的弧长
注意是对半径进行二分!!(弧长公式:半径乘对应的角度)(一定要找到进行二分的对象)
#include<iostream> #include<stdio.h> #include<algorithm> #include<math.h> using namespace std; double l; double f(double a) { return 2*asin(l/(a*2))*a;//反三角sin() } double g(double b) { return b-sqrt(b*b-l*l/4); } int main() { double n,c,r1,r2,L,mid; while(scanf("%lf%lf%lf",&l,&n,&c)!=EOF) { if(l<0&&n<0&&c<0) break; if(l==0||n==0||c==0) {printf("0.000\n");continue;} r1=l/2;//左半径最小应大于这个数。 r2=l;//注意一个数学的简单现象:半径越长,弧长越短。 L=(1+n*c)*l; while(f(r2)>L) r2=r2*2;//这里判断求一个比实际弧长小的数就行了。 while(fabs(f(r1)-f(r2))>1e-9)//对半径进行二分 { mid=r1/2+r2/2; if(f(mid)>L) r1=mid; else if(f(mid)<L) r2=mid; else break; } printf("%.3lf\n",g(mid)); } return 0; }
Aggressive cowshttp://poj.org/problem?id=2456
二分+贪心:思路:就是把那个距离进行二分(当全部大于这个距离时,把它放大,不然就缩小)
#include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int n,a[100005],c; int judge(int s) { int i,number=1,frontt=0; for(i=0;i<n;i++) { if(a[i]-a[frontt]>=s) { number++;frontt=i; if(number==c) return 1; } } return 0; } int main() { int i,left,right,mid; scanf("%d%d",&n,&c); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); left=0; right=a[n-1]-a[0]; while(left<=right) { mid=(left+right)/2; if(judge(mid))//判断在这个距离时,能不能全部放入 left=mid+1; else right=mid-1; } printf("%d\n",right); return 0; }
Can you solve this equation?http://acm.hdu.edu.cn/showproblem.php?pid=2199
一个最基础的二分题:就是从一个函数入手(一般题目最后都要找到这类的函数)
#include<stdio.h> #include<math.h> int main() { int y,T; scanf("%d",&T); while(T--) { double l=0,r=100,mid,sum; scanf("%d",&y); if(y<6||y>807020306) { printf("No solution!\n"); continue; } while(r-l>1e-9)//一般都要大于这个数才准确吧。(小数点后九位) { mid=(r+l)/2; sum=pow(mid,4)*8+7*pow(mid,3)+mid*mid*2+3*mid+6; if(sum>y) r=mid; else if(sum<y) l=mid; else if(sum==y) break; } printf("%.4lf\n",mid); } return 0; }
Strange fuctionhttp://acm.hdu.edu.cn/showproblem.php?pid=2899
一个基础的三分题目:(不必多说,一般此类题目的裸体就是这个样子。)
#include<iostream> #include<stdio.h> #include<algorithm> #include<math.h> using namespace std; double y; double dis(double x) { return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x; } int main() { double left,right,mid,mmid,t2,t1; int t; scanf("%d",&t); while(t--) { scanf("%lf",&y); left=0;right=100; while(right-left>1e-9) { mid=left/2+right/2; mmid=mid/2+right/2; t2=dis(mid);t1=dis(mmid); if(t2>t1) { left=mid; } else if(t2<t1) { right=mmid; } else break; } printf("%.4lf\n",t1); } return 0; }
相关文章推荐
- HDU 2199 Can you solve this equation? && NYOJ 503 解方程
- hdu2199 Can you solve this equation? && hdu2899 Strange fuction && hdu1551Cable master
- HDU2199 Can you solve this equation 二分求方程的根
- 杭电2199 Can you solve this equation?(二分)
- hdoj 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation? 二分水题
- hdu 2199 Can you solve this equation?
- HDU 2199 Can you solve this equation?
- 搜索—Problem_1001-Can you solve this equation?
- Can you solve this equation?(简单二分)
- HDU 2199 Can you solve this equation? 二分
- HDU—2199—Can you solve this equation?—【二分】【精度控制】
- Can you solve this equation?--二分
- HDU 2199 Can you solve this equation?(二分算法)
- hdu 2199 Can you solve this equation? 【二分】
- HDU 2199 Can you solve this equation?(二分搜索)
- 2199 Can you solve this equation?
- hdu 2199_Can you solve this equation?
- HDU2199 Can you solve this equation?(二分)
- hdu 2199 Can you solve this equation?