[POI2006]SZK-Schools
[POI2006]SZK-Schools
#include<bits/stdc++.h>
using namespace std;
const int N=405,M=1e5+5;
int re(){
int x=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*w;
}
int n,s,t,cnt=1,flow,ans;
int h[N],d[N],id[N],p[N];
queue<int>q;bool vis[N];
struct edge{int to,next,f,w;}e[M];
void link(int u,int v,int w){
e[++cnt]=(edge){v,h[u],1,w};h[u]=cnt;
e[++cnt]=(edge){u,h[v],0,-w};h[v]=cnt;
}
bool spfa(){
memset(d,63,sizeof(d));
q.push(s);d[s]=0;vis[s]=1;
while(!q.empty()){
int u=q.front();q.pop();vis[u]=0;
for(int i=h[u];i;i=e[i].next){
int v=e[i].to;
if(d[v]>d[u]+e[i].w&&e[i].f){
d[v]=d[u]+e[i].w;p[v]=u;id[v]=i;
if(!vis[v])vis[v]=1,q.push(v);
}
}
}
if(d[t]==d[t+1])return 0;
for(int i=t;i!=s;i=p[i])
e[id[i]].f--,e[id[i]^1].f++;
flow++;ans+=d[t];return 1;
}
int main(){
n=re();t=2*n+1;
for(int i=1,m,l,r,k;i<=n;i++){
m=re(),l=re(),r=re(),k=re();
link(s,i,0),link(i+n,t,0);
for(int j=l;j<=r;j++)link(i,j+n,k*abs(m-j));
}
while(spfa());
if(flow^n)puts("NIE");
else printf("%d\n",ans);
return 0;
}
[POI2006]SZK-Schools的更多相关文章
- POJ1236Network of Schools[强连通分量|缩点]
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16571 Accepted: 65 ...
- POJ 1236 Network of Schools(Tarjan缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16806 Accepted: 66 ...
- Network of Schools --POJ1236 Tarjan
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Description A number of schools are conne ...
- BZOJ 1121: [POI2008]激光发射器SZK
1121: [POI2008]激光发射器SZK Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 792 Solved: 653[Submit][Sta ...
- 【BZOJ-1121】激光发射器SZK 物理 + 数学 + 乱搞
1121: [POI2008]激光发射器SZK Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 682 Solved: 565[Submit][Sta ...
- POJ 1236 Network of Schools(强连通分量/Tarjan缩点)
传送门 Description A number of schools are connected to a computer network. Agreements have been develo ...
- POJ1236Network of Schools(强连通分量 + 缩点)
题目链接Network of Schools 参考斌神博客 强连通分量缩点求入度为0的个数和出度为0的分量个数 题目大意:N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后 ...
- [强连通分量] POJ 1236 Network of Schools
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16803 Accepted: 66 ...
- POJ1236 - Network of Schools tarjan
Network of Schools Time Limit: 1000MS Memory Limi ...
- POJ 1236 Network of Schools (Tarjan + 缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12240 Accepted: 48 ...
随机推荐
- Docker以及registry的入门学习安装
一.前言 如果你是数据中心或云计算IT圈子的人,我想你一定听过Docker,关于它们的新闻从未间断过.Docker的发展历程虽然算不上太长,但是自2014年6月Docker 1.0 正式发布,但是Do ...
- MSSQL站库分离情况的渗透思路
本文转自:http://bbs.blackbap.org/thread-6203-1-2.html 1. 服务器属内网环境,站库分离,通过web.config找到数据库服务库SA帐号密码,成功添加用户 ...
- eclipse maven tools.jar找不到y也就是在这个
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile ...
- vueAdmin使用动态路由时踩坑
在路由守护方法router.beforeEach中如果有使用动态路由,注意此时的路由对当前的router无效,下次路由时才起效. 导致的问题是---- 当页面刷新或重新打开页面时,无法找到当前路由(跳 ...
- DNS 取得授权
1.阿里云上cnroot.cn申请DNS解析服务器 也就是cnroot.cn下的子域名都从这个DNS上获取. 如www.cnroot.cn 如 handle.cnroot.cn 2.vi /home/ ...
- 程序员必备SQL语句优化技巧
1.任何地方都不要使用 select * from t ,用具体的字段列表代替"*",不要返回用不到的任何字段. 2.尽量使用数字型字段,字符型会降低查询和连接的性能,并会增加存储 ...
- 在eclipse中使用Maven建web工程的两种方式
Eclipse版本:Neon Release (4.6.0) Maven版本:3.3.9 第一种方式: 右键新建maven工程,勾选创建一个简单工程 填入信息,注意打包方式要改为war 点击完成,创建 ...
- 利用CFAbsoluteTimeGetCurrent()计算时间差
开发中,遇到计算时间差的问题,利用CFAbsoluteTimeGetCurrent()可以很方便的进行计算 实例: 场景:类似购物车中修改商品数量的功能,如下图所示,要求,修改完的数量,要同步到服务器 ...
- html实现网站全局按钮点击后置灰,不允许连续点击
<script> document.addEventListener("mouseup", upHandler, true); function upHandler(e ...
- linux 进程的 5 大段
BSS段:BSS段(bss segment)通常是指用来存放程序中数据段:数据段(data segment)通常是指用来存放程序中已初始化的全局变量的一块内存区域.数据段属于静态内存分配. 数据段:数 ...