ICPC 2012 - B. Curvy Little Bottles
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
Source-first archive entry
This page is built from the copied files in competitive_programming/icpc/2012/B-curvy-little-bottles. Edit
competitive_programming/icpc/2012/B-curvy-little-bottles/solution.tex to update the written solution and
competitive_programming/icpc/2012/B-curvy-little-bottles/solution.cpp to update the implementation.
The website does not replace those files with hand-maintained HTML. It reads the copied source tree during the build and exposes the exact files below.
Problem Statement
Copied statement text kept beside the solution archive for direct reference.
Problem B
Curvy Little Bottles
Problem ID: bottle
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 ≤ n ≤ 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 ≤ ai ≤ 100, and an 6= 0.
• Line 3:
◦ xlow and xhigh , the real valued boundaries of the bottle (−100 ≤ xlow < xhigh ≤ 100 and
xhigh − xlow > 0.1).
◦ inc, an integer which is the volume increment before each successive mark on the bottle
(1 ≤ inc ≤ 500).
Output
For each test case, display the case number and the volume of the full bottle on one line. On a sec-
ond 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 dec-
imal 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 Output for Sample Input
1 Case 1: 263.89
4.0 -0.25 0.51 1.06 1.66 2.31 3.02 3.83 4.75 5.87
0.0 12.0 25 Case 2: 263.89
1 insufficient volume
4.0 -0.25 Case 3: 50.00
0.0 12.0 300 2.00 4.00
0 Case 4: 31.42
1.7841241161782 3.18 6.37 9.55
5.0 10.0 20
0
1.0
0.0 10.0 10
Editorial
Rendered from the copied solution.tex file. The original TeX source remains
available below.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
Exact copied C++ implementation from solution.cpp.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files
Exact copied source-of-truth files. Edit solution.tex for the write-up and solution.cpp for the implementation.
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}
\title{ICPC World Finals 2012\\B. Curvy Little Bottles}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Problem Summary}
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
\section*{Key Observations}
\begin{itemize}[leftmargin=*]
\item Write the structural observations that make the problem tractable.
\item State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
\item If the constraints matter, explain exactly which part of the solution they enable.
\end{itemize}
\section*{Algorithm}
\begin{enumerate}[leftmargin=*]
\item Describe the data structures and the state maintained by the algorithm.
\item Explain the processing order and why it is sufficient.
\item Mention corner cases explicitly if they affect the implementation.
\end{enumerate}
\section*{Correctness Proof}
We prove that the algorithm returns the correct answer.
\paragraph{Lemma 1.}
State the first key claim.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Lemma 2.}
State the next claim if needed.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Theorem.}
The algorithm outputs the correct answer for every valid input.
\paragraph{Proof.}
Combine the lemmas and finish the argument.
\section*{Complexity Analysis}
State the running time and memory usage in terms of the input size.
\section*{Implementation Notes}
\begin{itemize}[leftmargin=*]
\item Mention any non-obvious implementation detail that is easy to get wrong.
\item Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
\end{itemize}
\end{document}
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}