题目链接

Luogu P3265

题解

非常正常的线性基!

但是我不会线性基……

(吐槽:#define double long double 才过……)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#define space putchar(' ')
#define enter putchar('\n')
typedef long long ll;
using namespace std;
template <class T>
void read(T &x){
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
} #define double long double const int N = 505;
const double eps = 1e-5;
int n, m, ins[N], ans, cnt;
struct vec {
int val;
double x[N];
bool operator < (const vec &b) const{
return val < b.val;
}
} a[N]; void gauss(){
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
if(fabs(a[i].x[j]) > eps){
if(!ins[j]){
cnt++, ans += a[i].val;
ins[j] = i;
break;
}
double rate = a[i].x[j] / a[ins[j]].x[j];
for(int k = m; k >= j; k--)
a[i].x[k] -= rate * a[ins[j]].x[k];
}
} int main(){ read(n), read(m);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
read(a[i].x[j]);
for(int i = 1; i <= n; i++)
read(a[i].val);
sort(a + 1, a + n + 1);
gauss();
write(cnt), space, write(ans), enter; return 0;
}

最新文章

  1. linux 下压缩大批量文件
  2. 进程内部异步事件调用组件Async-Event
  3. Microsoft Visual Studio 语言切换
  4. 使用 vmstat 监测系统性能
  5. QReadWriteLock上锁容忍的等待时间是多久?
  6. Objective-C之成魔之路【16-使用文件】
  7. 1.C#基础学习笔记3---C#字符串(转义符和内存存储无关)
  8. 初识Ubuntu
  9. [Codeforces 940E]Cashback
  10. Linux-安装Windows字体
  11. window.location.replace和window.location.href的区别
  12. 第二节 Python基础之变量,运算符,if语句,while和for循环语句
  13. java后台打开浏览器代码
  14. 面象对象设计原则之二:开放封闭原则(Open-Closed Principle, OCP)
  15. 「美团外卖APP签约快捷支付」流程体验
  16. oracle单行函数 之 数字函数
  17. Schiff Move Free维骨力这个牌子的保健效果怎么样,是要给中老年人群服用的
  18. 2.2.10数据类型String的常量池特性
  19. BZOJ3996:[TJOI2015]线性代数(最大权闭合子图)
  20. 2018.09.27 codeforces1045A. Last chance(线段树优化建图+最大流)

热门文章

  1. 一头雾水的"Follow The Pointer"
  2. BootStrap学习(1)
  3. Luogu P1337 [JSOI2004]平衡点 / 吊打XXX
  4. [Oracle]Oracle Fail Safe 与 SQLNET.AUTHENTICATION_SERVICES关系
  5. (理论篇)从基础文件IO说起虚拟内存,内存文件映射,零拷贝
  6. BugkuCTF web3
  7. json中获取key值
  8. mysql连接数设置操作(Too many connections)及设置md5值的加密密码
  9. restfull环境搭建-helloword(二)
  10. mariadb第二章-增删改