HDU - 3347 Calculate the expression

You may find it’s easy to calculate the expression such as:
a = 3
b = 4
c = 5
a + b + c = ?
Isn’t it?

Input
The first line contains an integer stands for the number of test cases.
Each test case start with an integer n stands for n expressions will follow for this case.
Then n – 1 expressions in the format: [variable name][space][=][space][integer] will follow.
You may suppose the variable name will only contain lowercase letters and the length will not exceed 20, and the integer will between -65536 and 65536.
The last line will contain the expression you need to work out.
In the format: [variable name| integer][space][+|-][space][variable name| integer] …= ?
You may suppose the variable name must have been defined in the n – 1 expression and the integer is also between -65536 and 65536.
You can get more information from the sample.
Output
For each case, output the result of the last expression.
Sample Input

3
4
aa = 1
bb = -1
aa = 2
aa + bb + 11 = ?
1
1 + 1 = ?
1
1 + -1 = ?

Sample Output

12
2
0
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int inf=0x3f3f3f3f;//无穷大
#define PI acos(-1)

int main(){
    int t;
    double l, a, b, l1, l2, ans, c;
    while(scanf("%d", &t) != EOF){
        while(t--){
            scanf("%lf%lf%lf", &l, &a, &b);
            if(a < b)
            {
                int tem;
                tem = b;
                b = a;
                a = tem;
            }
            l1 = sqrt(2) * l;//printf("%.4f  ", l1);
            l2 = l1 / 2;
            c = b / 2;
            if(l1 < c){
                ans = l * l;
                printf("%.4f\n", ans);
            }
            else if(l2 >= c){
                ans = c * c;
                printf("%.4f\n", ans);
            }
            else if(l2 < c && l1 > c){
                ans = l * l - (l1 - c) * (l1 - c);
                printf("%.4f\n", ans);
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ling_wang/article/details/79595104