XMU 1050 Diffuse Secret 【最短路】

秘密扩散问题与Floyd算法
探讨了在一个社交网络中,每个人将自己所知的秘密每天与其朋友分享的情况下,所有人得知所有秘密所需的时间。通过Floyd算法求解最短路径问题,以确定秘密传播的最长时间。

1050: Diffuse Secret

Time Limit: 500 MS  Memory Limit: 64 MB
Submit: 10  Solved: 8
[Submit][Status][Web Board]

Description

  A secret is good in one, better in two, ill in three and worse in four. 
  ----Hi, I know a secret, come on I will tell you. But you must promise that you won’t tell it to other guys. 
  ----OK, of course I won't.
 
  Do you think they will keep the secret? No no, just like most people, they share their secrets with their own friends. If everybody knows a secret, it will never be secret any more. 
  For some reasons that know to all, TheBeet keep the salaries of employees as secret. But the employees don’t. At the beginning, everyone only knows how much he/she get. Everyday they share every secret they know with their friends (They don’t share the secret that they just heard today). For Example, A and B are good friends, B and C are good friends, A knows the secret a and secret d. B knows the secret b and secret c. C knows the secret e. After they share their secrets, A will know the secret abcd, B will know the secret abcde, C will know the secret bce. Today TheBeet increases every employee’s salary and he wonders when will be known to all employees.

Input

  The input file contains several test cases. 
  Each test case begins with two integers N, M 0 < N <= 100, 0 <= M <= (N * (N – 1)), N is the number of employee and M indicates there are M pairs of friend. 
  The following M lines contain 2 integers each line describing the pair of friends. 
N = 0 and M = 0 indicates the end of input and should not be processed.

Output

  For each test case, for each test case, output “Case #:” on the first line, '#' is the number of the test case. Then output a single integer as after such days, these secrets will never be secret. If there is one secret that some one will never know, you just output “Secret.” (Without quotes)

Sample Input

5 5
1 2
2 3
3 4
4 5
5 1
3 1
1 2
0 0

Sample Output

Case 1:
2
Case 2:
Secret.

HINT

 

Source

[ Submit][ Status][ Web Board]

 

 

题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1050

题目大意:

  每个人都有个秘密,他们每一天都会把自己的所有知道的秘密与他朋友分享

  当天得到的秘密不会分享。问所有人都知道所有秘密时是第几天。

题目思路:

  【最短路】

  考虑第i个人的秘密最迟到j,则秘密从i到j的传播为从i到j的最短路。

  那么所有人的秘密都到达最远的人的时间就为答案,即求所有人到所有人的最短路里的最大值。

  用floyd即可。

 

 1 /****************************************************
 2     
 3     Author : Coolxxx
 4     Copyright 2017 by Coolxxx. All rights reserved.
 5     BLOG : http://blog.youkuaiyun.com/u010568270
 6     
 7 ****************************************************/
 8 #include<bits/stdc++.h>
 9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double EPS=1e-8;
15 const int J=10000;
16 const int MOD=100000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=104;
20 using namespace std;
21 typedef long long LL;
22 double anss;
23 LL aans;
24 int cas,cass;
25 int n,m,lll,ans;
26 int e[N][N],f[N][N];
27 void floyd()
28 {
29     int i,j,k;
30     for(k=1;k<=n;k++)
31     {
32         for(i=1;i<=n;i++)
33         {
34             if(i==k)continue;
35             for(j=1;j<=n;j++)
36             {
37                 if(i==j || k==j)continue;
38                 f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
39             }
40         }
41     }
42 }
43 int main()
44 {
45     #ifndef ONLINE_JUDGE
46     freopen("1.txt","r",stdin);
47 //    freopen("2.txt","w",stdout);
48     #endif
49     int i,j,k,l;
50     int x,y,z;
51 //    for(scanf("%d",&cass);cass;cass--)
52 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
53 //    while(~scanf("%s",s))
54     while(~scanf("%d",&n))
55     {
56         scanf("%d",&m);
57         if(!n && !m)break;
58         ans=0;mem(f,0x01);
59         printf("Case %d:\n",++cass);
60         for(i=1;i<=m;i++)
61         {
62             scanf("%d%d",&x,&y);
63             f[x][y]=f[y][x]=e[x][y]=e[y][x]=1;
64         }
65         floyd();
66         for(i=1;i<=n;i++)
67         {
68             for(j=1;j<=n;j++)
69             {
70                 if(i==j)continue;
71                 ans=max(ans,f[i][j]);
72             }
73         }
74         if(ans==0x01010101)puts("Secret.");
75         else printf("%d\n",ans);
76     }
77     return 0;
78 }
79 /*
80 //
81 
82 //
83 */
View Code

 

转载于:https://www.cnblogs.com/Coolxxx/p/6691642.html

### 关于XMU OOMALL的理解 XMU OOMALL 可能是指厦门大学(Xiamen University, XMU)的一个在线订单管理系统(Order Management System, OOMALL)。如果将其与引用中的 SpringBoot 和 Java 学生学费支付系统的描述相结合,则可以推测这是一个基于 Web 的应用程序,用于管理学生的学费支付流程以及其他相关功能。 从技术角度来看,Spring Boot 是一种流行的框架,它简化了构建独立的、生产级的 Spring 应用程序的过程。Java 则是一种广泛使用的编程语言,适用于开发企业级应用。结合这些工具和技术栈,可以实现一个高效且可扩展的学生学费支付系统[^1]。 以下是关于如何设计这样一个系统的一些核心概念: #### 1. 用户角色定义 在该系统中存在三种主要用户角色:学生、财务人员以及管理员。每种角色都有特定权限和职责: - **学生**负责完成个人信息注册并执行缴费操作。 - **财务人员**能够查看所有交易记录,并处理异常情况。 - **管理员**则具有高权限,可用于维护整个平台的安全性和稳定性。 #### 2. 数据库交互机制 每当有新的登录尝试发生时,系统会向数据库写入一条日志记录以跟踪活动状态。这种做法有助于审计目的以及提高安全性水平。 #### 3. 注册模块的重要性 考虑到高校环境中可能存在频繁的人事变动,因此提供灵活便捷的新账户创建途径显得尤为重要。通过允许每位新生自行完成账号设置过程,不仅减少了人工干预需求,还提升了用户体验满意度。 ```java // 示例代码片段展示简单的身份验证逻辑 public boolean authenticateUser(String username, String password){ // 假设这里有一个方法可以从数据库获取密码哈希值 String storedPasswordHash = getUserPasswordFromDatabase(username); if(storedPasswordHash != null && PasswordUtil.matches(password, storedPasswordHash)){ logLoginAttempt(username, true); // 成功登录的日志记录 return true; }else{ logLoginAttempt(username, false); // 失败登录的日志记录 return false; } } ``` 上述代码展示了基本的身份验证函数结构,其中包含了成功或失败情况下均需调用的方法来保存相应的事件数据到后台存储位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值