2020级练习赛2(E,F)

E-Chain Email

Description

A chain email is an email that people receive and then forward to all of their friends. This sort of email is very common amongst elderly people, who have notably bad memories. Elderly people’s memories are so bad that if they ever receive a chain email they will forward it to all of their contacts. This can become very problematic when elderly people continually send the same email to each other. For instance, if two people have each other in their contacts and if either of them receive a chain email they will continually send the email to each other back and forth forever. Email companies are worried that this will result in a massive amount of storage loss on their servers and have asked you to determine if a specific person were to start a chain email, who would receive that email forever.

Given each elderly person’s contacts and which elderly person will be starting a chain email, determine who will be indefinitely receiving emails.

Input
The first line of input will have two single-space-separated integers, p (1≤p≤50), indicating the number of people who use the email service and, s (1≤s≤p), indicating the source of the chain email, where each person is labeled from 1 to p. Following this will be a single line with the names of all of the people, from person 1 to person p, who use the email service, each separated by exactly one space. All names will contain alphabetic characters only and be between 1 and 19 characters (inclusive) in length. Following this will be p lines. The i th line will describe the contact list of the i th person. This description will consist of an integer, m (0≤m<p), indicating the number of contacts this person has, followed by the 1-based index of each of the contacts, each separated by exactly one space. It’s guaranteed that no one will contain themselves as a contact.

Output
Print the names of all of the people who will infinitely receive chain emails, assuming that everyone continually forwards the email to all of their contacts. Each name should be followed by a space. List these contacts in the order that they appear in the input. If no one will infinitely receive chain emails, then print “Safe chain email!” instead.

题意

有n个人使用连锁邮件系统,每个人都会有若干个联系人
当给你的联系人发送一封连锁邮件后,收到邮件的人又会给他的联系人发生一封邮件

在确定了n个人的名字,联系人,以及连锁邮件的出发点的情况下判断那些人是可以无限次收到邮件的,输出他们的名字。

思路

首先判断这个连锁邮件系统中 是否可以构成回路(环)
如果可以构成回路,那么回路上的所有人,以及这些人的联系人都是可以无限次接受到邮件的

方法之一

1.利用弗洛伊德计算两个人之间的最短距离
2.然后用最短距离判断是否出现了回路
3.对出现回路的人进行标记
4.对刚才标记过的人,遍历他们的联系人,将他们的联系人也标记上

参考代码-弗洛伊德求最短路算法

for(int i=1;i<=n;i++)
	     for(int j=1;j<=n;j++)
	       for(int k=1;k<=n;k++)
	       {
	       	  dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
		   }

F-Faster Microwaving

Description
Chris likes getting his food quickly so he cooks a lot using the microwave. However, he is frustrated by how microwave makers seem not to communicate well with makers of microwavable foods. For example, many microwaves have a “popcorn” button, but most microwave popcorn instructions say “Do not use the ‘popcorn’ button.” To avoid any chance of ruining his food, Chris uses only timed cooking, entering the time to cook each item in minutes and seconds (in MM:SS format) on the numbered buttons of the microwave. Since there is one digit per button, he has to press one digit at a time and move his finger between different digits, which is tedious and annoying because he’s hungry. One nice thing is that there is no button for the “:” as the microwave always interprets the last 2 digits as seconds, and inserts the “:” appropriately—however, it does not enforce a restriction that the last two digits are 59 seconds or less; if Chris presses 1, then 9, then 0 for a time of “1:90” it will cook for 1 minute and 90 seconds, which is the same as 2 minutes and 30 seconds.

Chris would like to be able to enter the cooking times more quickly. He notices that it takes 1 “moment” (a unit of time just under half a second) to press each digit’s button firmly, and it also takes 1 moment (the same unit of time) to move his finger away from one digit’s button to find the button for a different digit. Therefore, to enter a time “4:00” takes 4 moments in total—one to press “4”, one to move from “4” to “0”, one to press “0”, and one to press “0” again immediately, without having to find the button. It also takes 4 moments to enter “4:45” (press 4, then 4 again, then move from 4 to 5, then press 5), but it takes 5 moments to enter “4:30” (4, then move, then 3, then move, then 0).

After some experimentation, Chris devises the following plan to enter faster cooking times that are reasonably close to the recommended times in the cooking instructions for each item:

Based on the microwavable item type, consider using a range of proposed cooking times that are each within a small percent above or below the recommended cooking time. For example, using 10% with a recommended cooking time of 2 minutes and 30 seconds (2:30), the proposed cooking times would be the range of times from 2:15 to 2:45 inclusive.
Find the sequence of digits (buttons) that takes the lowest total moments to enter out of any of the proposed cooking times in the range.
If there are multiple sequences of digits that have the same lowest total moments, choose the sequence that yields an actual cooking time that is closest to the recommended cooking time.
Chris has verified that the above plan always results in a unique answer so you may assume so.

Given the recommended cooking time for a microwavable item, and a percent to use for the range of proposed cooking times, output the sequence of digits that Chris should press in order to start the microwave as fast as possible, according to his plan.

Input
The first input line contains only the recommended cooking time for the microwavable item, which consists of exactly 5 characters in the format $MM:SS$ with 2-digit minutes $MM$ ($00 \le MM \le 20$) and 2-digit seconds $SS$ ($SS \in {00, 15, 30, 45}$). The recommended cooking time will be at least 00:15 (15 seconds). The second input line contains only an integer $p$ ($2 \le p\le 10$), which is the percent of the recommended cooking time that defines the range of lower and higher proposed cooking times.

Output
Print the exact digits that should be pressed, in the order they should be pressed.

Note that the seconds are always integers and the time must be “within” the percent range. For example, for a recommended cooking time of 00:45 and 10%, the range of proposed cooking times is 41 seconds to 49 seconds (45 ± 4, because 40 and 50 are not within 10% of the recommended time).

题意

用电磁炉进行烹饪食物
第一行输入的是推荐烹饪时间,格式为 mm:ss
下面跟一行 输入 数字 p
表示实际的烹饪时间范围 在 推荐烹饪时间 ± p% 之间

电磁炉上有若干个按钮,我们每次(按按钮)或者(移动)都需要花费一个单位的时间
我们需要用按按钮的方式将烹饪时间表示出来
比如 1:30 即需要 按1-移动-按3-移动-按0 (5个单位时间)

我们需要在 实际烹饪时间范围内 找出我们用于 按按钮用时最短 的
按按钮顺序 并将该顺序输出

特殊的:电磁炉有问题,时间不一定是60进制,也可能是100进制
例如 1:30可以变成 0:90 (易错点)

思路-模拟

进行模拟处理
求出实际时间范围之后,将范围内的时间点分别转化成
正常的时间格式 和 非正常的时间格式

(本题只需要考虑到非正常的时间格式就问题不大)

然后不断的寻找所用时间最少的 按钮顺序 即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值