[UVA][分&二分] 1280 - Curvy Little Bottles@Morris' Blog|PChome Online 人新台
2013-10-11 08:00:13| 人1,752| 回0 | 上一篇 | 下一篇

[UVA][分&二分] 1280 - Curvy Little Bottles

0 收藏 0 0 站台

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 polynomial P 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 0$ le$n$ le$10).
  • 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, -100$ le$ai$ le$100, and an $ neq$ 0.
  • Line 3:
    o
    xlow and xhigh, the real valued boundaries of the bottle (- 100$ le$xlow < xhigh$ le$100 and xhigh - xlow > 0.1).
    o
    inc, an integer which is the volume increment before each successive mark on the bottle (1$ le$inc$ le$500).

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 

1 4.0 -0.25 0.0 12.0 25 1 4.0 -0.25 0.0 12.0 300 0 1.7841241161782 5.0 10.0 20 0 1.0 0.0 10.0 10 

Sample Output 

Case 1: 263.89 0.51 1.06 1.66 2.31 3.02 3.83 4.75 5.87 Case 2: 263.89 insufficient volume Case 3: 50.00 2.00 4.00 Case 4: 31.42 3.18 6.37 9.55

目描述:
要你瓶上刻度,而瓶定的方式一在[xlow, xhight] 在 x 上方的多式,
多式著 x 旋而成,xlow 表示杯底部。

每刻度的差指定容量,印出最多前 8 刻度。

目解法:


先解出分方程,
integral(p^2 * pi)dx

二分下一指定的刻度。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double pi = acos(-1);
double calcPoly(double p[], double x, int n) {
double ret = 0, y = 1;
int i;
for(i = 0; i <= n; i++)
ret += p[i]*y, y *= x;
return ret;
}
#define eps 1e-8
int main() {
int n, cases = 0;
int i, j, k;
double xlow, xhigh, inc;
double a[25], b[25], c[25];
while(scanf("%d", &n) == 1) {
for(i = 0; i <= n; i++)
scanf("%lf", &a[i]);
scanf("%lf %lf %lf", &xlow, &xhigh, &inc);
memset(b, 0, sizeof(b));// b = a^2
memset(c, 0, sizeof(c));// c = integral of b.
for(i = 0; i <= n; i++)
for(j = 0; j <= n; j++)
b[i+j] += a[i]*a[j];
for(i = 0; i <= 2*n; i++)
c[i+1] = b[i]/(i+1);
n = 2*n+1;
double volume = (calcPoly(c, xhigh, n)-calcPoly(c, xlow, n))*pi;
printf("Case %d: %.2lf\n", ++cases, volume);
int marking = min((int)floor(volume/inc), 8);
if(marking == 0)
puts("insufficient volume");
else {
double prev = xlow;
for(i = 0; i < marking; i++) {
double l = prev, r = xhigh, mid;
double lv = calcPoly(c, l, n), mv;
while(fabs(l-r) > eps) {
mid = (l+r)/2;
mv = calcPoly(c, mid, n);
if((mv-lv)*pi > inc)
r = mid;
else
l = mid;
}
if(i) putchar(' ');
printf("%.2lf", mid-xlow);
prev = mid;
}
puts("");
}
}
return 0;
}
 

台: Morris
人(1,752) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 教育(修、留、研究、教育概) | 人分: UVA |
此分下一篇:[UVA][散化&dp] 1092 - Tracking Bio-bots
此分上一篇:[UVA][二分搜] 10372 - Leaps Tall Buildings

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86