题目链接 : https://ac.nowcoder.com/acm/contest/206/A

  这个题去年有幸去秦皇岛参加集训,见过这道题,当时特别菜还不会网络流,现在学了一点发现这个网络流还是比较简单的。

  首先题意要求价值根据蜡烛数量有变化,因为数据不大,我们可以每个点多联几条变,写成第一区域连接汇点

  区域到汇点的流量为1,费用为1,3,5,7.。。。。,因为从小到大加和,和正好为x的平方,所以的边流量都为1,因为只可以走一次,最后从原点到汇点跑个网络流就可以了

  AC代码 :

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<vector>
#include<queue>
using namespace std;
#define INT_MAX 0x73f3f3f
typedef struct w_w{
int eend;
int weight;
int liu;
int next;
}miao;
miao x[];
int head[];
int cnt;
int money[];
int bian[];
int dian[];
int vis[];
queue<int> q1;
int spfa(int s,int e){
memset(bian,-,sizeof(bian));
memset(dian,-,sizeof(dian));
for(int i=;i<=;i++){
money[i]=INT_MAX;
}
money[e]=INT_MAX;
while(q1.size()) q1.pop();
q1.push(s);
money[s]=;
while(q1.size()){
int dang=q1.front();
//printf("%d\n",dang);
q1.pop();
vis[dang]=;
for(int i=head[dang];i!=-;i=x[i].next){
int to=x[i].eend;
int w=x[i].weight;
if(x[i].liu>&&money[dang]+w<money[to]){
money[to]=money[dang]+w;
if(vis[to]==) q1.push(to);
vis[to]=;
bian[to]=i;
dian[to]=dang;
//printf("%d %d %d\n",dang,i,to);
//system("pause");
}
}
}
if(money[e]!=INT_MAX) return ;
else return ;
}
void add(int s,int e,int l,int w){
x[cnt].eend=e;
x[cnt].weight=w;
x[cnt].liu=l;
x[cnt].next=head[s];
head[s]=cnt++;
}
int main()
{
int m,n;
scanf("%d %d",&m,&n);
memset(head,-,sizeof(head));
cnt=;
int start=;
int eend=;
for(int i=;i<=m;i++){
int a,b;
scanf("%d %d",&a,&b);
add(,n+i,,);
add(n+i,,,);
add(n+i,a,,);
add(a,n+i,,);
add(n+i,b,,);
add(b,n+i,,);
}
for(int i=;i<=n;i++){
for(int j=;j<n+;j++){
add(i,eend,,*j+);
add(eend,i,,-(*j+));
}
}
int sum=;
while(spfa(start,eend)){
//printf("+++\n");
int minn=INT_MAX;
for(int i=eend;i!=start;i=dian[i]){
int k=bian[i];
//printf("+++%d\n",i);
minn=min(minn,x[k].liu);
}
sum+=minn*money[eend];
for(int i=eend;i!=start;i=dian[i]){
int k=bian[i];
x[k].liu-=minn;
x[k^].liu+=minn;
//printf("%d\n",k);
}
}
printf("%d\n",sum);
return ;
}

牛客国庆day 6 A的更多相关文章

  1. 牛客国庆集训派对Day6 A Birthday 费用流

    牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...

  2. 2019牛客国庆集训派对day5

    2019牛客国庆集训派对day5 I.Strange Prime 题意 \(P=1e10+19\),求\(\sum x[i] mod P = 0\)的方案数,其中\(0 \leq x[i] < ...

  3. 牛客国庆集训派对Day1 L-New Game!(最短路)

    链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  4. 牛客国庆集训派对Day4 J-寻找复读机

    链接:https://www.nowcoder.com/acm/contest/204/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  5. 牛客国庆集训派对Day4 I-连通块计数(思维,组合数学)

    链接:https://www.nowcoder.com/acm/contest/204/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  6. 牛客国庆集训派对Day1-C:Utawarerumono(数学)

    链接:https://www.nowcoder.com/acm/contest/201/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  7. 牛客国庆集训派对Day2 Solution

    A    矩阵乘法 思路: 1° 牛客机器太快了,暴力能过. #include <bits/stdc++.h> using namespace std; #define N 5000 in ...

  8. 平衡二叉树 (牛客国庆day2)解锁二叉树打表姿势&&找规律套路

    链接:https://www.nowcoder.com/acm/contest/202/F来源:牛客网 平衡二叉树,顾名思义就是一棵“平衡”的二叉树.在这道题中,“平衡”的定义为,对于树中任意一个节点 ...

  9. 牛客国庆集训day5 B 电音之王 (大数乘模)

    链接:https://www.nowcoder.com/acm/contest/205/B来源:牛客网 题目描述 终于活成了自己讨厌的样子. 听说多听电音能加快程序运行的速度. 定义一个数列,告诉你a ...

  10. 牛客国庆集训day6 B Board (模拟标记思维或找规律或分块???)

    链接:https://www.nowcoder.com/acm/contest/206/B来源:牛客网 题目描述 恬恬有一个nx n的数组.她在用这个数组玩游戏: 开始时,数组中每一个元素都是0. 恬 ...

随机推荐

  1. mapreduce去重

    现有一个某电商网站的数据文件,名为buyer_favorite1,记录了用户收藏的商品以及收藏的日期,文件buyer_favorite1中包含(用户id,商品id,收藏日期)三个字段,数据内容以“\t ...

  2. python3.7安装Scrapy

    环境:windows 7. 安装过程中遇到的问题 1.error: Unable to find vcvarsall.bat 2.1083: Cannot open include file: 'ba ...

  3. Selenium+Python+Webdriver:保存截图到指定文件夹

    保存图片到指定文件夹: from selenium import webdriverfrom pathlib import Pathfrom time import sleepdriver = web ...

  4. Android中的时间格式的校验

    public class MainActivity extends Activity implements OnClickListener{ private Button btn1; private ...

  5. maya2012安装失败如何卸载重装

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  6. mysql初期使用全本

    mysql mysql前戏 数据库服务器-:运行数据库管理软件 =>pc 数据库管理软件:管理-数据库 => mysql 数据库:用来组织文件/表 => 文件夹 表:用来存放多行内容 ...

  7. Murano Weekly Meeting 2015.09.08

    Meeting time: 2015.September.8th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting su ...

  8. Java学习第十六天

    1:List的子类(掌握) (1)List的子类特点 ArrayList: 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector: 底层数据结构是数组,查询快,增删慢 线程安全,效率低 ...

  9. webgl学习总结画线面及场景和物体动

    WebGL是在浏览器中实现三维效果的一套规范.是浏览器中的3D引擎,是利用js代码来实现加载3D模型,渲染.输出等功能,从而实现在浏览器和微信中浏览三维文件的效果. three.js是基于WebGL的 ...

  10. js 去掉字符串前后空格5种方法

    第一种:循环检查替换 //供使用者调用 function trim(s){ return trimRight(trimLeft(s)); } //去掉左边的空白 function trimLeft(s ...