POJ2378——Tree Cutting

Distance Statistics
Time Limit: 2000MS Memory Limit: 64000K
Total Submissions: 1660 Accepted: 528
Case Time Limit: 1000MS

Description

Frustrated at the number of distance queries required to find a reasonable route for his cow marathon, FJ decides to ask queries from which he can learn more information. Specifically, he supplies an integer K (1 <= K <= 1,000,000,000) and wants to know how many pairs of farms lie at a distance at most K from each other (distance is measured in terms of the length of road required to travel from one farm to another). Please only count pairs of distinct farms (i.e. do not count pairs such as (farm #5, farm #5) in your answer).

Input

* Lines 1 ..M+1: Same input format as in "Navigation Nightmare"

* Line M+2: A single integer, K.

Output

* Line 1: The number of pairs of farms that are at a distance of at most K from each-other.

Sample Input

7 6
1 6 13 E
6 3 9 E
3 5 7 S
4 1 3 N
2 4 20 W
4 7 2 S
10

Sample Output

5

Hint

There are 5 roads with length smaller or equal than 10, namely 1-4 (3), 4-7 (2), 1-7 (5), 3-5 (7) and 3-6 (9).

Source

USACO 2004 February


求树的重心,只要判断拿掉重心以后,其余每一部分点数的最大值是否超过一半,如果超过,则输出NONE,否则输出所有的重心

 /*  
    定义dp[i]为去掉i结点,剩下的树里,结点最多的那颗树的结点数。  
    可分为2类情况。  
    1、由于i结点的儿子结点都成了一棵树的根节点,所以dp[i] = (i的每个儿子所拥有的结点数,的最大值)。  
    2、而另一种情况就是剩下的那棵树,所以dp[i] = N-num[i]。  
    其中num[i]表示以i为根的树的所有结点数,可以dfs求出。  
*/ 
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 50010;
const int inf = 0x3f3f3f3f;
int n;

struct node
{
	int next;
	int to;
}edge[N << 1];

int zhonxin[N];
int head[N];
int dp[N];
int num[N];
int tot;
bool vis[N];
int dist[N];

void addedge(int from, int to)
{
	edge[tot].to = to;
	edge[tot].next = head[from];
	head[from] = tot++;
}

int dfs(int u)
{
	vis[u] = 1;
	num[u] = 1;
	for (int i = head[u]; ~i; i = edge[i].next)
	{
		int v = edge[i].to;
		if (!vis[v])
		{
			num[u] += dfs(v);
		}
	}
	return num[u];
}

void DP(int u)
{
	vis[u] = 1;
	for (int i = head[u]; ~i; i = edge[i].next)
	{
		int v = edge[i].to;
		if (vis[v])
		{
			dp[u] = max(dp[u], n - num[u]);
		}
		else
		{
			dp[u] = max(dp[u], num[v]);
			DP(v);
		}
	}
}

int main()
{
	int u, v;
	while (~scanf("%d", &n))
	{
		memset ( head, -1, sizeof(head) );
		memset ( num, 0, sizeof(num) );
		memset ( vis, 0, sizeof(vis) );
		memset ( dp, 0, sizeof(dp) );
		tot = 0;
		for (int i = 0; i < n - 1; ++i)
		{
			scanf("%d%d", &u, &v);
			addedge(u, v);
			addedge(v, u);
		}
		dfs(1);
		memset ( vis, 0, sizeof(vis) );
		DP(1);
		int ans = inf;
		for (int i = 1; i <= n; ++i)
		{
			if (ans > dp[i])
			{
				ans = dp[i];
			}
		}
		int res = 0;
		for (int i = 1; i <= n; ++i)
		{
			if (ans == dp[i])
			{
				zhonxin[res++] = i;
			}
		}
		if (ans > n / 2)
		{
			printf("NONE\n");
			continue;
		}
		for (int i = 0; i < res; ++i)
		{
			printf("%d\n", zhonxin[i]);
		}
	}
	return 0;
}


电动汽车集群并网的分布式鲁棒优化调度模型(Matlab代码实现)内容概要:本文围绕“电动汽车集群并网的分布式鲁棒优化调度模型”展开,基于Matlab代码实现,旨在应对电动汽车大规模接入电网带来的不确定性挑战。通过构建分布式鲁棒优化模型,充分考虑电动汽车充电负荷的随机性与波动性,在保证电网安全稳定运行的前提下,优化调度方案以降低运行成本、提升能源利用效率。文中结合博士论文复现背景,详细阐述了模型构建、算法设计及仿真验证过程,并提供了完整的代码资源支持,体现了较强的理论深度与工程实践价值。此外,文档还列举了大量相关研究主题,涵盖微电网优化、需求响应、储能调度等多个方向,突出其在综合能源系统优化中的典型应用场景。; 适合人群:具备一定电力系统、优化理论及Matlab编程基础的研究生、科研人员及从事新能源并网、智能电网调度等相关领域的工程技术人员;尤其适合开展电动汽车调度、鲁棒优化建模等课题研究的高年级本科生与博士生。; 使用场景及目标:①复现并深入理解电动汽车集群并网的分布式鲁棒优化调度方法;②掌握Matlab在电力系统优化中的建模与求解技巧;③为科研论文撰写、课题申报及实际项目开发提供算法参考与代码基础;④拓展至其他分布鲁棒优化问题的研究与应用。; 阅读建议:建议结合提供的Matlab代码逐模块学习,重点理解目标函数构建、不确定集合设定、ADMM等分布式求解算法的实现逻辑。同时可参照文档中列出的相关案例进行对比分析,提升综合建模能力。注意区分集中式与分布式优化架构差异,加强对鲁棒性与计算效率平衡的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值