[费用流专题]Going Home,Minimum Cost,工作安排

文章目录

  • T1:Going Home
    • 题目
    • 题解
    • CODE
  • T2:Minimum Cost
    • 题目
    • 题解
    • CODE
  • T3:工作安排
    • 题解
    • CODE

T1:Going Home

题目

On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step he moves, until he enters a house. The task is complicated with the restriction that each house can accommodate only one little man.

Your task is to compute the minimum amount of money you need to pay in order to send these n little men into those n different houses. The input is a map of the scenario, a ‘.’ means an empty space, an ‘H’ represents a house on that point, and am ‘m’ indicates there is a little man on that point.
在这里插入图片描述
You can think of each point on the grid map as a quite large square, so it can hold n little men at the same time; also, it is okay if a little man steps on a grid with a house without entering that house.
Input
There are one or more test cases in the input. Each case starts with a line giving two integers N and M, where N is the number of rows of the map, and M is the number of columns. The rest of the input will be N lines describing the map. You may assume both N and M are between 2 and 100, inclusive. There will be the same number of 'H’s and 'm’s on the map; and there will be at most 100 houses. Input will terminate with 0 0 for N and M.
Output
For each test case, output one line with the single integer, which is the minimum amount, in dollars, you need to pay.
Sample Input
2 2
.m
H.
5 5
HH…m



mm…H
7 8
…H…
…H…
…H…
mmmHmmmm
…H…
…H…
…H…
0 0
Sample Output
2
10
28

题解

简单题意就是一张图,HHH表示一间屋子,mmm表示一个人,现在每个人要走到一间屋子里,消耗的费用为两点之间的距离,求每个都有一个房子的最小耗费


是一道很裸的费用流问题,这里本蒟蒻选择了EK+SPFAEK+SPFAEK+SPFA
我们考虑建图问题,先建一个超级源点s和一个超级汇点t,然后将所有房子HHH和s建边,容量定义为1,边权免费,同理把所有人在的mmm和t建边,容量为1,边权免费
最后的边权决定于房子和人的搭配,这个边权就是矩阵里面两个点之间的距离,容量仍然是1,因为一人一间房
在这里插入图片描述

CODE

#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 1e9
#define MAXM 1000005
#define MAXN 100005
struct node {int v, w, next, c, flow;
}edge[MAXM];
queue < int > q;
vector < pair < int, int > > h, m;
//处理出每一个房子和人所在的位置,第一关键字是行,第二关键字是列
int cnt, N, M, s, t;
int head[MAXN], dis[MAXN], pre[MAXN];
bool vis[MAXN];void add ( int x, int y, int flow, int fi ) {edge[cnt].next = head[x];edge[cnt].v = y;edge[cnt].w = fi;edge[cnt].c = flow;edge[cnt].flow = 0;head[x] = cnt ++;	
}bool spfa () {memset ( vis, 0, sizeof ( vis ) ); memset ( dis, 0x7f, sizeof ( dis ) );memset ( pre, -1, sizeof ( pre ) );while ( ! q.empty() )q.pop();q.push( s );dis[s] = 0;vis[s] = 1;while ( ! q.empty() ) {int u = q.front();q.pop();vis[u] = 0;for ( int i = head[u];i != -1;i = edge[i].next ) {int v = edge[i].v;if ( dis[v] > dis[u] + edge[i].w && edge[i].c > edge[i].flow ) {dis[v] = dis[u] + edge[i].w;pre[v] = i;if ( ! vis[v] ) {q.push( v );vis[v] = 1;}}}} return pre[t] != -1;
}void MCMF ( int &maxflow, int &mincost ) {maxflow = mincost = 0;while ( spfa() ) {int MIN = INF;for ( int i = pre[t];i != -1;i = pre[edge[i ^ 1].v] )MIN = min ( MIN, edge[i].c - edge[i].flow );for ( int i = pre[t];i != -1;i = pre[edge[i ^ 1].v] ) {edge[i].flow += MIN;edge[i ^ 1].flow -= MIN;mincost += MIN * edge[i].w;}maxflow += MIN;}
}int Fabs ( int x ) {if ( x < 0 )return -x;return x;
}int main() {while ( scanf ( "%d %d", &N, &M ) ) {if ( N == 0 && M == 0 )return 0;memset ( head, -1, sizeof ( head ) );cnt = 0;h.clear();m.clear(); for ( int i = 1;i <= N;i ++ ) {getchar();for ( int j = 1;j <= M;j ++ ) {char ch;scanf ( "%c", &ch );if ( ch == 'H' )h.push_back( make_pair ( i, j ) );if ( ch == 'm' )m.push_back ( make_pair ( i, j ) );}}s = 0;t = N * M + 1;for ( int i = 0;i < h.size();i ++ ) {//与超级源点建边add ( s, ( h[i].first - 1 ) * M + h[i].second, 1, 0 );add ( ( h[i].first - 1 ) * M + h[i].second, s, 0, 0 );for ( int j = 0;j < m.size();j ++ ) {//屋子与人建边,算是一种hash吧,毕竟每一个人和每一件房子都是独一无二的add ( ( h[i].first - 1 ) * M + h[i].second, ( m[j].first - 1 ) * M + m[j].second, 1, Fabs ( h[i].first - m[j].first ) + Fabs ( h[i].second - m[j].second ) );add ( ( m[j].first - 1 ) * M + m[j].second, ( h[i].first - 1 ) * M + h[i].second, 0, - Fabs ( h[i].first - m[j].first ) - Fabs ( h[i].second - m[j].second ) );}}//与超级汇点建边for ( int i = 0;i < m.size();i ++ ) {add ( ( m[i].first - 1 ) * M + m[i].second, t, 1, 0 );add ( t, ( m[i].first - 1 ) * M + m[i].second, 0, 0 );}int maxflow, mincost;MCMF ( maxflow, mincost );printf ( "%d\n", mincost );}return 0;
} 

T2:Minimum Cost

题目

Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area there are N shopkeepers (marked from 1 to N) which stocks goods from him.Dearboy has M supply places (marked from 1 to M), each provides K different kinds of goods (marked from 1 to K). Once shopkeepers order goods, Dearboy should arrange which supply place provide how much amount of goods to shopkeepers to cut down the total cost of transport.

It’s known that the cost to transport one unit goods for different kinds from different supply places to different shopkeepers may be different. Given each supply places’ storage of K kinds of goods, N shopkeepers’ order of K kinds of goods and the cost to transport goods for different kinds from different supply places to different shopkeepers, you should tell how to arrange the goods supply to minimize the total cost of transport.
Input
The input consists of multiple test cases. The first line of each test case contains three integers N, M, K (0 < N, M, K < 50), which are described above. The next N lines give the shopkeepers’ orders, with each line containing K integers (there integers are belong to [0, 3]), which represents the amount of goods each shopkeeper needs. The next M lines give the supply places’ storage, with each line containing K integers (there integers are also belong to [0, 3]), which represents the amount of goods stored in that supply place.

Then come K integer matrices (each with the size N * M), the integer (this integer is belong to (0, 100)) at the i-th row, j-th column in the k-th matrix represents the cost to transport one unit of k-th goods from the j-th supply place to the i-th shopkeeper.

The input is terminated with three "0"s. This test case should not be processed.
Output
For each test case, if Dearboy can satisfy all the needs of all the shopkeepers, print in one line an integer, which is the minimum cost; otherwise just output “-1”.
Sample Input
1 3 3
1 1 1
0 1 1
1 2 2
1 0 1
1 2 3
1 1 1
2 1 1

1 1 1
3
2
20

0 0 0
Sample Output
4
-1

题解

其实这道题有点考语文,输入太**
在这里插入图片描述
我们考虑建一个超级源点和超级汇点,
在源点和店主的需求之间建一条边,没有中间商赚差价,容量自然就是店主的订单量,
同理在供应地点和超级汇点之间建一条边,也没有中间商赚差价,容量为供应地点生产的产品数;
最后就是店主与供应地点之间的建边,因为有kkk种不同的商品,所以一个供应地点跟一个店主之间的成本也会随着kkk的不一样而改变,两个解决办法
在这里插入图片描述
1.把一个供应地点拆成kkk个彼此独立的供应柜台,专门只销售一种类型的
由上面我们就可以发现,柜台之间是彼此独立的,互不影响,所以我们就有了第二种解决方案
2.把费用流拆成kkk次一种商品的费用流,每次费用流都只处理一种商品,这样建边就不那么冗长

CODE

#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 1e9
#define MAXN 100
struct node {int v, w, next, c, flow;
}edge[MAXN * MAXN];
queue < int > q;
int cnt, n, m, k, s, t;
int head[MAXN], dis[MAXN], pre[MAXN], need[MAXN][MAXN], num[MAXN][MAXN], matrix[MAXN][MAXN][MAXN];
bool vis[MAXN];void add ( int x, int y, int flow, int cost ) {edge[cnt].next = head[x];edge[cnt].v = y;edge[cnt].w = cost;edge[cnt].c = flow;edge[cnt].flow = 0;head[x] = cnt ++;	
}bool spfa () {memset ( vis, 0, sizeof ( vis ) ); memset ( dis, 0x7f, sizeof ( dis ) );memset ( pre, -1, sizeof ( pre ) );while ( ! q.empty() )q.pop();q.push( s );dis[s] = 0;vis[s] = 1;while ( ! q.empty() ) {int u = q.front();q.pop();vis[u] = 0;for ( int i = head[u];~ i;i = edge[i].next ) {int v = edge[i].v;if ( dis[v] > dis[u] + edge[i].w && edge[i].c > edge[i].flow ) {dis[v] = dis[u] + edge[i].w;pre[v] = i;if ( ! vis[v] ) {q.push( v );vis[v] = 1;}}}} return pre[t] != -1;
}void MCMF ( int &maxflow, int &mincost ) {maxflow = mincost = 0;while ( spfa() ) {int MIN = INF;for ( int i = pre[t];~ i;i = pre[edge[i ^ 1].v] )MIN = min ( MIN, edge[i].c - edge[i].flow );for ( int i = pre[t];~ i;i = pre[edge[i ^ 1].v] ) {edge[i].flow += MIN;edge[i ^ 1].flow -= MIN;mincost += MIN * edge[i].w;}maxflow += MIN;}
}int main() {while ( scanf ( "%d %d %d", &n, &m, &k ) != EOF ) {if ( n == 0 && m == 0 && k == 0 )return 0;int sum = 0;for ( int i = 1;i <= n;i ++ )for ( int j = 1;j <= k;j ++ ) {scanf ( "%d", &need[i][j] );sum += need[i][j];}for ( int i = 1;i <= m;i ++ )for ( int j = 1;j <= k;j ++ )scanf ( "%d", &num[i][j] );for ( int i = 1;i <= k;i ++ )for ( int j = 1;j <= n;j ++ )for ( int p = 1;p <= m;p ++ )scanf ( "%d", &matrix[i][j][p] );s = 0;t = n + m + 1;int result = 0, Flow = 0;for ( int i = 1;i <= k;i ++ ) {memset ( head, -1, sizeof ( head ) );cnt = 0;for ( int j = 1;j <= n;j ++ ) {add ( s, j, need[j][i], 0 );add ( j, s, 0, 0 );}for ( int j = 1;j <= n;j ++ )for ( int p = 1;p <= m;p ++ ) {add ( j, n + p, num[p][i], matrix[i][j][p] );add ( n + p, j, 0, -matrix[i][j][p] );}for ( int j = 1;j <= m;j ++ ) {add ( j + n, t, num[j][i], 0 );add ( t, j + n, 0, 0 );}int mincost, maxflow;MCMF ( maxflow, mincost );result += mincost;Flow += maxflow;}if ( Flow == sum )printf ( "%d\n", result );elseprintf ( "-1\n" );}return 0;
} 

T3:工作安排

你的公司接到了一批订单。订单要求你的公司提供n类产品,产品被编号为1n1~n1 n,其中第i类产品共需要Ci件。公司共有m名员工,员工被编号为1m1~m1 m员工能够制造的产品种类有所区别。一件产品必须完整地由一名员工制造,不可以由某名员工制造一部分配件后,再转交给另外一名员工继续进行制造。

我们用一个由0和1组成的m*n的矩阵A来描述每名员工能够制造哪些产品。矩阵的行和列分别被编号为1m1~m1 m1n1~n1 n,Ai,j为1表示员工i能够制造产品j,为0表示员工i不能制造产品j。

如果公司分配了过多工作给一名员工,这名员工会变得不高兴。我们用愤怒值来描述某名员工的心情状态。愤怒值越高,表示这名员工心情越不爽,愤怒值越低,表示这名员工心情越愉快。员工的愤怒值与他被安排制造的产品数量存在某函数关系,鉴于员工们的承受能力不同,不同员工之间的函数关系也是有所区别的。

对于员工i,他的愤怒值与产品数量之间的函数是一个Si+1段的分段函数。当他制造第1Ti1~Ti1 Ti,1件产品时,每件产品会使他的愤怒值增加Wi,1,当他制造第Ti,1+1Ti,2Ti,1+1~Ti,2Ti,1+1 Ti,2件产品时,每件产品会使他的愤怒值增加Wi,2……Wi,2……Wi,2为描述方便,设Ti,0=0,Ti,si+1=+∞,Ti,0=0,Ti,si+1=+∞,Ti,0=0,Ti,si+1=+那么当他制造第Ti,j−1+1Ti,jTi,j-1+1~Ti,jTi,j1+1 Ti,j件产品时,每件产品会使他的愤怒值增加Wi,j,1≤j≤Si+1Wi,j, 1≤j≤Si+1Wi,j1jSi+1

你的任务是制定出一个产品的分配方案,使得订单条件被满足,并且所有员工的愤怒值之和最小。由于我们并不想使用Special Judge,也为了使选手有更多的时间研究其他两道题目,你只需要输出最小的愤怒值之和就可以了。

Input
第一行包含两个正整数m和n,分别表示员工数量和产品的种类数;
第二行包含n 个正整数,第i个正整数为Ci;

以下m行每行n 个整数描述矩阵A;
下面m个部分,第i部分描述员工i的愤怒值与产品数量的函数关系。每一部分由三行组成:第一行为一个非负整数Si,第二行包含Si个正整数,其中第j个正整数为Ti,j,如果Si=0那么输入将不会留空行(即这一部分只由两行组成)。第三行包含Si+1个正整数,其中第j个正整数为Wi,j。

Output
仅输出一个整数,表示最小的愤怒值之和。

Sample Input
2 3
2 2 2
1 1 0
0 0 1
1
2
1 10
1
2
1 6
Sample Output
24

Hint
在这里插入图片描述

题解

考语文啊~~
在这里插入图片描述
这道题的提示,保证了愤怒值是单调递增的,就是费用流的关键,给我们的解题提供了保障
我们考虑对于一堆产品,第一阶段的产品生产的愤怒值一定小于后面阶段的产品生产的愤怒值,那么我们把愤怒值当成费用,我们一定会先选择第一阶段的流量边再选择第二阶段的流量边,这样就不会出现直接生产第二阶段导致我们的出错


那么我们就建一个超级源点和超级汇点,源点和员工之间连边,员工和产品之间连边,边数就是员工的愤怒阶段+1+1+1,最后一段是infinfinf,每个阶段对应的容量就是该阶段的产品数,费用就是愤怒值;最后是产品和汇点之间连边

CODE

#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 1e9
#define LL long long
#define MAXN 1005
struct node {int v, next;LL w, c, flow;
}edge[MAXN * MAXN];
queue < int > q;
int cnt, n, m, s, t;
int head[MAXN], pre[MAXN], C[MAXN], a[MAXN][MAXN], b[MAXN];
bool vis[MAXN];
LL dis[MAXN];void add ( int x, int y, LL flow, LL cost ) {edge[cnt].next = head[x];edge[cnt].v = y;edge[cnt].w = cost;edge[cnt].c = flow;edge[cnt].flow = 0;head[x] = cnt ++;	
}bool spfa () {memset ( vis, 0, sizeof ( vis ) ); memset ( dis, 0x7f, sizeof ( dis ) );memset ( pre, -1, sizeof ( pre ) );while ( ! q.empty() )q.pop();q.push( s );dis[s] = 0;vis[s] = 1;while ( ! q.empty() ) {int u = q.front();q.pop();vis[u] = 0;for ( int i = head[u];~ i;i = edge[i].next ) {int v = edge[i].v;if ( dis[v] > dis[u] + edge[i].w && edge[i].c > edge[i].flow ) {dis[v] = dis[u] + edge[i].w;pre[v] = i;if ( ! vis[v] ) {q.push( v );vis[v] = 1;}}}} return pre[t] != -1;
}void MCMF ( LL &maxflow, LL &mincost ) {maxflow = mincost = 0;while ( spfa() ) {LL MIN = INF;for ( int i = pre[t];~ i;i = pre[edge[i ^ 1].v] )MIN = min ( MIN, edge[i].c - edge[i].flow );for ( int i = pre[t];~ i;i = pre[edge[i ^ 1].v] ) {edge[i].flow += MIN;edge[i ^ 1].flow -= MIN;mincost += MIN * edge[i].w;}maxflow += MIN;}
}int main() {memset ( head, -1, sizeof ( head ) );scanf ( "%d %d", &m, &n );s = 0;t = n + m + 1;for ( int i = 1;i <= n;i ++ ) {scanf ( "%d", &C[i] );add ( s, i, C[i], 0 );add ( i, s, 0, 0 );}for ( int i = 1;i <= m;i ++ )for ( int j = 1;j <= n;j ++ ) {scanf ( "%d", &a[i][j] );if ( a[i][j] ) {add ( j, i + n, INF, 0 );add ( i + n, j, 0, 0 );}}for ( int i = 1;i <= m;i ++ ) {int S;scanf ( "%d", &S );for ( int j = 1;j <= S;j ++ )scanf ( "%d", &b[j] );b[S + 1] = INF;for ( int j = 1;j <= S + 1;j ++ ) {int w;scanf ( "%d", &w );add ( i + n, t, ( b[j] - b[j - 1] ), w );add ( t, i + n, 0, -w );}}LL maxflow, mincost;MCMF ( maxflow, mincost );printf ( "%lld", mincost );return 0;
} 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/318089.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2021牛客OI赛前集训营-提高组(第五场)C-第K排列【dp】

正题 题目链接:https://ac.nowcoder.com/acm/contest/20110/C 题目大意 一个长度为nnn的字符串SSS&#xff0c;SSS中存在一些???&#xff0c;有N/O/I/PN/O/I/PN/O/I/P四个字符作为字符集&#xff0c;每对相邻的字符会产生不同的贡献&#xff0c;现在要求所有权值不小于xxx…

Sky Garden

Sky Garden 题意&#xff1a; 画n个圆和m条直线&#xff0c;圆的中心点为(0,0)&#xff0c;圆的半径分别从1到n&#xff0c;而直线都必经过(0,0)点&#xff0c;并且所有直线会把每个圆平均分成2m个面积相等的区域&#xff0c;直线会和圆形成交点&#xff0c;求所有交点两两经…

IdentityServer4-前后端分离的授权验证(六)

上两节介绍完Hybrid模式在MVC下的使用&#xff0c;包括验证从数据获取的User和Claim对MVC的身份授权。本节将介绍Implicit模式在JavaScript应用程序中的使用&#xff0c;使用Node.jsExpress构建JavaScript客户端&#xff0c;实现前后端分离。本节授权服务和资源服务器基于第四和…

YBTOJ洛谷P4055:游戏(二分图匹配)

文章目录解析解析代码解析 题目描述 小 AA 和小 YY 得到了《喜羊羊和灰太狼》的电影票&#xff0c;都很想去观看&#xff0c;但是电影票只有一张&#xff0c;于是他们用智力游戏决定胜负&#xff0c;赢得游戏的人可以获得电影票。 在 N \times MNM 的迷宫中有一个棋子&#x…

人类智慧贪心

题意看起来很清新&#xff0c;代码实现也基本在入门难度&#xff0c;但是为什么我不会&#xff01; 另&#xff1a;反悔贪心 <details><summary>$\texttt{solution}$</summary></details> P2672 [NOIP2015 普及组] 推销员 $\texttt{solution}$ 发现答案…

2021牛客OI赛前集训营-提高组(第五场)D-牛牛的border【SAM】

正题 题目链接:https://ac.nowcoder.com/acm/contest/20110/D 题目大意 求一个长度为nnn的字符串的所有子串的borderborderborder长度和。 1≤n≤1051\leq n\leq 10^51≤n≤105 解题思路 考虑到两个相同的子串会作为一个子串的borderborderborder&#xff0c;所以问题可以变…

周末狂欢赛3(跳格子,英雄联盟,排序问题)

文章目录T1&#xff1a;跳格子题目题解CODET2&#xff1a;英雄联盟题目题解CODET3&#xff1a;排序问题题目题解CODET1&#xff1a;跳格子 题目 n 个格子排成一列&#xff0c;一开始&#xff0c;你在第一个格子&#xff0c;目标为跳到第 n 个格子。在每个格子 i 里面你可以做…

YBTOJ洛谷P4298:祭祀(二分图匹配)

文章目录题目描述解析解析题目描述 在遥远的东方&#xff0c;有一个神秘的民族&#xff0c;自称Y族。他们世代居住在水面上&#xff0c;奉龙王为神。每逢重大庆典&#xff0c; Y族都会在水面上举办盛大的祭祀活动。我们可以把Y族居住地水系看成一个由岔口和河道组成的网络。每…

想让AI在企业落地?微软最新Azure AI不容错过!

Microsoft Connect(); 2018 如期举行&#xff0c;大会上发布的众多顶尖技术&#xff0c;瞬间引爆了全球&#xff01;AI的高速发展&#xff0c;正在掀起新一波的创新浪潮。对于很多企业来说&#xff0c;AI创造的巨大价值&#xff0c;是不容错过的风口&#xff0c;大会上&#xf…

点分治

点分治常用于树上路径统计等问题。 点分治 每次分治过程大致如下&#xff1a; 我们先求出当前连通块树的重心&#xff1b; 处理与重心有关的答案&#xff1b; 删除重心 递归处理与重心相连的子连通块。 伪代码如下&#xff1a; void solve(int x) {Find1(x,0),Find2(x,0); …

P1852-跳跳棋【思维,差分,二分】

正题 题目链接:https://www.luogu.com.cn/problem/P1852 题目大意 一个数轴上有333个跳棋&#xff0c;你每次可以将一个跳棋跳到另一个跳棋对称的位置&#xff0c;但是不能一次跨过两个棋子。给出初始状态&#xff0c;和目标状态&#xff0c;求最小步数。 坐标的绝对值不超过…

[费用流]数字配对,新生舞会

文章目录T1&#xff1a;数字配对题目题解CODET2&#xff1a;新生舞会题目题解CODE&#xff08;最大费用最大流版&#xff09;CODE&#xff08;最小费用最大流版&#xff09;T1&#xff1a;数字配对 题目 有 n 种数字&#xff0c;第 i 种数字是 ai、有 bi 个&#xff0c;权值是…

AcWing 253. 普通平衡树

您需要写一种数据结构&#xff08;可参考题目标题&#xff09;&#xff0c;来维护一些数&#xff0c;其中需要提供以下操作&#xff1a; 插入数值x。删除数值x(若有多个相同的数&#xff0c;应只删除一个)。查询数值x的排名(若有多个相同的数&#xff0c;应输出最小的排名)。查…

.NET Core实战项目之CMS 第十三章 开发篇-在MVC项目结构介绍及应用第三方UI

作为后端开发的我来说&#xff0c;前端表示真心玩不转&#xff0c;你如果让我微调一个位置的样式的话还行&#xff0c;但是让我写一个很漂亮的后台的话&#xff0c;真心做不到&#xff0c;所以我一般会选择套用一些开源UI模板来进行系统UI的设计。那如何套用呢&#xff1f;今天…

YBTOJ:伞兵空降(二分图匹配)

文章目录题目描述解析代码题目描述 有n个点和m条边的有向无环图&#xff0c;在这张图上的某些点上空投伞兵&#xff0c;使伞兵可以走到图上所有的点。 且每个点只能被一个伞兵走一次。问至少需要放多少伞兵。 解析 考虑一开始给每个点分配一个伞兵&#xff0c;最差就是这样n…

CF388C-Fox and Card Game【博弈论,结论】

正题 题目链接:https://www.luogu.com.cn/problem/CF388C 题目大意 有nnn堆卡片&#xff0c;第iii堆有sis_isi​张&#xff0c;给出每张卡的权值。现在先手选择一堆取走堆底的牌&#xff0c;然后后手选择一堆取走堆顶的牌&#xff0c;直到所有牌被取走。在双方都要求最大化取…

[FFT/IFFT]快速傅里叶(逆)变化 + 递归和递推模板

现在时间是2021-2-2&#xff0c;重新回来看2019学习的一知半解的FFTFFTFFT&#xff0c;又有了新的理解 所以修改了以往写过的文章&#xff0c;并增添些许内容 因为过去一年多&#xff0c;上了高中&#xff0c;学的知识多了些&#xff0c;以前不懂的有些东西现在看来挺简单的&am…

软件开发模式:瀑布与敏捷

瀑布和敏捷不是什么新概念&#xff0c;这里只是个人在团队合作中不得不去思考而做的归纳和总结&#xff0c;同时记录自己曾经踩过的坑&#xff0c;新瓶装旧酒&#xff0c;希望对你有所启发。瀑布模式瀑布模型是比较传统一种开发模式&#xff0c;特别是在2B的传统企业&#xff0…

257. 关押罪犯

题意&#xff1a; S城现有两座监狱&#xff0c;一共关押着N名罪犯&#xff0c;编号分别为1~N。他们之间的关系自然也极不和谐。很多罪犯之间甚至积怨已久&#xff0c;如果客观条件具备则随时可能爆发冲突。我们用“怨气值”&#xff08;一个正整数值&#xff09;来表示某两名罪…

AC 自动机

比我小一届却吊打我的大脚玩家(djwj233)的博客 什么是 AC 自动机 AC 自动机是一种多模匹配算法&#xff0c;就是解决 多个模式串 匹配 单个/多个 文本串用的。 AC 自动机的过程 P3808 【模板】AC 自动机(简单版) 总的来说&#xff0c;AC 自动机类似将所有串跑一个 KMP。 看到有…