Fork me on GitHub

Uva 10499 - The Land of Justice

Problem H

The Land of Justice

Input: standard input

Output: standard output

Time Limit: 4 seconds

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 inn 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 < 231), 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%


Problemsetter:  Tazrian Khan, University of Dhaka

 

 

复制代码
#include<stdio.h>
#include<string.h>
#include<math.h>

int main()
{
    double percent, n;
    while(scanf("%lf", &n) == 1 && n >= 0)
    {
        if(n != 1) percent = floor((n*1.0/4)*100+0.5);
        else percent = 0;
        printf("%.0lf%%\n", percent);
    }

    return 0;
}
复制代码

解题思路:
题目的意思根据背景理解可能更简单,首先是由于政府的政策导致商家的减少,而此时数学家提出意见说一件物品以它的表面积为销售单位而不是体积。这种方法被政府接受了,数学家为了盈利其实也想经商,而这时题目模拟出来了:就是给你一个球,本来的表面积特定的,但为了得到利润,把它劈开相同的大小的块,此时表面积肯定会增加,而相对于原来增加了多少的百分比,这就需要你去计算的。

刚开始可是题目都没读懂,而且还是用了整型,并没有考虑溢出的情况,WA了几次。

 

posted @   Gifur  阅读(415)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
TOP
点击右上角即可分享
微信分享提示