Created
August 28, 2016 03:39
-
-
Save pxpc2/1b3b5edac9c7f84161d39becc07852a2 to your computer and use it in GitHub Desktop.
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.Scanner; | |
| /** | |
| * @author Pedro Daia | |
| */ | |
| public class ciclovias | |
| { | |
| public static void main(final String[] args) | |
| { | |
| final Scanner s = new Scanner(System.in); | |
| int n = s.nextInt(); int m = s.nextInt(); | |
| System.out.println(n); | |
| int[][] adj = new int[n][n]; | |
| for (int i = 0; i < m; i++) | |
| { | |
| int k = s.nextInt()-1; | |
| int j = s.nextInt()-1; | |
| adj[k][j] = 1; | |
| adj[j][k] = 1; | |
| } | |
| } | |
| } |
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.Scanner; | |
| /** | |
| * @author Pedro Daia | |
| */ | |
| public class falta | |
| { | |
| public static void main(final String[] args) | |
| { | |
| final Scanner s = new Scanner(System.in); | |
| final int n = s.nextInt(); | |
| final String discard = s.nextLine(); | |
| } | |
| } |
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.Scanner; | |
| /** | |
| * @author Pedro Daia | |
| */ | |
| public class jardim | |
| { | |
| private static int[] x, y; | |
| public static void main(final String[] args) | |
| { | |
| final Scanner s = new Scanner(System.in); | |
| x = new int[7]; | |
| y = new int[7]; | |
| for (int i = 0; i < 7; i++) | |
| { | |
| x[i] = s.nextInt(); | |
| y[i] = s.nextInt(); | |
| } | |
| setEixoPos(); | |
| // p2p3 sempre paralelos ao eixo x e colineares com p2,p3,p4,p5 | |
| int yParalel = y[1]; | |
| for (int i = 1; i < 5; i++) | |
| { | |
| if (y[i] != yParalel) | |
| { | |
| System.out.println("N"); | |
| return; | |
| } | |
| } | |
| /*for (int i = 0; i < 7; i++) | |
| { | |
| System.out.print("X(p"+(i+1)+") = " + x[i]); | |
| System.out.println(" Y(p"+(i+1)+") = " + y[i]); | |
| }*/ | |
| /* | |
| comprimento de p1 ao p2: | |
| sqrt[(|x1-x2|)ˆ2 + (|y1-y2|)ˆ2] | |
| */ | |
| checkSizeOne(); | |
| //checkMedOne(); | |
| checkDifSize(); | |
| checkSizeTwo(); | |
| System.out.println("S"); | |
| } | |
| private static void checkSizeOne() | |
| { | |
| int a = (x[0] > x[1] ? x[0] - x[1] : x[1] - x[0]); | |
| int b = (y[0] > y[1] ? y[0] - y[1] : y[1] - y[0]); | |
| int c = (x[0] > x[2] ? x[0] - x[2] : x[2] - x[0]); | |
| int d = (y[0] > y[2] ? y[0] - y[2] : y[2] - y[0]); | |
| int e = a*a + b*b, f = c*c + d*d; | |
| if (e != f) | |
| { | |
| System.out.println("N"); | |
| System.exit(0); | |
| } | |
| } | |
| private static void checkMedOne() | |
| { | |
| int a = (x[1] > x[2] ? x[1] - x[2] : x[2] - x[1]); | |
| int b = (x[3] > x[4] ? x[3] - x[4] : x[4] - x[3]); | |
| if (a/2 != b/2) | |
| { | |
| System.out.println("N"); | |
| System.exit(0); | |
| } | |
| } | |
| private static void checkDifSize() | |
| { | |
| int a = (x[1] > x[2]? x[1] - x[2] : x[2] - x[1]); | |
| int b = (x[3] > x[4]? x[3] - x[4] : x[4] - x[3]); | |
| if (a < b) | |
| { | |
| System.out.println("N"); | |
| System.exit(0); | |
| } | |
| } | |
| private static void intercept() | |
| { | |
| int ox = x[0]; | |
| int sx = x[5]; | |
| if (ox > sx) | |
| { | |
| } | |
| } | |
| private static void checkSizeTwo() | |
| { | |
| int c = (y[3] > y[5]? y[3] - y[5] : y[5] - y[3]); | |
| int d = (y[4] > y[6]? y[4] - y[6] : y[6] - y[4]); | |
| //int e = a*a + b*b, f = c*c + d*d; | |
| if (c != d) | |
| { | |
| System.out.println("N"); | |
| System.exit(0); | |
| } | |
| } | |
| private static void setEixoPos() | |
| { | |
| int minx = 1111111111, miny = 1111111111; | |
| for (int i : x) | |
| { | |
| if (i <= minx) | |
| minx = i; | |
| } | |
| for (int i : y) | |
| { | |
| if (i <= miny) | |
| miny = i; | |
| } | |
| // ponto zero ta em (minx, miny) | |
| for (int i = 0; i < x.length; i++) | |
| { | |
| if (x[i] <= 0) | |
| { | |
| x[i] = (minx - x[i])*-1; | |
| } | |
| else | |
| { | |
| x[i] = x[i] - minx; | |
| } | |
| if (y[i] <= 0) | |
| { | |
| y[i] = (miny - y[i])*-1; | |
| } | |
| else | |
| { | |
| y[i] = y[i] - miny; | |
| } | |
| } | |
| } | |
| } |
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.ArrayList; | |
| import java.util.Scanner; | |
| /** | |
| * @author Pedro Daia | |
| */ | |
| public class pokemon | |
| { | |
| public static void main(final String args[]) | |
| { | |
| final Scanner s = new Scanner(System.in); | |
| int numdoces = s.nextInt(); | |
| final int x = s.nextInt(); | |
| final int y = s.nextInt(); | |
| final int z = s.nextInt(); | |
| int[] aa = new int[3]; | |
| aa[0] = x; aa[1] = y; aa[2] = z; | |
| ArrayList<Integer> one = new ArrayList<>(); | |
| for (int i : aa) | |
| one.add(i); | |
| ArrayList<Integer> sorted = sort(one); | |
| int count = 0; | |
| for (Integer aSorted : sorted) | |
| { | |
| int a = numdoces - aSorted; | |
| if (a >= 0) | |
| { | |
| numdoces = a; | |
| count++; | |
| } | |
| } | |
| System.out.println(count); | |
| } | |
| private static ArrayList<Integer> sort(ArrayList<Integer> arr) | |
| { | |
| ArrayList<Integer> l = new ArrayList<>(); | |
| int min = 11111111; | |
| int ind = 0; | |
| for (int i = 0; i < arr.size(); i++) | |
| { | |
| if (arr.get(i) <= min) | |
| { | |
| min = arr.get(i); | |
| ind = i; | |
| } | |
| } | |
| l.add(arr.get(ind)); | |
| arr.remove(ind); | |
| min = 111111; | |
| for (int i = 0; i < arr.size(); i++) | |
| { | |
| if (arr.get(i) <= min) | |
| { | |
| ind = i; | |
| min = arr.get(i); | |
| } | |
| } | |
| l.add(arr.get(ind)); | |
| arr.remove(ind); | |
| l.addAll(arr); | |
| return l; | |
| } | |
| } |
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.ArrayList; | |
| import java.util.Scanner; | |
| /** | |
| * @author Pedro Daia | |
| */ | |
| public class primo | |
| { | |
| public static void main(final String[] args) | |
| { | |
| final Scanner s = new Scanner(System.in); | |
| int n = s.nextInt(); int k = s.nextInt(); | |
| int[] primos = new int[k]; | |
| for (int i = 0; i < k; i++) | |
| primos[i] = s.nextInt(); | |
| ArrayList<Integer> lista = new ArrayList<>(); | |
| for (int a : primos) | |
| { | |
| lista.add(a); | |
| } | |
| ArrayList<Integer> shouldnt = new ArrayList<>(); | |
| for (int i = n; i > 0; i--) | |
| { | |
| if (!shouldnt.contains(i)) | |
| { | |
| //if (i == 4) | |
| // System.out.println("passei"); | |
| for (int p : lista) | |
| { | |
| int sqrt = (int)Math.sqrt(i); | |
| if (sqrt*sqrt == i && sqrt >= p) | |
| { | |
| //System.out.println("sqrt of " +i); | |
| if ((sqrt % p) == 0) | |
| { | |
| shouldnt.add(sqrt); | |
| shouldnt.add(i); | |
| continue; | |
| } | |
| } | |
| if ((i % p) == 0) | |
| { | |
| //System.out.println("i: " + i + " e p: " + p); | |
| shouldnt.add(i); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| System.out.println(n - shouldnt.size()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment