[POI2006]SZK-Schools

luogu

#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的更多相关文章

  1. POJ1236Network of Schools[强连通分量|缩点]

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16571   Accepted: 65 ...

  2. POJ 1236 Network of Schools(Tarjan缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16806   Accepted: 66 ...

  3. Network of Schools --POJ1236 Tarjan

    Network of Schools Time Limit: 1000MS Memory Limit: 10000K Description A number of schools are conne ...

  4. BZOJ 1121: [POI2008]激光发射器SZK

    1121: [POI2008]激光发射器SZK Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 792  Solved: 653[Submit][Sta ...

  5. 【BZOJ-1121】激光发射器SZK 物理 + 数学 + 乱搞

    1121: [POI2008]激光发射器SZK Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 682  Solved: 565[Submit][Sta ...

  6. POJ 1236 Network of Schools(强连通分量/Tarjan缩点)

    传送门 Description A number of schools are connected to a computer network. Agreements have been develo ...

  7. POJ1236Network of Schools(强连通分量 + 缩点)

    题目链接Network of Schools 参考斌神博客 强连通分量缩点求入度为0的个数和出度为0的分量个数 题目大意:N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后 ...

  8. [强连通分量] POJ 1236 Network of Schools

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16803   Accepted: 66 ...

  9. POJ1236 - Network of Schools tarjan

                                                     Network of Schools Time Limit: 1000MS   Memory Limi ...

  10. POJ 1236 Network of Schools (Tarjan + 缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12240   Accepted: 48 ...

随机推荐

  1. Nginx auto_index和auth_basic

    Nginx auto_index和auth_basic 1.nginx auto_index nginx站点目录浏览功能,默认情况下为关闭 启用或禁用目录列表输出 开启这个功能的前提是站点目录下没有首 ...

  2. 2017.5.27 使用propagation实现:根据参数决定是否需要事务管理

    1.功能描述 要实现rest接口:POST ***/entry,其中参数中有action参数. 当action=rollback时,批量新增出错时需要回滚. 当action!=rollback时,批量 ...

  3. ASP.NET MVC生成安全验证码

    html部分: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  4. Notepad++搭配MinGW 配置编译运行C/C++

    1. Notepad++与Dev-Cpp都能编译运行, 环境变量的设置: 在PATH中加入"Dev-Cpp的MinGW64下的bin", 这是寻找gcc编译器的路径. 新建LIBR ...

  5. 笔记本中G-Sensor(加速计) M-Sensor 陀螺仪等传感器的区别与作用

    1.G-sensor重力传感器 作用 G-sensor中文是加速度传感器的意思(英文全称是Accelerometer-sensor),它能够感知到加速力的变化,加速力就是当物体在加速过程中作用在物体上 ...

  6. 在caffe中用训练好的 caffemodel 来分类新的图片所遇到的问题

    结合之前的博客: http://www.cnblogs.com/Allen-rg/p/5834551.html#3949333 用caffemodel去测试单通道的图像(mnist数据集)时,出现了问 ...

  7. 自己定义控件三部曲视图篇(二)——FlowLayout自适应容器实现

    前言:我最大的梦想,就是有一天.等老了坐在摇椅上回望一生,有故事给孩子们讲--. 相关文章: <Android自己定义控件三部曲文章索引>:http://blog.csdn.net/har ...

  8. 解决ubuntukylin 13.10安装wine时无法解决软件包依赖问题

    在ubuntukylin 13.10中,无论是在软件中心安装wine还是通过apt-get install安装wine都会出现软件包依赖问题且无法解决. 问题重现 在软件中心安装wine报错例如以下: ...

  9. oracle中提高order by的性能

    1.如果order by columnA,那么在where查询条件中添加条件columnA=value,则oracle内部会过滤order by排序,直接用索引(可以通过execution plan查 ...

  10. web开发中比较常用的html标签

    作为一名web开发人员,总结了一下经常用到的html标签,如下:<html> <head> <!--meta头标签 表示页面三秒后跳转到新浪页面--> <me ...