[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 ...
随机推荐
- block传值以及利用block封装一个网络请求类
1.block在俩个UIViewController间传值 近期刚学了几招block 的高级使用方法,事实上就是利用block语法在俩个UIViewController之间传值,在这里分享给刚開始学习 ...
- hibernate学习系列-----(1)开发环境搭建
其实一两个月前就在了解hibernate方面的知识了,但一直以来,都没有好好的总结,而且一直使用的是myeclipse,感觉有些傻瓜式的操作就可以搭建起hibernate的开发环境,但这样一点都不好, ...
- DeleteDC、ReleaseDC 、DeleteObject的使用
DeleteDC 该函数删除指定的设备上下文环境(DC). 原型: BOOL DeleteDC(HDC hdc): 参数: hdc:设备上下文环境的句柄. 返回值: 成功,返回非零值:失败,返回零.调 ...
- Java---24---基本数据类型对象包装类
基本数据类型对象包装类 byte Byte short short int Integer boolean Boolean float Float double Double char ...
- 【HTML5】summary交互元素
1.源码 <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"/> <tit ...
- 自制的React同构脚手架
代码地址如下:http://www.demodashi.com/demo/12575.html Web前端世界日新月异变化太快,为了让自己跟上节奏不掉队,总结出了自己的一套React脚手架,方便日后新 ...
- int a[3];中a+1与&a+1差别 -- C
int a[3]; a 和 &a 的地址一样的. a+1 == a + 1*sizeof(int);跳跃是一个数组元素大小 &a+1 == a + 3*sizeof(int);跳跃是整 ...
- 怎么以最新汇率牌价计算XX美元相当于多少人民币
http://www.meiguozhuji.com/exchange-rate 美国主机都是以美元来报价的,至于XX美元相当于多少人民币,很多朋友都不太清楚.为了让大家更直接的了解购买美国主机需要花 ...
- java游戏开发基础Swing之JRadioButton
© 版权声明:本文为博主原创文章,转载请注明出处 1.按钮(JButton) Swing中的按钮是JButton,它是javax.swing.AbstractButton类的子类,Swing中的按钮可 ...
- 【Linux 驱动】设备驱动程序再理解
学习设备驱动编程也有一段时间了,也写过了几个驱动程序,因此有对设备驱动程序有了一些新的理解和认识,总结一下.学习设备驱动编程也有一段时间了,也写过了几个驱动程序.因此有对设备驱动程序有了一些新的理解和 ...