这个大毒瘤题....居然反向卡精度....
别的题eps要开小,这个毒瘤要开大...
我一开始是1e-12,挂的奇惨无比,50分......
然后改成1e-7,就70分了...
1e-5 90分 1e-4 AC
做法就是用高斯消元的变式,消出一个上三角形,然后把代价加起来就行了。
每次选择花费最小的主元来消。
如果这个位置是0,就横着挪一格。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include2 #include 3 #include 4 const int N = 505; 5 const double eps = 1e-4; 6 7 double a[N][N]; 8 int m, n; 9 10 inline void out() {11 for(int i = 1; i <= n; i++) {12 for(int j = 1; j <= m; j++) {13 printf("%lf ", a[i][j]);14 }15 printf("%.0lf \n", a[i][0]);16 }17 puts("");18 return;19 }20 21 inline void Gauss() {22 int i, t = 1;23 for(i = 1; i <= n; t++, i++) {24 if(t > m) {25 break;26 }27 for(int j = i; j <= n; j++) {28 if(fabs(a[i][t]) < eps && fabs(a[j][t]) > eps) {29 std::swap(a[i], a[j]);30 }31 else if(fabs(a[j][t]) > eps && a[j][0] < a[i][0]) {32 std::swap(a[i], a[j]);33 }34 }35 //out();36 if(fabs(a[i][t]) < eps) {37 i--;38 continue;39 }40 for(int j = i + 1; j <= n; j++) {41 double k = a[j][t] / a[i][t];42 for(int p = t; p <= m; p++) {43 a[j][p] -= k * a[i][p];44 }45 }46 //out();47 }48 i--;49 printf("%d ", i);50 double ans = 0;51 for(int j = 1; j <= i; j++) {52 ans += a[j][0];53 }54 printf("%.0lf", ans);55 return;56 }57 58 int main() {59 scanf("%d%d", &n, &m);60 for(int i = 1; i <= n; i++) {61 for(int j = 1; j <= m; j++) {62 scanf("%lf", &a[i][j]);63 }64 }65 for(int i = 1; i <= n; i++) {66 scanf("%lf", &a[i][0]);67 }68 //out();69 Gauss();70 return 0;71 }