杭电5858 (Hard problem)
Problem Description
cjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it?
Give you the side length of the square L, you need to calculate the shaded area in the picture.
The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square.
Give you the side length of the square L, you need to calculate the shaded area in the picture.
The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square.
Input
The first line contains a integer T(1<=T<=10000), means the number of the test case. Each case contains one line with integer l(1<=l<=10000).
Output
For each test case, print one line, the shade area in the picture. The answer is round to two digit.
Sample Input
1 1
Sample Output
0.29分析:直接套公式!!!!AC代码如下:#include <iostream> #include <cmath> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <algorithm> using namespace std; #define PI acos(-1.0) #define n1 acos((double)5*sqrt(2.0)/8) #define n2 acos((double)3/4) int main() { //printf("%lf\n",PI); int t; cin >> t; while (t --) { int a; cin >> a; double s2 = (double)PI*a*a*n1/(2*PI); double s1 = (double)PI/4*a*a*(n1+n2)/(2*PI); double s3 = (double)sqrt(7.0)/16*a*a; double s4 = (double)4*(s1-s2+s3); printf("%.2lf\n",s4); } return 0; }
杭电5867(Water problem)Problem DescriptionIf the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3+3+5+4+4=19 letters used in total.If all the numbers from 1 to n (up to one thousand) inclusive were written out in words, how many letters would be used?
Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
InputThere are multiple test cases. The first line of input contains an integer T, indicating the number of test cases.
For each test case: There is one positive integer not greater one thousand.
OutputFor each case, print the number of letters would be used.
Sample Input3 1 2 3
Sample Output3 6 11
分析:水题!!!AC代码如下:
#include <iostream> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <algorithm> using namespace std; int a[20] = {0,3,3,5,4,4,3,5,5,4,3, 6, 6, 8, 8, 7, 7, 9, 8, 8}, b[11] = {0, 0, 6, 6, 5, 5 ,5 , 7, 6, 6}; int main() { int t; cin >>t; int res = 0; while (t --) { int n; cin >> n; if (n<=10) res += a[n]; else if (n>10 && n<100) { int n1 = n/10; if (n1 == 1) res += a[n]; else { int n2 = n%10; int num = b[n1] + a[n2]; res += num; } } else if (n >= 100 && n < 1000) { int n1 = n/100; int n2 = n%100; if (n2 == 0 && n1 == 1) res += 10; //100 else if (n2 < 20 && n1 == 1) { int num = 10+a[n1]+a[n2]; res += num; } else { //cout << n1 << endl; int num = 7+a[n1]; if (n2 != 0) { int n3 = n2/10; //b int n4 = n2%10; //a if (n3 >= 2) { num += b[n3] + a[n4]; res += num + 3; } else { num += a[n2]; res += num + 3; } } else res += num; } } else res += 11; cout << res << endl; } return 0; }