UVa247 Calling Circles

2023-11-07 20:39
文章标签 calling circles uva247

本文主要是介绍UVa247 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 gure 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 le will contain one or more data sets. Each data
set begins with a line containing two integers, n and m . The
rst 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 rst 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 le 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.

用floyd传递闭包,然后dfs,如果两个点互相可达就在一个集合里。

#include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
using namespace std;
map<string,int> mp;
string str[30];
int n,m,f[30][30],vis[30];
void init()
{int i,cnt=0;string s1,s2;memset(f,0,sizeof(f));memset(vis,0,sizeof(vis));mp.clear();for (i=1;i<=m;i++){cin>>s1>>s2;if (!mp.count(s1)) mp[s1]=++cnt,str[cnt]=s1;if (!mp.count(s2)) mp[s2]=++cnt,str[cnt]=s2;f[mp[s1]][mp[s2]]=1;}
}
void solve()
{int i,j,k;for (k=1;k<=n;k++)for (i=1;i<=n;i++)for (j=1;j<=n;j++)f[i][j]|=f[i][k]&f[k][j];
}
void dfs(int u)
{int v;for (v=1;v<=n;v++)if (f[u][v]&&f[v][u]&&!vis[v]){cout<<", "<<str[v];vis[v]=1;dfs(v);}
}
int main()
{int i,K=0;while (cin>>n>>m&&n){init();solve();if (K) cout<<endl;cout<<"Calling circles for data set "<<++K<<":"<<endl;for (i=1;i<=n;i++)if (!vis[i]){cout<<str[i];vis[i]=1;dfs(i);cout<<endl;}}
}

这篇关于UVa247 Calling Circles的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/366150

相关文章

Win32函数调用约定(Calling Convention)

平常我们在C#中使用DllImportAttribute引入函数时,不指明函数调用约定(CallingConvention)这个参数,也可以正常调用。如FindWindow函数 [DllImport("user32.dll", EntryPoint="FindWindow", SetLastError = true)]public static extern IntPtr FindWindow

【AI大模型应用开发】2.1 Function Calling连接外部世界 - 入门与实战(1)

Function Calling是大模型连接外部世界的通道,目前出现的插件(Plugins )、OpenAI的Actions、各个大模型平台中出现的tools工具集,其实都是Function Calling的范畴。时下大火的OpenAI的GPTs,原理就是使用了Function Calling,例如联网检索、code interpreter。 本文带大家了解下Function calling,看

Ollama Qwen2 支持 Function Calling

默认 Ollama 中的 Qwen2 模型不支持 Function Calling,使用默认 Qwen2,Ollama 会报错。本文将根据官方模板对 ChatTemplate 进行改进,使得Qwen2 支持 Tools,支持函数调用。 Ollama 会检查对话模板中是否存在 Tools,如果不存在就会报错,下面的代码是 Ollama 解析模板的代码。 Ollama 3.1 是支持 Tools

SOMEIP_ETS_089: SD_Calling_same_ports_before_and_after_suspendInterface

测试目的: 验证设备(DUT)是否能够在一个请求完成后,对相同的SOME/IP端口恢复监听和分派请求。 描述 本测试用例旨在检查DUT在执行了SuspendInterface操作后,是否仍然能够使用与之前相同的源端口和SOME/IP端口来响应方法调用。 测试拓扑: 具体步骤: TESTER:第一个TestFieldUINT8 Getter和SetterDUT:正常响应TESTER:

Social Circles

来自codeforces You invited nn guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circl

在SimpleRAG中使用SiliconCloud快速测试Function Calling

Funcion Calling介绍 函数调用允许您将模型如gpt-4o与外部工具和系统连接起来。这对于许多事情都很有用,比如为AI助手赋能,或者在你的应用程序与模型之间建立深度集成。 如果您了解或者使用过Semantic Kernel可能会发现除了OpenAI支持Function Calling的模型之外,自动函数调用好像并不好用,国产大模型几乎都不能使用,由于想解决这个问题,在GitHub上

来自OpenAI官网的Function calling介绍与最佳实践

学习如何将大型语言模型连接到外部工具。 介绍 函数调用允许您将模型如gpt-4o与外部工具和系统连接起来。这对于许多事情都很有用,比如为AI助手赋能,或者在你的应用程序与模型之间建立深度集成。 在2024年8月,我们推出了结构化输出功能。当你在函数定义中通过设置strict: true来开启时,结构化输出确保模型为函数调用生成的参数完全符合你在函数定义中提供的JSON架构。 使用场景示例

--uva247(calling circles)强联通与floyd-warshell

图论题:一开始我是用tarjan算法做的,wrong answer 了很多次,然后又用了floyd-warshell算法,也wa了 最后找了题解,原来最后的dataset后面不是组数,是样例的编号,题根本就没说,让人怎么理解。。。 tarjan #include<stdio.h>#include<iostream>#include<string.h>#include<string>#

Docker下使用llama.cpp部署带Function calling和Json Mode功能的Mistral 7B模型

Docker下使用llama.cpp部署带Function calling和Json Mode功能的Mistral 7B模型 说明: 首次发表日期:2024-08-27参考: https://www.markhneedham.com/blog/2024/06/23/mistral-7b-function-calling-llama-cpp/https://github.com/abetlen/

【PyYaml】yaml.load()时总是出现警告:YAMLLoadWarning: calling yaml.load() without Loader=...

警告提示:YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.   YAML 5.1版本后弃用了yaml.load(file)