1004: This is Halloween: Saving Money
Time Limit: 1 Sec | Memory Limit: 128 MB | |
Submit: 11 | Solved: 1 |
Description
The Mayor of Halloween Town was always concerned about saving money. When the Pumpkin King, Jack Skelington decided to try his hand at stealing Christmas again, the mayor began trying to cut corners wherever he could to afford it. They were in a recession, after all! When the great Jack commanded him to order enough wrapping paper for all the presents, the Mayor wanted to make sure he would only the absolute minimum amount. In order to do that, he has asked you, the local computer ghoul to write a problem to calculate the amount of wrapping paper that each of the different types of gifts would take. Thankfully for you, all of the gifts are able to fit in different sizes of rectangular boxes (The vampire trio, who is in charge of presents this year, got their start in manufacturing things while interns at Ikea). Each present can be represented by a name, and the three dimensions of the boxa,b,c(0 < a <= b <= c) in frightometers.
The procedure for wrapping the gift is first, a large sheet of wrapping paper is laid on a flat surface. Then, the box is placed on the wrapping paper with one of its ‘bc‘ faces resting on the wrapping paper. The wrapping paper is folded around the four ‘c‘ edges and the excess is cut off, leaving a 3 frightometer wide overlap on one of the ‘ac‘ faces (shown shaded in the figure). At this point, the wrapping paper has the form of a long rectangular tube.
Now more wrapping paper is cut off at the two ends of the tube. It is cut flush with the ‘a‘ edges. Along the ‘b‘ edges, rectangular flaps remain. These rectangular flaps are cut so that when they are folded along the ‘b‘ edges, they cover the two ‘ab‘ faces with a 3 frightometer wide overlap (overlapping areas shown shaded in the figure). The excess paper can be recycled (The Shadow on the Moon at night is an accomplished paper maker!), so that isn‘t to be taken into account. Calculate the amount of paper, in square frightometers that each box needs in order to be properly wrapped.
Input
Input will begin with a single line containing a single integer,n > 0, wherenis the number types of boxes you need to process. The followingnlines start with the name of a product, in single quotes followed by three integers,a,bandcwhich represent the three dimensions of the package, as illustrated in the picture above. Following the dimensions, a number of significant digits to include in the answer. The number of significant digits will never be greater than the number of digits in the answer. None of the dimensions will be greater than 10,000.
Output
Output will consist ofnlines of the form:"The Present <Present Name> requires <total paper area> square frightometers of paper to wrap"
Sample Input
5 ‘Kingdom Hearts III: When will it ever come out?‘ 1 2 3 1 ‘Killer Bunnies‘ 7 14 21 2 ‘Living head of Joseph Mengele‘ 34 81 101 1 ‘Barney and Friends: The complete Series‘ 1 7 11 3 ‘Abba: Greatest Hits‘ 45 78 650 5
Sample Output
The Present Kingdom Hearts III: When will it ever come out? requires 40 square frightometers of paper to wrap The Present Killer Bunnies requires 1200 square frightometers of paper to wrap The Present Living head of Joseph Mengele requires 20000 square frightometers of paper to wrap The Present Barney and Friends: The complete Series requires 265 square frightometers of paper to wrap The Present Abba: Greatest Hits requires 169330 square frightometers of paper to wrap
HINT
Source
2011 ACM ICPC South Central USA Regional Programming Contest
此题OJ还有点问题,还是等阳哥来搞改数据吧,原题是LA5745
题意理解:
包装礼品盒,如图的地方加 3 米宽的带子,求最少要多少布料,只保留 d 为有效数字。
#include <bits/stdc++.h> using namespace std; int num[1000]; int main() { //freopen("test.in","r",stdin); //freopen("out.txt","w",stdout); int cases; scanf("%d",&cases); while(cases--) { char s[10000],t[10000]; memset(s,‘\0‘,sizeof(s)); long long a,b,c,d; while(1) { scanf("%s",t); strcat(s," "); strcat(s,t); if(s[strlen(s)-1]==‘\‘‘) break; } scanf("%lld%lld%lld%lld",&a,&b,&c,&d); // printf("%s\n",s); // printf("%d %d %d %d\n",a,b,c,d); long long ans = 2*(a*b+a*c+b*c) + 6*b + 3*c; // printf("%d\n",ans); int k = 0; while(ans) { num[k] = ans % 10; ans = ans / 10; k++; } int pos = k - d; long long _ans = 0; for(int i=pos; i<k; i++) _ans += (int)num[i] *(int) pow(10.0,i); printf("\"The Present "); for(int i=2;i<strlen(s)-1;i++) putchar(s[i]); printf(" requires %d square frightometers of paper to wrap\"\n",_ans); } return 0; }