【ACM ICPC World Finals 2012】 Curvy Little Bottles (二分)
来源:互联网 发布:腾讯ec垃圾软件 编辑:程序博客网 时间:2024/04/20 06:10
In her bike rides around Warsaw, Jill happened upon a shop that sold interesting glass bottles. She thought it might make an interesting project to use such bottles for measuring liquids, but this would require placing markings on the bottles to indicate various volumes. Where should those volume marks be placed?
Jill formalized the problem as follows. Assume a bottle is formed by revolving a shape that is the same as the graph of a polynomialP between x = xlow and x = xhigh around the x-axis. Thus the x-axis is coincident with a vertical line through the center of the bottle. The bottom of the bottle is formed by a solid circular region at x = xlow , and the top of the bottle, at x = xhigh, is left open.
The first sample input represents a bottle formed using the simple polynomial 4 - 0.25x, with xlow = 0 and xhigh = 12. The bottom of this bottle is a circle with a radius of 4, and the opening at the top is a circle with a radius of 1. The height of this bottle is 12. Volume markings are in increments of 25.
Given a polynomial P, xlow, xhigh, and the volume increment between successive marks on the bottle, compute the distances up from xlow for the marks at successive volume increments. A mark cannot be made past the top of the bottle, and no more than the first 8 increments should be marked. Assume the value of P is greater than zero everywhere between xlow and xhigh.
Input
Each test case consists of three lines of bottle data:
- Line 1: n, the degree of the polynomial (an integer satisfying 0n10).
- Line 2: a0, a1,..., an, the real coefficients of the polynomial P defining the bottle's shape, where a0 is the constant term, a1 is the coefficient of x1,..., and an is the coefficient of xn. For each i, -100ai100, and an 0.
- Line 3:
- o
- xlow and xhigh, the real valued boundaries of the bottle (- 100xlow < xhigh100 and xhigh - xlow > 0.1).
- o
- inc, an integer which is the volume increment before each successive mark on the bottle (1inc500).
Output
For each test case, display the case number and the volume of the full bottle on one line. On a second line, display the increasing sequence of no more than 8 successive distances up from the bottom of the bottle for the volume markings. All volumes and height marks should be accurate to two decimal places. If the bottle does not have a volume that allows at least one mark, display the phrase `insufficient volume'. No test case will result in a mark within 0.01 from the top of the bottle. The volume of the bottle will not exceed 1 000. All rounded distances for marks on a bottle differ by at least 0.05.
Sample Input
14.0 -0.250.0 12.0 2514.0 -0.250.0 12.0 30001.78412411617825.0 10.0 2001.00.0 10.0 10
Sample Output
Case 1: 263.890.51 1.06 1.66 2.31 3.02 3.83 4.75 5.87Case 2: 263.89insufficient volumeCase 3: 50.002.00 4.00Case 4: 31.423.18 6.37 9.55代码:
#include <stdio.h>#include <string.h>#include <math.h>#include <string>#include <stdlib.h>#include <limits.h>#include <iostream>#include <algorithm>#define len 14#define pi acos(-1.0)#define eps 1e-6using namespace std;double getV(double a[], int n,double x1,double x2){ double ans=0.0; double x_1=1.0,x_2=1.0; for(int i=0; i<=2*n; ++i) { x_1*=x1; x_2*=x2; ans+=a[i]*(x_2-x_1)/(i+1); } return ans*pi;}double getMark(double a[],int n,double x1,double x2,int mark){ double x_1=x1; double mid=x2; double dif=getV(a,n,x_1,mid)-mark; if(dif>0) { while(fabs(dif)>eps) { mid=(x1+x2)/2; dif=getV(a,n,x_1,mid)-mark; if(dif>0) x2=mid; else x1=mid; } } return mid;}double a[len],b[2*len],c[10] ;int main(){ int n,mark,k=0,count; double x_high,x_low,res,x0,_x; while(scanf("%d",&n)!=EOF) { count=0; k++; memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(int i=0; i<=n; ++i) scanf("%lf",&a[i]); for(int i=0; i<=n; ++i) for(int j=0; j<=n; ++j) b[i+j]+=a[i]*a[j]; scanf("%lf%lf%d",&x_low,&x_high,&mark); printf("Case %d: ",k); res=getV(b,n,x_low,x_high); printf("%.2lf\n",res); if(res<mark) printf("insufficient volume\n"); else { x0=x_low; while(count<8) { _x=getMark(b,n,x_low,x_high,mark); if(_x<x_high) { c[++count]=_x-x0; x_low=_x; } else break; } for(int i=1; i<=count; ++i) printf((i==count)?"%.2lf\n":"%.2lf ",c[i]); } } return 0;}
- 【ACM ICPC World Finals 2012】 Curvy Little Bottles (二分)
- ACM/ICPC World Finals 2012 B Curvy Little Bottles
- 130716ACM-ICPC World Finals, 2012练习赛Curvy Little Bottles
- 【CodeForces】gym-101205B Curvy Little Bottles (2012 ACM-ICPC World Finals B)
- Curvy Little Bottles——ACM icpc 2012 word final problem B
- Curvy Little Bottles-二分和积分
- Gym 101205 (ACM-ICPC World Finals 2012)
- ACM-ICPC World Finals 2017
- ACM/ICPC World Finals 2012 D Fibonacci Words
- ACM-ICPC 2013 World Finals 简单题解
- Puzzle, ACM/ICPC World Finals 1993, UVa227
- ACM/ICPC World Finals 2013 D Factors
- ACM/ICPC World Finals 2010 D Castles
- Puzzle,ACM/ICPC World Finals 1993,UVa227
- Puzzle,ACM/ICPC World Finals 1993, UVa227
- Sqaures, ACM/ICPC World Finals 1990, UVa
- CUGBACM130715 组队赛 BNU Curvy Little Bottles - from lanshui_Yang
- 浙江大学获ACM-ICPC World Finals …
- java面向对象-RuntimeException异常
- 【拯救电源键】最详尽的android开发一键锁屏实例 提供免费源码+apk
- HDU 1015 Safecracker
- [C++面试题]之单链表
- java 泛型详解
- 【ACM ICPC World Finals 2012】 Curvy Little Bottles (二分)
- cocos2dx 基础触碰效果封装(通用于具有触碰效果的节点或精灵,类似按钮,方便扩展),很久以前的代码
- 桶排序
- ssh环境搭建
- 防御性编程
- 机房重构(1)——SqlHelper
- NYOJ-284 坦克大战
- Android进程与内存及内存泄露
- sql练习2