BZOJ 3265: 志愿者招募加强版 [单纯形法]
2024-10-11 09:47:14
一个人多段区间,一样....
不过国家队论文上说这道题好像不能保证整数解....
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=,M=1e4+;
const double INF=1e15,eps=1e-;
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;
double a[M][N];
int q[N];
void Pivot(int l,int e){
double t=a[l][e];a[l][e]=;
for(int j=;j<=n;j++) a[l][j]/=t;
int p=;
for(int j=;j<=n;j++) if(abs(a[l][j])>eps) q[++p]=j;
for(int i=;i<=m;i++) if(i!=l && abs(a[i][e])>eps){
double t=a[i][e];a[i][e]=;
for(int j=;j<=p;j++) a[i][q[j]]-=t*a[l][q[j]];
}
}
void simplex(){
while(true){
int l=,e=; double mn=INF;
for(int j=;j<=n;j++) if(a[][j]>eps) {e=j;break;}
if(!e) return;
for(int i=;i<=m;i++)
if(a[i][e]>eps && a[i][]/a[i][e]<mn) {mn=a[i][]/a[i][e];l=i;}
if(!l) return;//unbounded
Pivot(l,e);
}
}
int main(){
freopen("in","r",stdin);
n=read();m=read();
for(int i=;i<=n;i++)a[][i]=read();
for(int i=;i<=m;i++){
int k=read();
while(k--){
int l=read(),r=read();
for(int j=l;j<=r;j++) a[i][j]=;
}
a[i][]=read();
}
simplex();
printf("%d",int(-a[][]+0.5));
}
最新文章
- Odoo Graph 指定默认 类型
- Chrome54安装最新版Flash版本办法
- 解析window.open链接的参数
- qt-5.6.0 移植之实现板子与ubuntu主机通过网络进行文件传输
- 对只转发结果集的无效操作 first
- Java for LeetCode 033 Search in Rotated Sorted Array
- java几道简单的面试题目
- VBS_For Each...Next
- 图片加载js类库
- 每日一练--C语言--串
- C语言运算符优先级表
- 时间处理总结(二)oracle
- Ant自动构建
- IIS7.0发布后关于";不能在此路径中使用此配置节”的解决办法
- selenium框架与chrome浏览器的不兼容问题
- 解决弹出蒙层滑动穿透问题-vue
- inittab文件剖析[CentOS 5.X](第二版)
- hibernate关系映射
- dubbo协议报文格式
- jvm排查问题常用命令及注释