BZOJ 4004 [JLOI2015]装备购买 | 线性基
题目链接
题解
非常正常的线性基!
但是我不会线性基……
(吐槽:#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;
}
BZOJ 4004 [JLOI2015]装备购买 | 线性基的更多相关文章
- BZOJ 4004 [JLOI2015]装备购买 ——线性基
[题目分析] 题目很简单,就是要维护一个实数域上的线性基. 仿照异或空间的线性基的方法,排序之后每次加入一个数即可. 卡精度,开long double 和 1e-6就轻松水过了. [代码] #incl ...
- BZOJ 4004: [JLOI2015]装备购买
4004: [JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1154 Solved: 376[Submit][Statu ...
- bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消
4004: [JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 337 Solved: 139[Submit][Status ...
- bzoj 4004 [JLOI2015]装备购买 拟阵+线性基
[JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1820 Solved: 547[Submit][Status][Dis ...
- BZOJ 4004: [JLOI2015]装备购买 高斯消元解线性基
BZOJ严重卡精,要加 $long$ $double$ 才能过. 题意:求权和最小的极大线性无关组. 之前那个方法解的线性基都是基于二进制拆位的,这次不行,现在要求一个适用范围更广的方法. 考虑贪心 ...
- BZOJ 4004 JLOI2015 装备购买 高斯消元+线性基
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4004 Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装 ...
- BZOJ 4004: [JLOI2015]装备购买 [高斯消元同余 线性基]
和前两(一)题一样,不过不是异或方程组了..... 然后bzoj的新数据是用来卡精度的吧..... 所有只好在模意义下做啦 只是巨慢无比 #include <iostream> #incl ...
- bzoj 4004 [JLOI2015]装备购买——拟阵证明贪心+线性基
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004 看Zinn博客水过去…… 运用拟阵可以证明按价格从小到大买的贪心是正确的.但自己还不会 ...
- bzoj4004 [JLOI2015]装备购买——线性基+贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004 今天讲课讲到的题,据说满足拟阵的性质,所以贪心是正确的: 总之就贪心,按价格从小到大排 ...
随机推荐
- 【php增删改查实例】第十五节 - 用户管理模块(删除确认)
假如有一天,用户找到你,说万一不小心手一抖,就点击了删除用户,不太好.能不能再误点的时候,再给个确认框,让用户进行二次确认. OK,用户是上帝.这边我们可以考虑用confirm方法进行开发. 参考代码 ...
- springboot 中事件监听模型的一种实现
目录 定义事件本身 定义事件源 定义监听者 一.需要实现 ApplicationListener 二.使用 @EventListener 注解 测试 项目结构 前言: 事件监听模型是一种常用的设计模式 ...
- Docker容器学习梳理 - Volume数据卷使用
之前部署了Docker容器学习梳理--基础环境安装,接下来看看Docker Volume的使用. Docker volume使用 Docker中的数据可以存储在类似于虚拟机磁盘的介质中,在Docker ...
- 数组-在Shell脚本中的基本使用介绍
Shell脚本在运维工作中是极其重要的,而数组在shell脚本里的运用无论是在循环或运算方面都是非常实用的一个环节.下面是对shell脚本中数组方面一些操作在此进行记录,希望能帮助到有兴趣的朋友~1. ...
- 成功安装的Sublime Text3
安装指南 1:下载官网:https://www.sublimetext.com/3 2:安装指南:https://jingyan.baidu.com/article/b0b63dbfe1b8ff4a4 ...
- “北航学堂”M2阶段postmortem
“北航学堂”M2阶段postmortem 设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 这个问题我们在M1阶段的时候就已经探讨的比较明确了,就是 ...
- github第一次作业链接
https://github.com/xuhuzi/test/blob/master/test1 https://github.com/xuhuzi/test/blob/master/test2 ht ...
- github 心得体会
https://github.com/xu123/text 学习了很多知识感觉很有趣 git config :配置git git add:更新working directory中的文件至stagin ...
- 过滤器Filter的使用(以登录为例子)
使用过滤器步骤: (1)在web.xml文件中添加过滤器(以下例子是过滤多个请求) <!-- 用户登录过滤 --> <filter> <filter-name>lo ...
- squid反向代理
反向代理的作用是就爱那个网站中的静态自原本地化.也就是将一部分本应该有原是服务器处理的请求交给 Squid 缓存服务处理 编辑 Squid 服务程序的配置文件*(正向代理与反向代理不能同时使用,) ...