BZOJ 3265 志愿者招募加强版(单纯形)
2024-09-01 20:06:56
3265: 志愿者招募加强版
Time Limit: 20 Sec Memory Limit: 512 MB
Submit: 848 Solved: 436
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
3 3
2 3 4
1 1 2 2
1 2 3 5
1 3 3 2
2 3 4
1 1 2 2
1 2 3 5
1 3 3 2
Sample Output
14
HINT
题解:这一题类似于BZOJ1061,(几乎相同,只是把一段连续区间改为几段连续区间而已),做法一样,单纯形模板直接套就行;
具体看代码:
参考代码:
#include<bits/stdc++.h>
using namespace std;
#define cls(x, val) memset(x,val,sizeof(x))
#define RI register int
#define eps 1e-6
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int N=;
const int M=;
int n,m;
double a[M][N],b[M],c[M],v;
inline void pivot(int l,int e)//矩阵的转秩
{
b[l]/=a[l][e];
for(int j=;j<=n;++j)
{
if(j!=e) a[l][j]/=a[l][e];
}
a[l][e]=/a[l][e];
for(int i=;i<=m;++i)
{
if(i!=l&&fabs(a[i][e])>)
{
b[i]-=a[i][e]*b[l];
for(int j=;j<=n;++j)
{
if(j!=e) a[i][j]-=a[i][e]*a[l][j];
}
a[i][e]=-a[i][e]*a[l][e];
}
}
v+=c[e]*b[l];
for(int j=;j<=n;++j)
{
if(j!=e) c[j]-=c[e]*a[l][j];
}
c[e]=-c[e]*a[l][e];
} inline double simplex()
{
while()
{
int e=,l=;
for(e=;e<=n;++e)
{
if(c[e]>eps) break;
}
if(e==n+) return v;
double mn=INF;
for(int i=;i<=m;++i)
{
if(a[i][e]>eps&&mn>b[i]/a[i][e]) mn=b[i]/a[i][e],l=i;
}
if(mn==INF) return INF;
pivot(l,e);
}
} int main()
{
n=read(),m=read();
for(RI i=;i<=n;++i) c[i]=read();
for(RI i=;i<=m;++i)
{
RI k=read();
while(k--)
{
int s,t;
s=read(),t=read();
for(RI j=s;j<=t;++j) a[i][j]=1.0;
}
b[i]=read();
}
printf("%d\n",(int)(simplex()+0.5));
return ;
}
最新文章
- MongoDB使用锦集
- Windows消息大全(转)
- 解决安装sql server 需要重启问题
- 元素设置position:fixed属性后IE下宽度无法100%延伸
- python staticmethod classmethod
- Tomcat绑定多个IP地址 多域名绑定
- 03_RHEL7.1去掉注册提示
- POJ 1740 A New Stone Game(多堆博弈找规律)
- 简单聊聊不可或缺的Nginx反向代理服务器--实现负载均衡【上篇】
- <;input>;内容居中、去框、不可编辑等
- 帆软报表(finereport)实现自动滚屏效果
- CodeForces - 589B(暴力+排序)
- 利用Python 脚本生成 .h5 文件 代码
- Codeforces 960F - Pathwalks
- AIO编程
- ceph状态信息靠谱查询
- ios日期格式转换
- docker 下 mysql 集群的搭建
- Parallel Programming AND Asynchronous Programming
- js函数柯里化