**ACM Volume CIV 10499 - The Land of Justice**

**The Problem**

In the Land of Justice the selling price of everything is fixed all over the country. Nobody can buy a thing and sell it in double price. But, that created problems for the businessmen. They left their business and went to the production. So, after some days everybody was in production and nobody in business. And the people didn’t get their necessary things though the country was self-sufficient in every sector.

The government became very much anxious. But, they were intelligent enough to call the mathematicians.

The mathematicians gave a solution. They suggested setting the surface area of an object as its selling-unit instead of its volume. Actually the clever mathematicians were very much interested to establish their own business.

Now, the government asks the programmers to build the software that would calculate the profit things.

Here your job is to calculate the business profit for a solid sphere. A businessman buys a complete sphere and to maximize his profit he divides it in n equal parts. All cut should go through the axis of the sphere. And every part should look like the picture below:

**Input**

You are given a sequence of integers N (0 < N < 2

^{31}), indicating the numbers of parts of the sphere. The input file is terminated with a negative number. This number should not be processed.

**Output**

Calculate the profit over the sold pieces. The result should be in percentage and rounded to the nearest integer.

**Sample Input**

2

2

-1

**Sample Output**

50%

50%

**解題思考**

這一題是數學題，根本不需要什麼特別的方法。

首先我們知道，一個半徑為 R 的球體表面積公式為 4π × R

^{2}。而且，一個半徑為 R 的圓面積公式為 π × R

^{2}。

又因為，若是一顆球被切割成兩等分時，其表面積會增加四個半圓，也就是 2π × R

^{2}；而若是一顆球被切割成三等分時，其表面積會增加六個半圓，也就是 3π × R

^{2}。所以我們可以推得，若是一顆球被切割成 n 等分時，其表面積會增加 2n 個半圓，也就是 n × π × R

^{2}。

根據以上，我們便可以得到，當球被切成 n 等分時，表面積(利潤)將會是原來的 (n × π × R

^{2}) ÷ (4π × R

^{2}) = n / 4 = n × 25%。將這個結果寫成程式，答案就呼之欲出了。

**參考解答(C++)**

#include <iostream> using namespace std; int main(void) { while (1) { long long n; cin >> n; if (n < 0) { break; } if (n == 1) { cout << "0%" << endl; } else { cout << n * 25 << "%" << endl; } } #ifndef ONLINE_JUDGE system("pause"); #endif return 0; }

## 0 回覆:

## 張貼留言