## Wednesday, September 28, 2011

### SRM519

Level 1 Level 2 Level 3
Div 1 Level 1 Level 2 Level 3
Div 2 Level 1 Level 2 Level 3

## Tutorials:

### Solution

The same with Div2 - 900 pts.

### Solution

I just followed the tutorials on official website.

### Source Code:

//Wednesday, September 28, 2011 18:08 PDT
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class BinaryCards
{
public long largestNumber(long A, long B) {
for (int i=60; i>=0; --i)   // 60 = ceil( log2(10 ^ 18) )
if ( ((A^B) & (1L<<i) ) != 0)
return A | ((1L<<(i+1))-1);
return A;
}

}

### Solution

Solve the problem recursively. It's pretty natural.

### Source Code:

//Wednesday, September 28, 2011 18:08 PDT
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class ThreeTeleports
{
public int shortestDistance(int xMe, int yMe, int xHome, int yHome, String[] teleports)
{
long dist = Math.abs(xMe - xHome) + Math.abs(yMe - yHome);
for(int i=0; i<teleports.length; i++){
String[] strs = teleports[i].split(" ");
int x1 = Integer.parseInt(strs[0]);
int y1 = Integer.parseInt(strs[1]);
int x2 = Integer.parseInt(strs[2]);
int y2 = Integer.parseInt(strs[3]);
String[] teles = new String[teleports.length - 1];
for(int j=0, k=0; j<teleports.length; j++){
if(i!=j){
teles[k++] = teleports[j];
}
}

dist = Math.min(dist, Math.abs(xMe - x1) + Math.abs(yMe - y1) + 10L + shortestDistance(x2, y2, xHome, yHome, teles));
dist = Math.min(dist, Math.abs(xMe - x2) + Math.abs(yMe - y2) + 10L + shortestDistance(x1, y1, xHome, yHome, teles));
}
return (int)dist;
}
}

### Solution

Use the sum from 1 to 7, subtract every corresponding day from the sum, leave the only missing one to return.

### Source Code:

//Wed Sep 28 18:19:03 PDT 2011
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class WhichDay
{
public String getDay(String[] notOnThisDay)
{
int sum = (1 + 7) * 7 / 2;
for(String str : notOnThisDay){
sum -= getNumber(str);
}
return getDays(sum);
}

public int getNumber(String s){
if(s.compareTo("Sunday") == 0return 7;
if(s.compareTo("Saturday") == 0return 6;
if(s.compareTo("Friday") == 0return 5;
if(s.compareTo("Thursday") == 0return 4;
if(s.compareTo("Wednesday") == 0return 3;
if(s.compareTo("Tuesday") == 0return 2;
if(s.compareTo("Monday") == 0return 1;
return 0;
}

public String getDays(int n){
if(n == 1return "Monday";
if(n == 2return "Tuesday";
if(n == 3return "Wednesday";
if(n == 4return "Thursday";
if(n == 5return "Friday";
if(n == 6return "Saturday";
if(n == 7return "Sunday";
return "None";
}
}