Hard problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1219 Accepted Submission(s): 474
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
几何题,直接利用海伦公式,反三角函数
#include<stdio.h>
#include <map>
#include<cmath>
#include<string.h>
#include<string>
#include<algorithm>
#define PI 3.14159265358979323846
using namespace std;
int main()
{
int T;
double n,a,b,c,acos1,acos2,cosa1,cosa2,s,s1,s2,s3,p,re;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
scanf("%lf",&n);
a = n/2;
b = sqrt(2)*n/2;
c = n;
p = (a+b+c)/2;
cosa1=(b*b+c*c-a*a)/(2*b*c);
cosa2=(a*a+b*b-c*c)/(2*a*b);
acos1 = acos(cosa1) ;
acos2 = acos(cosa2) ;
s1 = acos1*(n*n);
s2 = (PI - acos2)*n*n/4;
s3 = 2*sqrt(p*(p-a)*(p-b)*(p-c));
s = s2 - (s1 - s3);
re = 2*s;
printf("%.2lf\n",re);
}
return 0;
}
Water problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1580 Accepted Submission(s): 568
Problem Description
If 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.
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.
Input
There 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.
For each test case: There is one positive integer not greater one thousand.
Output
For each case, print the number of letters would be used.
Sample Input
3 1 2 3
Sample Output
3 6 11
先同级不同的,再统计重复的
#include<stdio.h>
#include <map>
#include<cmath>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int b[1005];
int main()
{
int T,n;
b[1] = 3;
b[2] = 3;
b[3] = 5;
b[4] = 4;
b[5] = 4;
b[6] = 3;
b[7] = 5;
b[8] = 5;
b[9] = 4;
b[10] = 3;
b[11] = 6;
b[12] = 6;
b[13] = 8;
b[14] = 8;
b[15] = 7;
b[16] = 7;
b[17] = 9;
b[18] = 8;
b[19] = 8;
b[20] = 6;
b[30] = 6;
b[40] = 5;
b[50] = 5;
b[60] = 5;
b[70] = 7;
b[80] = 6;
b[90] = 6;
for(int i = 20; i < 100;i++)
{
int x = i%10;
int y = i/10;
if( x == 0) continue;
b[i] = b[y*10] + b[x];
}
for(int i =100 ;i <1000;i++)
{
int x = i%100;
int y = i/100;
if(x == 0)
{
b[i] = 7+ b[y];
continue;
}
b[i] =10 + b[y] +b[x];
}
b[1000] = 11;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
long long sum = 0;
scanf("%d",&n);
for(int i=1 ;i<=n;i++)
sum += b[i];
printf("%lld\n",sum);
}
return 0;
}