Competitive Programming: POJ 1654 – Area

 

Description

Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, …. In a subtree whose root node is X, we can get the minimum number in this subtree by repeating going down the left node until the last level, and we can also find the maximum number by going down the right node. Now you are given some queries as “What are the minimum and maximum numbers in the subtree whose root node is X?” Please try to find answers for the queries.

BST

Input

In the input, the first line contains an integer N, which represents the number of queries. In the next N lines, each contains a number representing a subtree with root number X (1 <= X <= 231 – 1).

Output

There are N lines in total, the i-th of which contains the answer for the i-th query.

Sample Input

2
8
10

Sample Output

1 15
9 11

Link to problem

import java.util.Scanner;

/*
There's a pattern with the lowest-order set bit of the numbers:
  - For leaf-node numbers, the lowest order set bit is 1.
  - Go up one level and the lowest order set bit is 2.
  - Go up one more level and the lowest order set bit is 4.
  - Etc.

That said, we can take advantage of Bit Hack #7 from 
http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
to isolate the lowest-order set bit.

Each node will have one less than that number of nodes in each subtree.
 */

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		while (N-- > 0) {
			int x = sc.nextInt();
			int diff = (x & (-x)) -1;
			System.out.println((x - diff) + " " + (x + diff));
		}

		sc.close();
	}
}

You Will Know Whether it Has All Been True

 

How does a life flash before one’s eyes
At the end? How is there time for so much time?
You pick up the book and hold it, knowing
Long since the failed romance, the strained
Marriage, the messenger, the mistake,
Knowing it all at once, as if looking through
A lighted dormer on the dark crest of a barn.
You know who is inside, and who has always been
At the other edge of the wood. She is waiting
For no one in particular. It could be you.
If you can discover which tree she has become,
You will know whether it has all been true.

— J.D. McClatchy, “Wolf’s Trees”

Diversity in Tech Efforts Self-Defeating?

 
Inclusion in Tech summit
Tash Wilder, Mimi Fox Melton, Damien Hooper-Campbell, and Tracy Chou [left to right] at The Atlantic’s Inclusion in Tech summit. (Photo: Tekla S. Perry)

Panelists at the Inclusion in Tech summit lamented that we can’t tell if tech is doing better on diversity because the data stinks.

My advice would be don’t worry about it. A lot of the noise around diversity in technology is self-defeating. If you’re a member of an underrepresented group, all you hear is that technology fields are hostile and awful and unwelcoming, you won’t be treated fairly, etc.

And you wonder why certain groups are underrepresented? You’ve answered your own question. Why would anyone who wants to have a happy life pursue a career beset by unfairness and hardship? Why not instead be a meeting planner or a flight attendant?

Asians are overrepresented in technology jobs but that’s a relatively recent development in the history of these fields. I don’t remember, when this transition from underrepresented to overrepresented was happening, hearing a lot about how technology fields were hostile to Asians. I don’t remember conferences being convened for the express purpose of complaining about the unfairness of it all.

Maybe it was happening and I just missed it, but either way, there’s a model for going from underrepresented to fairly represented or even overrepresented, and the model is accept the reality of your starting point, don’t complain, don’t get discouraged by listening to other people complain, do the work you need to do to accomplish what you want to accomplish.

Thus spoke The Programmer.

Competitive Programming: POJ 2242 – The Circumference of the Circle

 

Description

To calculate the circumference of a circle seems to be an easy task – provided you know its diameter. But what if you don’t?

You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.

Input

The input will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1,x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.

Output

For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.

Sample Input

0.0 -0.5 0.5 0.0 0.0 0.5
0.0 0.0 0.0 1.0 1.0 1.0
5.0 5.0 5.0 7.0 4.0 6.0
0.0 0.0 -1.0 7.0 7.0 7.0
50.0 50.0 50.0 70.0 40.0 60.0
0.0 0.0 10.0 0.0 20.0 1.0
0.0 -500000.0 500000.0 0.0 0.0 500000.0

Sample Output

3.14
4.44
6.28
31.42
62.83
632.24
3141592.65

Link to problem

Solution below . . .

Read more

The More We Rely on Technology . . .

 

No Internet Today

We had a brief network outage at the office, during which Mr. Frick walked over to Mr. Frack’s desk and said, “The network’s down. We can’t do the screen share,” i.e., they can’t see each other’s computer screen over the network because it’s down.

I was waiting for one of them — Frick or Frack — to say “Let’s just sit together in front of the one computer here like they used to in olden days” but neither of them ever did . . .

Foot of Pride

 

Billy Sunday

Yeah, from the stage they’ll be tryin’ to get water outta rocks
A whore will pass the hat, collect a hundred grand and say thanks
They like to take all this money from sin, build big universities to study in
Sing “Amazing Grace” all the way to the Swiss banks

Well, there ain’t no goin’ back when your foot of pride come down
Ain’t no goin’ back

— Bob Dylan, “Foot of Pride”

Essay on the One Hand and the Other

 

Consider the palms. They are faces,
eyes closed, their five spread fingers
soft exclamations, sadness or surprise.
They have smile lines, sorrow lines, like faces.
Like faces, they are hard to read.

Somehow the palms, though they have held my life
piece by piece, seem young and pale.
So much has touched them, nothing has remained.
They are innocent, maybe, though they guess
they have a darker side that they cannot grasp.

The backs of my hands, indeed, are so different
that sometimes I think they are not mine,
shadowy from the sun, all bones and strain,
but time on my hands, blood on my hands—
for such things I have never blamed my hands.

One hand writes. Sometimes it writes a reminder
on the other hand, which knows it will never write,
though it has learned, in secret, how to type.
That is sad, perhaps, but the dominant hand is sadder,
with its fear that it will never, not really, be written on.

They are like an old couple at home. All day,
each knows exactly where the other is.
They must speak, though how is a mystery,
so rarely do they touch, so briefly come together,
now and then to wash, maybe in prayer.

I consider my hands, palms up. Empty, I say,
though it is exactly then that they are weighing
not a particular stone or loaf I have chosen
but everything, everything, the whole tall world,
finding it light, finding it light as air.

Say One More Stupid Thing to Me

 

Sing me one more song, about you love me to the moon and the stranger
And your fall by the sword love affair with Errol Flynn
In these times of compassion when conformity’s in fashion
Say one more stupid thing to me before the final nail is driven in.

— Bob Dylan, “Foot of Pride”

Women in STEM: It’s Ambiguous but You’re Still Wrong

 

Woman in STEM

The Dartmouth student newspaper reports on a study finding that gender affects an individual’s perception of women’s anxiety in STEM disciplines.

Men are more likely than women to attribute this anxiety and self-doubt to internal factors, while women usually attribute such emotions to external factors.

Participants in the study read one story, among a selection, about an undergraduate woman taking a STEM class.

In the stories, based on the experiences of actual undergraduate women in STEM, the female main character expressed having anxiety or self-doubt. It was ambiguous whether the instructor in the stories harbored any biases against women.

According to research team leader Mary Flanagan, “Women identify the problem as something that is familiar and men identify the problem as something that is a particular student’s problem. Men are not seeing the systemic biases as much as the women are. That is something that we need to address in deeper conversations about STEM classrooms.”

The stories were ambiguous but stupid men still managed to draw the wrong conclusion!

Flanagan added that a large problem is the culture created by STEM classrooms that is inhospitable to women.

Flanagan, oddly enough, is a film and media studies professor. I have lots of experience with STEM classrooms . . . I never found them inhospitable to women, though admittedly I’m not a woman.

Flanagan said that the goal of the research is to change the mechanisms that create bias and to make STEM fields more inclusive for women.

I would have guessed that the goal of the research, to the extent that research is goal-oriented, was discovering whether gender impacts attribution of emotions.

Why bother with research if your conclusions have been drawn in advance, i.e., STEM fields are unfriendly to women, the reason being the inability or unwillingness of men to see things that are right under their noses.

The study was published in Psychology of Women Quarterly.

I’d love to see more women in STEM fields, particularly in computing, but I’m consistently disappointed by the quality of “research” in this area.

Thus spoke The Programmer.

Thomas Jefferson on Hillary Clinton

 
Thomas Jefferson

My fellow Americans —

Hillary Clinton is still rattling off all the “reasons” she lost the 2016 presidential election: misogyny, the FBI, sexism, the NRA, Russia . . .

To my knowledge, she has never correctly identified the actual culprits: the patriotic men and women of this country.

Thomas Jefferson

How You Should Think Of Me

 
Harper's Muslims and Christians

A disciple came to Maruf Kharki and said:

“I have been talking to people about you. Jews claim that you are a Jew; Christians revere you as one of their own saints; Muslims insist that you are the greatest of all Muslims.”

Maruf answered:

“This is what humanity says in Baghdad. When I was in Jerusalem, Jews said that I was a Christian, Muslims that I was a Jew, and Christians that I was a Muslim.”

“What must we think of you, then?” the man said.

“Some do not understand me and they revere me. Others do not either, so they revile me. That is what I have come to say. You should think of me as one who has said this.”

A Joke About Inequality

 
Goat

Igor and Boris are dirt-poor peasants in the Soviet Union (it’s an old joke), barely scratching enough crops from their small plots of land to feed their families. The only difference between them is that Boris owns a scrawny goat. One day a genie appears to Igor and grants him a wish. Igor says, “I wish that Boris’s goat should die.”

A Nest, a Haven and Calm Place

 

The low trolley on its cushiony rubber tyres luxuriously bore the corpse away down the middle of the ward. There was speed and secretiveness and deftness in its movement. Over the dead man’s face was a blanket, so that age, torture, ugliness and fear, all were hidden.

Instead of looking on this covering, this careful manipulation as an hypocrisy and cheat, I saw it for what it really was, a desperate effort to make life bearable and sane.

I admired the doctors and the nurses. I admired every human being in the world who, on top of a million, million horrors, yet built a nest, a haven and calm place.

— Denton Welch, A Voice Through a Cloud

David Hogg’s College Prospects

 
Hogg on CNN

A CNN news anchor asked Parkland shooting survivor and graduating senior David Hogg “what kind of dumbass colleges” would reject his application.

As it happens, the dumbass colleges include UCLA and three other UC schools: UC San Diego, UC Irvine and UC Santa Barbara.

Hogg scored a 1270 on the SAT. 1270 SAT scores are a dime a dozen. If his name were, say, Emma Gonzalez, he might get into a UC school with a 1270 SAT, but a white boy from Florida is not getting into a UC school with a 1270 SAT.

Unlike Laura Ingraham, I will not lose any advertisers for pointing this out because I don’t have any advertisers.

Hogg puts himself out there as a guy who’s going to play hardball with profane takedowns of anyone who doesn’t see the world the same way he does, but he feels victimized when someone says a 1270 SAT score is not very good? Hey no fair picking on a high school kid!

I live in California and I’m glad he’s not coming.

Was Nikolas Cruz Bullied?

 

In 2018, being accused of bullying is not on a par with being accused of murder, but it’s close.

Emma Gonzalez, one of the Parkland shooting survivors, said this about Nikolas Cruz at the anti-gun march in Washington, D.C.:

Since he was in middle school, it was no surprise to anyone who knew him that he was the shooter. Those talking about how we should have not ostracized him? You don’t know this kid. OK? We did!

I can’t see anything unusual about that. The popular kids sneer at the geeks, the nerds and the weirdos. Because they deserve it. You don’t know this kid. We did.

But when the kid in this case goes off the rails, which “was no surprise to anyone who knew him,” some self-reflection seems to be in order before blaming the usual suspects.

I don’t understand the strategy of gun control proponents. Every tragedy is used to hammer and shame and silence those with different views. Every time I hear the Parkland kids, they’re abrasive and rude.

Is that helpful? It may be cathartic but I’m pretty sure it just hardens people on both sides in their pre-existing opinions.

Nicolas Cruz arrest

This is Where Your PDF Resume Will Take You

 
Microsoft Word

Received the following advice today:

When applying for jobs, never send your resume in .docx format. Fonts don’t always get embedded and hiring managers cannot always open these files. Use PDF.

Do we really want to work for managers who can’t open a Word doc? Imagine the world-class mentoring and career development you’re going to get from such a person.

I mean, my wife can open Word docs no problem and she can’t even figure out how to turn on the TV.

Thus spoke The Programmer.