Last active
December 24, 2015 23:09
-
-
Save jcchurch/6878175 to your computer and use it in GitHub Desktop.
My solution to https://icpcarchive.ecs.baylor.edu/external/37/3774.pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
public class Taunting { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
while (scan.hasNextInt()) { | |
double thisx = 0; | |
double thisy = 0; | |
double size = 0; | |
int n = scan.nextInt(); | |
scan.nextLine(); | |
String line = scan.nextLine(); | |
String[] parts = line.split(","); | |
double firstx = Double.parseDouble(parts[0]); | |
double firsty = Double.parseDouble(parts[1]); | |
double previousx = firstx; | |
double previousy = firsty; | |
for (int i = 2; i <= n; i++) { | |
line = scan.nextLine(); | |
parts = line.split(","); | |
thisx = Double.parseDouble(parts[0]); | |
thisy = Double.parseDouble(parts[1]); | |
double miny = thisy; | |
double maxy = previousy; | |
if (previousy < thisy) { | |
miny = previousy; | |
maxy = thisy; | |
} | |
double timedelta = thisx - previousx; | |
size += (timedelta * miny) + (timedelta * (maxy-miny) * 0.5); | |
previousx = thisx; | |
previousy = thisy; | |
} | |
System.out.printf("%.2f to %.2f: %.4f\n", firstx, thisx, size); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment