Created
December 26, 2011 15:00
-
-
Save hamadu/1521331 to your computer and use it in GitHub Desktop.
Codeforces #97(div2)
This file contains 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.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemA { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.valueOf(s.readLine()); | |
int[] ans = new int[n+1]; | |
String[] info = s.readLine().split(" "); | |
for (int i = 0 ; i < n ; i++) { | |
ans[Integer.valueOf(info[i])] = i+1; | |
} | |
System.out.print(ans[1]); | |
for (int i = 2 ; i <= n ; i++) { | |
System.out.print(" " + ans[i]); | |
} | |
System.out.println(); | |
} | |
} |
This file contains 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.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemA { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.valueOf(s.readLine()); | |
int[] ans = new int[n+1]; | |
String[] info = s.readLine().split(" "); | |
for (int i = 0 ; i < n ; i++) { | |
ans[Integer.valueOf(info[i])] = i+1; | |
} | |
System.out.print(ans[1]); | |
for (int i = 2 ; i <= n ; i++) { | |
System.out.print(" " + ans[i]); | |
} | |
System.out.println(); | |
} | |
} |
This file contains 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.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemC { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.valueOf(s.readLine()); | |
int max = -1; | |
int maxidx = 0; | |
int[] an = new int[n]; | |
String[] info = s.readLine().split(" "); | |
for (int i = 0 ; i < n ; i++) { | |
an[i] = Integer.valueOf(info[i]); | |
if (max < an[i]) { | |
max = an[i]; | |
maxidx = i; | |
} | |
} | |
if (max == 1) { | |
for (int i = 0 ; i < n - 1 ; i++) { | |
System.out.print(1 + " "); | |
} | |
System.out.print(2); | |
System.out.println(); | |
return; | |
} | |
an[maxidx] = 1; | |
java.util.Arrays.sort(an); | |
for (int i = 0 ; i < n - 1 ; i++) { | |
System.out.print(an[i] + " "); | |
} | |
System.out.print(an[n-1]); | |
System.out.println(); | |
} | |
} |
This file contains 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.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemD { | |
public static int[][] points; | |
public static int INVALID = -1000000; | |
public static int isrect(int[] a) { | |
int ax = points[a[0]][0]; | |
int ay = points[a[0]][1]; | |
int maxdist = 0; | |
int maxbidx = 0; | |
for (int bidx = 1; bidx < 4 ; bidx++) { | |
int bx = points[a[bidx]][0]; | |
int by = points[a[bidx]][1]; | |
int dist = (ax-bx)*(ax-bx)+(ay-by)*(ay-by); | |
if (maxdist < dist) { | |
maxdist = dist; | |
maxbidx = bidx; | |
} | |
} | |
if (maxbidx == 0) { | |
return -1; | |
} | |
int bidx = maxbidx; | |
int bx = points[a[bidx]][0]; | |
int by = points[a[bidx]][1]; | |
int cx = INVALID, cy = INVALID; | |
int dx = INVALID, dy = INVALID; | |
for (int b = 1 ; b < 4 ; b++) { | |
if (b == bidx) { | |
continue; | |
} | |
if (cx == INVALID) { | |
cx = points[a[b]][0]; | |
cy = points[a[b]][1]; | |
continue; | |
} | |
if (dx == INVALID) { | |
dx = points[a[b]][0]; | |
dy = points[a[b]][1]; | |
continue; | |
} | |
} | |
int acx = cx - ax; | |
int acy = cy - ay; | |
int adx = dx - ax; | |
int ady = dy - ay; | |
int bcx = cx - bx; | |
int bcy = cy - by; | |
int bdx = dx - bx; | |
int bdy = dy - by; | |
if ((acx * ady - adx * acy) != 0) { | |
if (acx * adx + acy * ady == 0) { | |
if (bcx * bdx + bcy * bdy == 0) { | |
int acac = acx*acx + acy*acy; | |
int adad = adx*adx + ady*ady; | |
int bcbc = bcx*bcx + bcy*bcy; | |
int bdbd = bdx*bdx + bdy*bdy; | |
int min = acac; | |
int max = acac; | |
min = Math.min(min, adad); | |
min = Math.min(min, bcbc); | |
min = Math.min(min, bdbd); | |
max = Math.max(max, adad); | |
max = Math.max(max, bcbc); | |
max = Math.max(max, bdbd); | |
if (min == max) { | |
return 2; | |
} | |
return 1; | |
} | |
} | |
} | |
return -1; | |
} | |
public static boolean printarray(int[] a) { | |
for (int i = 0 ; i < a.length - 1 ; i++) { | |
System.out.print((a[i] + 1) + " "); | |
} | |
System.out.print(a[a.length-1] + 1); | |
System.out.println(); | |
return false; | |
} | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
points = new int[8][2]; | |
for (int i = 0 ; i < 8 ; i++) { | |
String[] info = s.readLine().split(" "); | |
points[i][0] = Integer.valueOf(info[0]); | |
points[i][1] = Integer.valueOf(info[1]); | |
} | |
for (int i = 0 ; i < (1<<8) ; i++) { | |
if (Integer.bitCount(i) == 4) { | |
int[] a = new int[4]; | |
int[] b = new int[4]; | |
int aidx = 0; | |
int bidx = 0; | |
for (int j = 0 ; j < 8 ; j++) { | |
if ((i & (1 << j)) >= 1) { | |
a[aidx++] = j; | |
} else { | |
b[bidx++] = j; | |
} | |
} | |
if (isrect(a) >= 2 && isrect(b) >= 1) { | |
System.out.println("YES"); | |
printarray(a); | |
printarray(b); | |
return; | |
} | |
} | |
} | |
System.out.println("NO"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment