[MM19-易] Surface to Volume Ratio
Problem Description
Write a program to compute surface to volume ratio. We will be given the height, width, and depth of N cuboid, and determine the smallest surface to volume ratio among them.
Input File Format
The first line of the input data consists of N, where 0 < N <= 1000. The next N lines contain the height, width, and depth of each cuboid. All the dimensions are between 1 and 50.
Output Format
You should output the smallest surface to volume ratio as "a/b". This number must be simplified, that is, a and b must be prime to each other.
Example
Write a program to compute surface to volume ratio. We will be given the height, width, and depth of N cuboid, and determine the smallest surface to volume ratio among them.
Input File Format
The first line of the input data consists of N, where 0 < N <= 1000. The next N lines contain the height, width, and depth of each cuboid. All the dimensions are between 1 and 50.
Output Format
You should output the smallest surface to volume ratio as "a/b". This number must be simplified, that is, a and b must be prime to each other.
Example
Sample Input: | Sample Output: |
2 2 3 4 1 1 1 | 13/6 |
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <stdio.h>
- #include <ctype.h>
- #include <cmath>
- using namespace std;
- int main() {
- // [MM19-易] Surface to Volume Ratio
- int n;
- int a, b, c;
- int mvol = 0, msur = 0;
- cin >> n;
- double min = 125000;
- for(int i = 0;i < n;i++)
- {
- cin >> a >> b >> c;
- int vol = a*b*c;
- int sur = (a*b+b*c+a*c)*2;
- double re = (double)sur/(double)vol;
- if(re < min)
- {
- min = re;
- mvol = vol;
- msur = sur;
- }
- }
- for(int i = 1;i < mvol;i++)
- {
- if(mvol % i == 0 && msur % i == 0)
- {
- if(i != 1)
- {
- while(mvol % i == 0 && msur % i == 0)
- {
- mvol = mvol / i;
- msur = msur / i;
- }
- }
- }
- }
- cout << msur << "/" << mvol << endl;
- return 0;
- }
沒有留言:
張貼留言