[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 ...
随机推荐
- 系统封装 如何为原生PE集成软件
1 我们首先集成Explorer.老外的BSExplorer比较好用,下载之后得到这些文件,不算太大. 2 这里需要注意,前一章讲解如何打造原生PE已经制作成了ISO,这里想要集成软件还需要回到刚 ...
- 已加载“C:\Windows\SysWOW64\ntdll.dll”。无法查找或打开 PDB 文件。
“Win32Project3.exe”(Win32): 已加载“D:\software\VS2013\VS2013 文档\Win32Project3\Debug\Win32Project3.exe”. ...
- C连接MySql
连接数据库connect.c #include <stdio.h> #include <mysql/mysql.h> int main() { //MYSQL句柄 MYSQL ...
- JavaScript Array splice函数
// 原来的数组 var array = ["one", "two", "four"]; // splice(position, numbe ...
- Spring获取HttpServletRequest
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
- 修改EXCEL
import xlrdfrom xlutils import copy # 先用xlrd模块,打开一个excelbook=xlrd.open_workbook('app_student.xls') # ...
- JSON-Schema 最科学的表单验证模式
相关传送门: # JSON schema与表单验证 https://mp.weixin.qq.com/s?__biz=MjM5MTA1MjAxMQ==&mid=2651226711&i ...
- MySQL:ERROR 1067 (42000): Invalid default value for 'end_time'
© 版权声明:本文为博主原创文章,转载请注明出处 1.错误截图 2.错误分析 表中的第一个TIMESTAMP列(如果未声明为NULL或显示DEFAULT或ON UPDATE子句)将自动分配DEFAUL ...
- Ubuntu 16.04主题美化和软件推荐
http://www.linuxidc.com/Linux/2016-09/135165.htm http://www.techweb.com.cn/network/system/2015-11-20 ...
- python实现测试中常用的脚本(待完善)
一. Python操作MySQL数据库,简单的增删改查 # coding=utf-8 ''' Created on 2015年5月12日 @author: Administrator ''' impo ...