bzoj4004 [JLOI2015]装备购买——线性基+贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004
今天讲课讲到的题,据说满足拟阵的性质,所以贪心是正确的;
总之就贪心,按价格从小到大排序,不能被表出就买上,计入答案,然后去消别的;
看博客说要用 long double,今天才第一次知道 long double 读入时是 %Lf 啊。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define eps 1e-6
using namespace std;
int const maxn=;
typedef long double ld;
int n,m,cnt,ans;
struct N{ld a[maxn]; int w;}t[maxn],p[maxn];
bool vis[maxn];
bool cmp(N x,N y){return x.w<y.w;}
void solve()
{
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
if(fabs(t[i].a[j])<eps)continue;
if(!vis[j])
{
vis[j]=;
p[j]=t[i];//j位置的装备
cnt++;
ans+=t[i].w;
break;
}
else//被消元
{
ld k=t[i].a[j]/p[j].a[j];
for(int l=;l<=m;l++)
t[i].a[l]-=k*p[j].a[l];
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%Lf",&t[i].a[j]);//%Lf!!
for(int i=;i<=n;i++)scanf("%d",&t[i].w);
sort(t+,t+n+,cmp);
solve();
printf("%d %d",cnt,ans);
return ;
}
bzoj4004 [JLOI2015]装备购买——线性基+贪心的更多相关文章
- BZOJ 4004 [JLOI2015]装备购买 | 线性基
题目链接 Luogu P3265 题解 非常正常的线性基! 但是我不会线性基-- (吐槽:#define double long double 才过--) #include <cstdio> ...
- BZOJ 4004 [JLOI2015]装备购买 ——线性基
[题目分析] 题目很简单,就是要维护一个实数域上的线性基. 仿照异或空间的线性基的方法,排序之后每次加入一个数即可. 卡精度,开long double 和 1e-6就轻松水过了. [代码] #incl ...
- BZOJ4004 [JLOI2015]装备购买[贪心+线性基+高消]
一个物品可以被其他物品表出,说明另外的每个物品看成矩阵的一个行向量可以表出该物品代表的行向量. 于是构造矩阵,求最多选多少个物品,就是尽可能用已有的物品去表示,相当于去消去一些没必要物品, 类似于xo ...
- 【题解】 bzoj4004: [JLOI2015]装备购买 (线性基)
bzoj4004,戳我戳我 Solution: 裸的线性基,这没啥好说的,我们说说有意思的地方(就是我老是wa的地方) Attention: 这题在\(luogu\),上貌似不卡精度,\(bzoj\) ...
- BZOJ4004: [JLOI2015]装备购买
总之就是线性基那一套贪心理论直接做就好了. 然而加强数据后很卡精度的样子. 于是重点在于这个特技:在整数模意义下搞. #include<cstdio> #include<algori ...
- [BZOJ4004][JLOI2015]装备购买(贪心+线性基)
求最小权极大线性无关组. 先将所有向量按权值排序,从小到大依次判断,若能被前面已选向量线性表出则不选,这样一定最优. 据说是用拟阵来证明,但感性理解一下感觉比较显然,首先这样个数一定是最多的,其次对于 ...
- bzoj 4004 [JLOI2015]装备购买——拟阵证明贪心+线性基
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004 看Zinn博客水过去…… 运用拟阵可以证明按价格从小到大买的贪心是正确的.但自己还不会 ...
- 【BZOJ4004】[JLOI2015]装备购买 贪心+高斯消元
[BZOJ4004][JLOI2015]装备购买 Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装备有 m 个属性,用向量zi(aj ,.....,am) 表示 ( ...
- BZOJ_4004_[JLOI2015]装备购买_线性基
BZOJ_4004_[JLOI2015]装备购买_线性基 Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装备有 m 个属性,用向量zi(aj ,.....,am) ...
随机推荐
- html5——表单
type类型 email //输入email格式 tel //手机号码 url //只能输入url格式 number //只能输入数字 search //搜索框 range //范围 滑动条 colo ...
- 【译】x86程序员手册16-5.3联合使用段与分页转换
5.3 Combining Segment and Page Translation 联合使用段与分页转换 Figure 5-12 combines Figure 5-2 and Figure 5- ...
- (转)Struts2的拦截器
http://blog.csdn.net/yerenyuan_pku/article/details/68648101 Struts2的拦截器 拦截器的概述 拦截器,在AOP(Aspect-Orien ...
- 用u盘安装黑苹果10.12.3
链接: https://pan.baidu.com/s/1eR9GgwE 密码: rubh 主机和显示器必须是数字口连接,如dvi.displayport,VGA不能进安装界面 下载苹果镜像文件10. ...
- lua_note_01_lua介绍
1. lua 1. lua 1.1. lua介绍 1.2. Lua 特性 1.3. 特点 1.4. Lua 应用场景 1.5. 环境搭建 1.6. VS lua 1.1. lua介绍 Lua 是一种轻 ...
- MySQL中是索引
MySQL中是索引: --.唯一索引: 一行中的内容不能一样, create t2( id int , num int, unique weiyisuiyin (id,num) ) --唯一; --约 ...
- VS单元测试"未能加载文件或程序集,或它的某一个依赖项"
Autofac.Core.DependencyResolutionException : An error occurred during the activation of a particular ...
- HTML学习笔记之标签基础
目录 1.基本标签 2.链接 3.图像 4.表格 5.列表 6.块与布局 1.基本标签 (1)标题与段落 标签 <h1> ~ <h6> 分别用于定义一至六级标题,标签 < ...
- Problem 34
Problem 34 https://projecteuler.net/problem=34 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 1 ...
- JavaSE 学习笔记之StringBuilder(十六)
< java.lang >-- StringBuilder字符串缓冲区:★★★☆ JDK1.5出现StringBuiler:构造一个其中不带字符的字符串生成器,初始容量为 16 个字符.该 ...