bzoj1570

一道挺裸的题~~~~

分层建图,常用技巧~~~~

最大流。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int amountt[3000];
int daytot = 0;
const int inf = 1000000000;
struct tedgee
{
	int from, to, cap;
};
tedgee tedge[3000];
struct edgee
{
	int from, to, cap;
	edgee(int f, int t, int cap) :from(f), to(t), cap(cap)
	{}
	edgee()
	{}
};
edgee edge[300000];
int first[150000], nextt[300000],tfirst[150000];
int edgetot;
int num[60][3000];
int n, m, allamount;
int day,all;
int height[150000];
void addedge(int from, int to,int cap)
{
	nextt[edgetot] = tfirst[from];
	tfirst[from] = edgetot;
	edge[edgetot++] = edgee(from, to, cap);
	nextt[edgetot] = tfirst[to];
	tfirst[to] = edgetot;
	edge[edgetot++] = edgee(to, from, 0);
}
bool bfs(int s, int t)
{
	for (int i = 0; i < day; i++)
	{
		height[i] =-1;
		first[i] = tfirst[i];
	}
	height[num[1][0]] = 0;
	queue<int>que;
	que.push(num[1][0]);
	while (!que.empty())
	{
		int now = que.front();
		que.pop();
		for (int i = tfirst[now]; i != -1; i = nextt[i])
		{
			int to = edge[i].to;
			if (height[to] == -1&&edge[i].cap > 0)
			{
				height[to] = height[now] + 1;
				que.push(to);
			}
		}
	}
	return height[t] == -1 ? false : true;
}
int dfs(int now, int cap,int t)
{
	if (now == t)
	{
		return cap;
	}
	for (int &i = first[now]; i != -1; i = nextt[i])
	{
		int to = edge[i].to;
		if (height[to] > height[now] && edge[i].cap > 0)
		{
			int d = dfs(to, min(cap, edge[i].cap), t);
			if (d > 0)
			{
				edge[i].cap -= d;
				edge[i ^ 1].cap += d;
				return d;
			}
		}
	}
	return 0;
}
bool flow(int s, int t)
{
	while (bfs(s, t))
	{
		int d = 0;
		while ((d = dfs(s, inf, t)))
		{
			all += d;
		}
	}
	return all >= allamount;
}
bool test(int dayy)
{
	for (int i = 1; i <= n; i++)
	{
		tfirst[day] = -1;
		num[i][dayy] = day++;
		addedge(num[i][dayy-1], num[i][dayy], inf);
	}
	int s = num[1][0]; int t = num[n][dayy];
	for (int i = 0; i < m; i++)
	{
		int from = tedge[i].from; int to = tedge[i].to; int cap = tedge[i].cap;
		addedge(num[from][dayy - 1], num[to][dayy], cap);
	}
	return flow(num[1][0], num[n][dayy]);
}
int main()
{
	scanf("%d%d%d", &n, &m, &allamount);
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d%d", &tedge[i].from, &tedge[i].to,&tedge[i].cap);
	}
	for (int i = 1; i <= n; i++)
	{
		tfirst[day] = -1;
		num[i][0] = day++;
	}
	int tday = 1;
	while (!test(tday))
		tday++;
	printf("%d\n", tday);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BZOJ 2908 题目是一个数据下载任务。这个任务要求下载指定的数据文件,并统计文件中小于等于给定整数的数字个数。 为了完成这个任务,首先需要选择一个合适的网址来下载文件。我们可以使用一个网络爬虫库,如Python中的Requests库,来帮助我们完成文件下载的操作。 首先,我们需要使用Requests库中的get()方法来访问目标网址,并将目标文件下载到我们的本地计算机中。可以使用以下代码实现文件下载: ```python import requests url = '目标文件的网址' response = requests.get(url) with open('本地保存文件的路径', 'wb') as file: file.write(response.content) ``` 下载完成后,我们可以使用Python内置的open()函数打开已下载的文件,并按行读取文件内容。可以使用以下代码实现文件内容读取: ```python count = 0 with open('本地保存文件的路径', 'r') as file: for line in file: # 在这里实现对每一行数据的判断 # 如果小于等于给定整数,count 加 1 # 否则,不进行任何操作 ``` 在每一行的处理过程中,我们可以使用split()方法将一行数据分割成多个字符串,并使用int()函数将其转换为整数。然后,我们可以将该整数与给定整数进行比较,以判断是否小于等于给定整数。 最后,我们可以将统计结果打印出来,以满足题目的要求。 综上所述,以上是关于解决 BZOJ 2908 数据下载任务的简要步骤和代码实现。 希望对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值