mengxiang000的龙

题目链接:

https://ac.nowcoder.com/acm/problem/15619

思路:

用数学方法列出两个方程组,解方程组时使用克拉默法则便可。

解题代码:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cmath>
 5 #include <string>
 6 #include <cstring>
 7 #include <map>
 8 using namespace std;
 9 const long long N = 1e9 + 7;
10 typedef long long ll;
11 
12 int main()
13 {
14     double x1,y1,x2,y2,A,B,C;
15     cin >> x1 >> y1 >> x2 >> y2 >> A >> B >> C;
16     double A1,A2,B1,B2,C1,C2;
17     A1 = -A;
18     B1 = B;
19     C1 = (B*x1-A*y1);
20     A2 = B;
21     B2 = A;
22     C2 = 2*C - A*x1 - B*y1;
23     double a,b;
24     b = ((C1 * B2)-(C2 * B1)) / ((A1 * B2)-(A2 * B1));
25     a = ((A1 * C2)-(A2 * C1)) / ((A1 * B2)-(A2 * B1));
26     A1 = A;
27     B1 = B;
28     C1 = C;
29     A2 = b - y2;
30     B2 = x2 - a;
31     C2 = b*x2 - a*y2;
32     double c,d;
33     c = ((C1 * B2)-(C2 * B1)) / ((A1 * B2)-(A2 * B1));
34     d = ((A1 * C2)-(A2 * C1)) / ((A1 * B2)-(A2 * B1));
35     printf("%.7f %.7f\n",c,d);
36     return 0;
37 }

 

上一篇:Java中的小数运算与精度损失


下一篇:模拟购物车