UVa 247 Calling Circles

本文深入探讨了电话公司在提供服务与降低成本方面的新策略——‘电话圈’概念。通过分析不同电话公司的策略,特别是LibertyBellPhoneCo.的创新方法,我们了解到如何通过智能圈选技术优化客户沟通渠道,实现更高效的服务与成本控制。文章详细解释了电话圈的定义、工作原理以及其背后的算法逻辑,旨在帮助读者理解这一新兴技术如何重塑电话服务行业。


 Calling Circles 

If you've seen television commercials for long-distance phone companies lately, you've noticed that many companies have been spending a lot of money trying to convince people that they provide the best service at the lowest cost. One company has ``calling circles." You provide a list of people that you call most frequently. If you call someone in your calling circle (who is also a customer of the same company), you get bigger discounts than if you call outside your circle. Another company points out that you only get the big discounts for people in your calling circle, and if you change who you call most frequently, it's up to you to add them to your calling circle.

LibertyBell Phone Co. is a new company that thinks they have the calling plan that can put other companies out of business. LibertyBell has calling circles, but they figure out your calling circle for you. This is how it works. LibertyBell keeps track of all phone calls. In addition to yourself, your calling circle consists of all people whom you call and who call you, either directly or indirectly.

For example, if Ben calls Alexander, Alexander calls Dolly, and Dolly calls Ben, they are all within the same circle. If Dolly also calls Benedict and Benedict calls Dolly, then Benedict is in the same calling circle as Dolly, Ben, and Alexander. Finally, if Alexander calls Aaron but Aaron doesn't call Alexander, Ben, Dolly, or Benedict, then Aaron is not in the circle.

You've been hired by LibertyBell to write the program to determine calling circles given a log of phone calls between people.

Input

The input file will contain one or more data sets. Each data set begins with a line containing two integers, n and m. The first integer, n, represents the number of different people who are in the data set. The maximum value for n is 25. The remainder of the data set consists of m lines, each representing a phone call. Each call is represented by two names, separated by a single space. Names are first names only (unique within a data set), are case sensitive, and consist of only alphabetic characters; no name is longer than 25 letters.

For example, if Ben called Dolly, it would be represented in the data file as

Ben Dolly

Input is terminated by values of zero (0) for n and m.

Output

For each input set, print a header line with the data set number, followed by a line for each calling circle in that data set. Each calling circle line contains the names of all the people in any order within the circle, separated by comma-space (a comma followed by a space). Output sets are separated by blank lines.

Sample Input

5 6
Ben Alexander
Alexander Dolly
Dolly Ben
Dolly Benedict
Benedict Dolly
Alexander Aaron
14 34
John Aaron
Aaron Benedict
Betsy John
Betsy Ringo
Ringo Dolly
Benedict Paul
John Betsy
John Aaron
Benedict George
Dolly Ringo
Paul Martha
George Ben
Alexander George
Betsy Ringo
Alexander Stephen
Martha Stephen
Benedict Alexander
Stephen Paul
Betsy Ringo
Quincy Martha
Ben Patrick
Betsy Ringo
Patrick Stephen
Paul Alexander
Patrick Ben
Stephen Quincy
Ringo Betsy
Betsy Benedict
Betsy Benedict
Betsy Benedict
Betsy Benedict
Betsy Benedict
Betsy Benedict
Quincy Martha
0 0

Sample Output

Calling circles for data set 1:
Ben, Alexander, Dolly, Benedict
Aaron

Calling circles for data set 2:
John, Betsy, Ringo, Dolly
Aaron
Benedict
Paul, George, Martha, Ben, Alexander, Stephen, Quincy, Patrick

#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <iostream>
using namespace std;

// d[i][j] = 1 代表第i个点可达第j个点,否则不可达
int d[30][30];


int n, m;

// my_map[i]为名字为i的对应点编号
map<string, int> my_map;

// table[i]为对应第i个点的名字
string table[30];


// visit[i] = 1代表第i个点被遍历过
int visit[30];


int main()
{
	int count = 1;
	while(cin >> n >> m && !(n == 0 && m == 0))
	{
		my_map = map<string, int>();
		memset(d, 0, sizeof(d));
		memset(visit, 0, sizeof(visit));
		
		// 读入图
		int num = 1;
		string x, y;
		for(int i = 1; i <= m; i++)
		{
			cin >> x >> y;
			int s, t;
			if(my_map.find(x) == my_map.end())	
			{
				my_map[x] = num;
				s = num;
				table[num] = x;
				num++;				
			}
			else
				s = my_map[x];
			if(my_map.find(y) == my_map.end())
                        {
                                my_map[y] = num;  
                                t = num;
				table[num] = y;
                                num++;
                        }
                        else
                                t = my_map[y];

			d[s][t] = 1;	
		}	

		// 用Floyd算法计算传递闭包
		for(int k = 1; k <= n; k++)
			for(int i = 1; i <= n; i++)
				for(int j = 1; j <= n; j++)
					d[i][j] = (d[i][j] || (d[i][k] && d[k][j]));

		
		// 打印结果
		if(count > 1)
			printf("\n");
		printf("Calling circles for data set %d:\n", count);

		for(int i = 1; i <= n; i++)
		{
			if(visit[i] == 0)
			{
				visit[i] = 1;
				cout << table[i];
				for(int j = 1; j <= n; j++)
				{
					if(j != i && d[i][j] == 1 && d[j][i] == 1)
					{
						visit[j] = 1;
						cout << ", " << table[j];
					}
				}
				cout << endl;
			}
		}		
		count++;					
	}	
	return 0;
}


这题本质上是求有向图上的传递闭包,用d[i][j]代表第i个人直接或间接地给第j个人打电话。用Floyd-Warshall算法求出传递闭包后,d[i][j]和d[j][i]都为1代表两个人在同一个电话圈内。
混合动力汽车(HEV)模型的Simscape模型(Matlab代码、Simulink仿真实现)内容概要:本文档介绍了一个混合动力汽车(HEV)的Simscape模型,该模型通过Matlab代码和Simulink仿真工具实现,旨在对混合动力汽车的动力系统进行建模与仿真分析。模型涵盖了发动机、电机、电池、传动系统等关键部件,能够模拟车辆在不同工况下的能量流动与控制策略,适用于动力系统设计、能耗优化及控制算法验证等研究方向。文档还提及该资源属于一个涵盖多个科研领域的MATLAB仿真资源包,涉及电力系统、机器学习、路径规划、信号处理等多个技术方向,配套提供网盘下载链接,便于用户获取完整资源。; 适合人群:具备Matlab/Simulink使用基础的高校研究生、科研人员及从事新能源汽车系统仿真的工程技术人员。; 使用场景及目标:①开展混合动力汽车能量管理策略的研究与仿真验证;②学习基于Simscape的物理系统建模方法;③作为教学案例用于车辆工程或自动化相关课程的实践环节;④与其他优化算法(如智能优化、强化学习)结合,实现控制策略的优化设计。; 阅读建议:建议使用者先熟悉Matlab/Simulink及Simscape基础操作,结合文档中的模型结构逐步理解各模块功能,可在此基础上修改参数或替换控制算法以满足具体研究需求,同时推荐访问提供的网盘链接获取完整代码与示例文件以便深入学习与调试。
Function Calling允许大型语言模型(如GPT)决定何时调用外部函数,并将函数结果整合到其响应中[^1]。 ### 基本概念 Function Calling中的“Function”指的是一个个的函数,在SpringAI里可以使用@Tool注解来标记这些特殊的函数。可任意定义一个Spring的Bean,然后将其中的方法用@Tool标记。例如: ```java @Component public class FuncDemo { @Tool(description="Function的功能描述,将来会作为提示词的一部分,大模型依据这里的描述判断何时调用该函数") public String func(String param) { // ... return ""; } } ``` 这里的描述会作为提示词的一部分,大模型依据描述判断何时调用该函数[^3]。 ### 使用方法 以Python代码示例说明实际调用工具的过程: ```python function_calling_message = completion.choices[0].message function_calling = completion.choices[0].message.tool_calls[0] import json def get_weather(*, latitude:float, longitude:float): return { "temperature": 23, "weather": "Sunny", "wind_direction": "South", "windy": 2, } functions = { "get_weather": get_weather # 字典形式,将存在了的函数放进去 } # 进行 Function Calling,将 Calling Date 传入到 Function 中 function_result = functions[function_calling.function.name](**json.loads(function_calling.function.arguments)) ``` 此代码中,先从响应中获取函数调用信息,定义了一个`get_weather`函数,将函数存于字典`functions`中,最后根据函数名和参数调用相应函数并得到结果[^2]。 ### 相关技术信息 Function Calling与大型语言模型紧密相关,借助大模型的理解和判断能力,依据提示词和函数描述来决定是否调用以及调用哪个外部函数。在SpringAI框架下,利用@Tool注解简化了定义可被调用函数的过程,使得开发者能更方便地将自定义函数集成到与大模型的交互中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值