BZOJ 4004: [JLOI2015]装备购买 [高斯消元同余 线性基]
和前两(一)题一样,不过不是异或方程组了.....
然后bzoj的新数据是用来卡精度的吧.....
所有只好在模意义下做啦
只是巨慢无比
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long ll;
const int N=;
const int P=1e9+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,c,ans,cnt;
double eps=1e-;
struct Matrix{
ll a[N];
int c;
ll& operator[](int x){return a[x];}
bool operator <(const Matrix &r)const{return c<r.c;}
}a[N];
inline ll Pow(ll a,int b){
ll re=;
for(;b;b>>=,a=a*a%P)
if(b&) re=re*a%P;
return re;
}
inline ll Inv(ll a){return Pow(a,P-);}
bool check(Matrix &a){
for(int i=;i<=m;i++) if(a[i]) return true;
return false;
}
int pivot[N];
void Gauss(){
for(int i=;i<=n;i++){
for(int j=;j<=m;j++) if(a[i][j]){
if(pivot[j]){
int pj=pivot[j];
ll t=a[i][j]*Inv(a[pj][j])%P;
for(int k=;k<=m;k++) a[i][k]=(a[i][k]-t*a[pj][k]%P+P)%P;
}else{pivot[j]=i;break;}
}
if(check(a[i])) ans+=a[i].c,cnt++;
}
}
int main(){
freopen("in","r",stdin);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) for(int j=;j<=m;j++) a[i][j]=read();
for(int i=;i<=n;i++) a[i].c=read();
sort(a+,a++n);
Gauss();
printf("%d %d",cnt,ans);
}
BZOJ 4004: [JLOI2015]装备购买 [高斯消元同余 线性基]的更多相关文章
- BZOJ 4004 JLOI2015 装备购买 高斯消元+线性基
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4004 Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装 ...
- BZOJ 4004: [JLOI2015]装备购买 高斯消元解线性基
BZOJ严重卡精,要加 $long$ $double$ 才能过. 题意:求权和最小的极大线性无关组. 之前那个方法解的线性基都是基于二进制拆位的,这次不行,现在要求一个适用范围更广的方法. 考虑贪心 ...
- 【bzoj4568】[Scoi2016]幸运数字 树上倍增+高斯消元动态维护线性基
题目描述 A 国共有 n 座城市,这些城市由 n-1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个幸运数字,以纪念碑的形式矗立在这座城市的正中心,作为城市的象征.一些旅行者希望游 ...
- 【bzoj4184】shallot 线段树+高斯消元动态维护线性基
题目描述 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从小葱手里拿走一颗小葱苗,并且 让小葱从自己手中的小 ...
- bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消
4004: [JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 337 Solved: 139[Submit][Status ...
- BZOJ 4004: [JLOI2015]装备购买
4004: [JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1154 Solved: 376[Submit][Statu ...
- bzoj 4004 [JLOI2015]装备购买 拟阵+线性基
[JLOI2015]装备购买 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1820 Solved: 547[Submit][Status][Dis ...
- HDU3949:XOR(高斯消元)(线性基)
传送门 题意 给出n个数,任意个数任意数异或构成一个集合,询问第k大个数 分析 这题需要用到线性基,下面是一些资料 1.高斯消元&线性基&Matirx_Tree定理 笔记 2.关于线性 ...
- bzoj2115 [Wc2011] Xor——高斯消元 & 异或线性基
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2115 异或两次同一段路径的权值,就相当于没有走这段路径: 由此可以得到启发,对于不同的走法, ...
随机推荐
- 来说说datatype
今天敲代码一直卡在一个问题上面好久那就是--datatype的未定义,起初不晓得datatype的含义,遇到这种情况首先想到的就是自己又忘记加上面头文件了.随即写了个stdlib.h上去.可是问题并没 ...
- C#面试题整理(1)
最近在看CLR VIA C#,发现了一些案例很适合来做面试题.特此整理: 1,System.Object里的GetType方法是否为虚函数?说出理由. 答案:不是,因为C#是一种类型安全的语言,如果覆 ...
- Java客户端API
添加依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookee ...
- TPshop学习(8)微信支付
http://blog.csdn.net/phper8/article/details/76383415 学习内容: https://www.kancloud.cn/tpshop/thinkphp5/ ...
- bug 对应
异常1:not-null property references a null or transient value解决方法:将“一对多”关系中的“一”方,not-null设置为false http: ...
- Vue.js学习网址
Vue官网:http://cn.vuejs.org/v2/guide/index.html 淘宝镜像:http://npm.taobao.org/ Vue-router:https://router. ...
- oracle04_plsql
PLSQL:Procedural Language SQL (1) plsql的基本结构(a) declare id constant number(2):=2;--常量定义 name varchar ...
- arduino笔记
接下来,初来博客,准备自己也写一系列的arduino的学习经验. http://zhongbest.com/2017/05/23/arduino%e4%b8%ad%e7%9a%84%e4%b8%ad% ...
- scrapy_xpath
什么是xpath? 路径表达式 在xml和html中进行导航 包含标准函数库 遵循w3c标准 xpth节点关系是什么? 父节点 子节点 兄弟节点 先辈节点 后代节点 xpth语法 a ...
- Failed to connect to VMware Lookup Service……SSL certificate verification failed
今天登陆vsphere web-client时候,报错如下: Failed to connect to VMware Lookup Service https://vc-test.cebbank.co ...