BZOJ 4004: [JLOI2015]装备购买
4004: [JLOI2015]装备购买
Time Limit: 20 Sec Memory Limit: 128 MB
Submit: 1154 Solved: 376
[Submit][Status][Discuss]
Description
Input
Output
一行两个数,第一个数表示能够购买的最多装备数量,第二个数表示在购买最多数量的装备的情况下的最小花费
Sample Input
1 2 3
3 4 5
2 3 4
1 1 2
Sample Output
HINT
Source
挺水的线性基裸题,只是把两个数的异或改成两行数的相消。
一开始怕double掉精度(只是不想用EPS),就写了个辗转相消,后来经短短等人的提示,发现会爆long long,所以,还是用long double吧。
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using std::fabs; typedef long double lng; const int mxn = ;
const lng eps = 1E-; int n, m; struct data
{
int c;
lng s[mxn];
}A[mxn], *B[mxn]; inline bool cmp(data *a, data *b)
{
return a->c < b->c;
} lng G[mxn][mxn]; inline bool insert(data *d)
{
for (int i = ; i <= m; ++i)
if (fabs(d->s[i]) > eps)
{
if (fabs(G[i][i]) > eps)
{
lng k = d->s[i] / G[i][i]; for (int j = i; j <= m; ++j)
d->s[j] -= G[i][j] * k;
}
else
{
for (int j = i; j <= m; ++j)
G[i][j] = d->s[j]; return true;
}
} return false;
} signed main(void)
{
scanf("%d%d", &n, &m); for (int i = ; i <= n; ++i)
for (int j = ; j <= m; ++j)
scanf("%d", &A[i].c), A[i].s[j] = A[i].c; for (int i = ; i <= n; ++i)
scanf("%d", &A[i].c), B[i] = A + i; std::sort(B + , B + n + , cmp); int cnt = , ans = ; for (int i = ; i <= n; ++i)
if (insert(B[i]))
++cnt, ans += B[i]->c; printf("%d %d\n", cnt, ans);
}
@Author: YouSiki
BZOJ 4004: [JLOI2015]装备购买的更多相关文章
- 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 装备购买 高斯消元+线性基
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4004 Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装 ...
- BZOJ 4004: [JLOI2015]装备购买 [高斯消元同余 线性基]
和前两(一)题一样,不过不是异或方程组了..... 然后bzoj的新数据是用来卡精度的吧..... 所有只好在模意义下做啦 只是巨慢无比 #include <iostream> #incl ...
- BZOJ 4004: [JLOI2015]装备购买 高斯消元解线性基
BZOJ严重卡精,要加 $long$ $double$ 才能过. 题意:求权和最小的极大线性无关组. 之前那个方法解的线性基都是基于二进制拆位的,这次不行,现在要求一个适用范围更广的方法. 考虑贪心 ...
- bzoj 4004 [JLOI2015]装备购买——拟阵证明贪心+线性基
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004 看Zinn博客水过去…… 运用拟阵可以证明按价格从小到大买的贪心是正确的.但自己还不会 ...
- BZOJ 4004 [JLOI2015]装备购买 | 线性基
题目链接 Luogu P3265 题解 非常正常的线性基! 但是我不会线性基-- (吐槽:#define double long double 才过--) #include <cstdio> ...
- BZOJ 4004 [JLOI2015]装备购买 ——线性基
[题目分析] 题目很简单,就是要维护一个实数域上的线性基. 仿照异或空间的线性基的方法,排序之后每次加入一个数即可. 卡精度,开long double 和 1e-6就轻松水过了. [代码] #incl ...
- 【BZOJ 4004】 装备购买(高斯消元+贪心)
装备购买 题目 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装备有 m 个属性,用向量zi(aj ,.....,am) 表示 (1 <= i <= n; 1 <= j ...
随机推荐
- 基于TLS证书手动部署kubernetes集群(上)
一.简介 Kubernetes是Google在2014年6月开源的一个容器集群管理系统,使用Go语言开发,Kubernetes也叫K8S. K8S是Google内部一个叫Borg的容器集群管理系统衍生 ...
- WPF编程,通过Double Animation动态缩放控件的一种方法。
原文:WPF编程,通过Double Animation动态缩放控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...
- [胡泽聪 趣题选讲]大包子环绕宝藏-[状压dp]
Description 你有一个长方形的地图,每一个格子要么是一个障碍物,要么是一个有一定价值的宝藏,要么是一个炸弹,或者是一块空地.你的初始位置已经给出.你每次可以走到上.下.左.右这四个相邻的格子 ...
- Caffe上手教程
Caffe上手教程 入门系列FAQ72 在Unbuntu上安装Caffe828 Windows下安装Caffe1.4K Caffe框架上手教程1.2K Caffe编译运行调试462 Caffe 电脑配 ...
- docker之搭建私有仓库
一.私有仓库 1.防止网络原因:下载慢,访问不到的情况,需要在内网搭建一个私有仓库. 二.仓库镜像下载 [root@node03 ~]# docker pull registry 三.创建私有仓库容器 ...
- 212. Space Replacement【LintCode by java】
Description Write a method to replace all spaces in a string with %20. The string is given in a char ...
- Apache Ignite 学习笔记(三): Ignite Server和Client节点介绍
在前两篇文章中,我们把Ignite集群当做一个黑盒子,用二进制包自带的脚本启动Ignite节点后,我们用不同的客户端连接上Ignite进行操作,展示了Ignite作为一个分布式内存缓存,内存数据库的基 ...
- Grin v0.5在Ubuntu下的安装和启动
Grin和bitcoin一样也是一种点对点的现金交易系统,但它通过零和验证算法,使得双方的交易金额不会被第三方知晓,让它在隐私保护方面更强.其官方的介绍是: 所有人的电子交易,没有审查或限制.并提出它 ...
- Linux内核的启动过程分析
秦鼎涛 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.实验目的及要求: 使用gdb跟踪调试内核从s ...
- Linux 第五周 实验: 分析system_call中断处理过程
姬梦馨 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 使用gdb跟踪分析一个系统调用内核函数 ...