Competitive Programming: POJ 1125 – Stockbroker Grapevine

 

Description

Stockbrokers are known to overreact to rumors. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumors in the fastest possible way.

Unfortunately for you, stockbrokers only trust information coming from their “Trusted sources” This means you have to take into account the structure of their contacts when starting a rumor. It takes a certain amount of time for a specific stockbroker to pass the rumor on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumor, as well as the time it will take for the rumor to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.

Input

Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring to the contact (e.g. a ‘1’ means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.

Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.

Output

For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes.

It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message “disjoint”. Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.

Sample Input

3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0

Sample Output

3 2
3 10

Link to problem

Solution below . . .

Read more

USC’s Unreal Finish to Win Track and Field Championship

 

I’ve never seen a come-from-behind finish like this!

The male announcer says twice in the home stretch that Purdue is going to win the race.

Female announcer: “Here comes USC.”

Male announcer: “Not gonna catch Purdue . . . oh my god . . .”

More People I’m Sick Unto Death Of: Grads

 

Why is it always “Dads and Grads”? Mothers get the whole month of May to themselves — despite the fact that a lot of graduations take place in May — but June is always Dads and Grads.

Granted, Moms and Grads doesn’t rhyme like Dads and Grads or Highways and Byways . . . but why not Moms and Proms? Flowers for everyone!

Anyway, Happy Fathers Day, guys.

I Feared That the Dam Might Break So I Loosed the River

 

I can never remake the thing I have destroyed;
  I brushed the golden dust from the moth’s bright wing,
I called down wind to shatter the cherry-blossoms,
  I did a terrible thing.

I feared that the cup might fall, so I flung it from me;
  I feared that the bird might fly, so I set it free;
I feared that the dam might break, so I loosed the river:
  May its waters cover me.

— Aline Murray Kilmer, “Shards”

Competitive Programming: POJ 2488 – A Knight’s Journey

 

Description

Background

Knight moves

The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular to this. The world of a knight is the chessboard he is living on. Our knight lives on a chessboard that has a smaller area than a regular 8 * 8 board, but it is still rectangular. Can you help this adventurous knight to make travel plans?

Problem

Find a path such that the knight visits every square once. The knight can start and end on any square of the board.

Input

The input begins with a positive integer n in the first line. The following lines contain n test cases. Each test case consists of a single line with two positive integers p and q, such that 1 <= p * q <= 26. This represents a p * q chessboard, where p describes how many different square numbers 1, . . . , p exist, q describes how many different square letters exist. These are the first q letters of the Latin alphabet: A, . . .

Output

The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. Then print a single line containing the lexicographically first path that visits all squares of the chessboard with knight moves followed by an empty line. The path should be given on a single line by concatenating the names of the visited squares. Each square name consists of a capital letter followed by a number.
If no such path exist, you should output impossible on a single line.

Sample Input

3
1 1
2 3
4 3

Sample Output

Scenario #1:
A1

Scenario #2:
impossible

Scenario #3:
A1B3C1A2B4C2A3B1C3A4B2C4

Link to problem

Solution below . . .

Read more

Those Weren’t Burglars, They Were “Confidential Informants”

 
Richard Nixon

F.B.I. Used Informant to Investigate Russia Ties to Campaign, Not to Spy, as Trump ClaimsNew York Times

It’s too bad for Richard Nixon that he wasn’t able to come up with a similarly quick-witted explanation for Watergate.

It reminded me of a joke:

A man sees one of his neighbors scattering crumbs all around his house.

“Why are you doing that?” he asked.

“I’m keeping the tigers away.”

“But there aren’t any tigers around here.”

“That’s right. You see how well it works?”

Galactic Meetup Scheduled

 

Our nearest neighbor, the Andromeda galaxy, is speeding toward the Milky Way at 250,000 miles per hour and will crash into us in 3.75 billion years.

The good news is that because of the vast distances between stars, it’s unlikely that any stars will actually collide.

Before you mark this event on your calendar, however, remember that our sun is continually growing. About 3 billion years from now, the sun will be 40 percent larger than its current state and all life on Earth will probably cease to exist.

https://cdn-images-1.medium.com/max/2000/1*M_IxqPdX4_B148fyOH-0qA.jpeg

Answers to Persistent Questions

 

Is there a God? No.

What is the nature of reality? What physics says it is.

What is the purpose of the universe? There is none.

Does prayer work? Of course not.

What happens when we die? We are put a few feet in the ground to blindly rot and disappear forever. Otherwise, things go on pretty much as before.

See You in Hell: Morgan Freeman Edition

 
Satan

[See You in Hell is a feature by our guest blogger, Satan — PE]

Greetings from the underworld!

I was looking forward to reading the “shocking” allegations against Morgan Freeman . . . it turns out he likes to look at women’s breasts!

WHAAAAT?!

Men like to look at breasts, women like to look at breasts . . . and he also says things like “I’d like to spend an hour with her.”

Every person on earth older than 12 has said the same thing. If looking at breasts and naming a person you’d like to fuck gets you condemned to Hell, I’m not going to have enough room to put all these people.

Heaven will be empty!

Public life in America is now dominated by whatever actresses are currently complaining about.

See you in Hell!

Amazon Devices Recording Private Conversations?

 

Woman says her Amazon device recorded private conversation, sent it out to random contact

Echo devices

Is the woman’s name Alexa? No? It’s Danielle?

Despite what we’re told, it’s impossible that these microphones aren’t listening until you say their name — Alexa, Siri, OK Google, etc. How do they hear their name if they’re not listening?

I’m not listening until you say my name: Paul. Until then, I’m not hearing anything you say. Not listening, won’t repeat it to anyone. Your total privacy is assured.

There is No Doubt = There is Doubt

 

There is no doubt about it. The scenario that took place at Starbucks back in April is serious. Targeting someone because of their skin color in 2018 seems ridiculous, because it is. Haven’t we come far beyond this sort of thing in the past fifty years?

Jim Bohn

When someone says “There is no doubt about it” or “It is an indisputable fact” or “Everyone knows . . .”, rest assured that what follows will be an opinion about which there is nothing but doubt and the speaker wants to sidestep having to make a case for whatever he or she is putting forward.

It doesn’t make sense to preface something about which there really is no doubt by saying “There is no doubt about it.” It’s superfluous and silly.

If I were one of the Starbucks employees, I’d be suing for defamation. What evidence are you relying on to humiliate me with attacks on my motivation and my character?

I’m doing what I was told to do. You can’t sit in the store without buying anything. Bathrooms are for customers only. If I ask someone to leave and they won’t leave, call the police.

Not every bad thing that befalls a black American is racially motivated.

Experts and Empty Suits

 

Our inability to predict in environments subjected to the Black Swan, coupled with a general lack of awareness of this state of affairs, means that certain professionals, while believing they are experts, are in fact not. Based on their empirical record, they do not know more about their subject than the general population, but they are much better at narrating — or, worse, at smoking you with complicated mathematical models. They are also more likely to wear a tie.

— Nassim Nicholas Taleb, The Black Swan

Philip Roth, 1933-2018

 

The final question assigned to the class was “What is life?” Merry’s answer was something her father and mother chuckled over together that night. According to Merry, while the other students labored busily away with their phony deep thoughts, she — after an hour of thinking at her desk — wrote a single, unplatitudinous declarative sentence: “Life is just a short period of time in which you are alive.” “You know,” said the Swede, “it’s smarter then it sounds. She’s a kid — how has she figured out that life is short? She is somethin’, our precocious daughter. This girl is going to Harvard.” But once again the teacher didn’t agree, and she wrote beside Merry’s answer, “Is that all?” Yes, the Swede thought now, that is all. Thank God, that is all; even that is unendurable.

American Pastoral

RIP Philip Roth

Competitive Programming: POJ 1159 – Palindrome

 

Description

A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome.

As an example, by inserting 2 characters, the string “Ab3bd” can be transformed into a palindrome (“dAb3bAd” or “Adb3bdA”). However, inserting fewer than 2 characters does not produce a palindrome.

Input

Your program is to read from standard input. The first line contains one integer: the length of the input string N, 3 <= N <= 5000. The second line contains one string with length N. The string is formed from uppercase letters from ‘A’ to ‘Z’, lowercase letters from ‘a’ to ‘z’ and digits from ‘0’ to ‘9’. Uppercase and lowercase letters are to be considered distinct.

Output

Your program is to write to standard output. The first line contains one integer, which is the desired minimal number.

Sample Input

5
Ab3bd

Sample Output

2

Link to problem

Solution below . . .

Read more