diff --git a/src/main/java/com/kattis/ncpc26/p2/pending/D.java b/src/main/java/com/kattis/ncpc26/p2/pending/D.java deleted file mode 100644 index 9ff3041..0000000 --- a/src/main/java/com/kattis/ncpc26/p2/pending/D.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.kattis.ncpc26.p2.pending; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -public class D { - public static void main(String[] args) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - char[][] board = new char[8][8]; - - for(int i = 0; i < 8; i++) - { - board[i] = br.readLine().toCharArray(); - } - - int[][] dig = { - {1,1}, {-1,1}, {-1,1}, {-1,-1} - }; - - for(int bx = 0; bx < 8; bx++) - { - for(int by = 0; by < 8; by++) - { - if(board[bx][by] == '*') - { - for(int i = 0; i < 8; i++) - { - if(i == bx) continue; - if(board[i][by] == '*') - { - System.out.println("invalid"); - return; - } - } - for(int i = 0; i < 8; i++) - { - if(i == by) continue; - if(board[bx][i] == '*') - { - System.out.println("invalid"); - return; - } - } - } - for(int i = 0; i < 2; i++) - { - int[] mod = dig[i]; - int x = mod[0]; - int y = mod[1]; - int base = (i==0?0:7); - for(int j = 0; j < 8; j++) - { - if(base+x*j == bx && y*j == by) continue; - if(board[base+x*j][y*j] == '*') - { - System.out.println("invalid"); - return; - } - } - } - } - } - - System.out.println("valid"); - } -} diff --git a/src/main/java/com/kattis/ncpc26/p2/pending/E.java b/src/main/java/com/kattis/ncpc26/p2/pending/E.java deleted file mode 100644 index 6022df6..0000000 --- a/src/main/java/com/kattis/ncpc26/p2/pending/E.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.kattis.ncpc26.p2.pending; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Locale; -import java.util.Scanner; - -public class E { - public static void main(String[] args) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - int n = Integer.parseInt(br.readLine()); - - int[] maxNumber = new int[n]; - int[] minNumber = new int[n]; - - for(int i = 0; i < n; i++) - { - String hexNum = br.readLine().toUpperCase(Locale.ROOT); - - if(hexNum.length() > 1 && (hexNum.startsWith("0") || hexNum.startsWith("D"))) - { - hexNum = "d" + hexNum.substring(1); - } - { - minNumber[i] = Integer.parseInt(hexNum.replaceAll("B", "8").replaceAll("D", "0"), 16); - maxNumber[i] = Integer.parseInt(hexNum.replaceAll("8", "B").replaceAll("0", "D"), 16); - } - } - - int maxOut = 0; - int minOut = 0; - - for(int i = 0; i < n; i++) { - minOut += minNumber[i]; - maxOut += maxNumber[i]; - } - - System.out.println(Integer.toHexString(maxOut).toUpperCase(Locale.ROOT)); - System.out.println(Integer.toHexString(minOut).toUpperCase(Locale.ROOT)); - } -} diff --git a/src/main/java/com/kattis/ncpc26/p3/pending/A.java b/src/main/java/com/kattis/ncpc26/p3/pending/A.java new file mode 100644 index 0000000..d074a71 --- /dev/null +++ b/src/main/java/com/kattis/ncpc26/p3/pending/A.java @@ -0,0 +1,23 @@ +package com.kattis.ncpc26.p3.pending; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class A { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int num = Integer.parseInt(reader.readLine()); + String s = reader.readLine(); + String[] nums = s.split(" "); + for(int i = 1; i <= num; i++){ + if(!(nums[i-1].equals("mumble") || Integer.parseInt(nums[i-1]) == i)) + { + System.out.println("something is fishy"); + return; + } + } + System.out.println("makes sense"); + } +} diff --git a/src/main/java/com/kattis/ncpc26/p3/pending/B.java b/src/main/java/com/kattis/ncpc26/p3/pending/B.java new file mode 100644 index 0000000..a06e7a0 --- /dev/null +++ b/src/main/java/com/kattis/ncpc26/p3/pending/B.java @@ -0,0 +1,112 @@ +package com.kattis.ncpc26.p3.pending; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class B { + public static void main(String[] args) throws IOException { + Map> exclusiveFollowing = new HashMap<>(); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String in = reader.readLine(); + int N = Integer.parseInt(in.split(" ")[0]); + int M = Integer.parseInt(in.split(" ")[1]); + for(int i = 0; i < M; i++) + { + in = reader.readLine(); + int u = Integer.parseInt(in.split(" ")[0]); + int v = Integer.parseInt(in.split(" ")[1]); + Set followings = exclusiveFollowing.getOrDefault(v, new HashSet<>()); + followings.add(u); + exclusiveFollowing.put(v, followings); + } + + ArrayList> sortedFollowings = new ArrayList<>(); + + for(Map.Entry> user : exclusiveFollowing.entrySet()) + { + int me = user.getKey(); + int likesMe = 0; + for(int i : user.getValue()) + { + if(!exclusiveFollowing.getOrDefault(i, new HashSet<>()).contains(me)) + { + likesMe++; + } + } + sortedFollowings.add(new Pair<>(me, likesMe)); + } + + int mostFollowedUser = 1, followers = 0; + for(Pair user : sortedFollowings) + { + if(user.value > followers) + { + mostFollowedUser = user.key; + followers = user.value; + } + else if(user.value == followers) + { + if(user.key < mostFollowedUser) + { + mostFollowedUser = user.key; + } + } + } + System.out.printf("%d %d", mostFollowedUser, followers); + } + + public static class Pair { + /** + * The key of the pair. + */ + private K key; + /** + * The value of the pair. + */ + private V value; + + /** + * Creates a new instance of Pair. + * @param key The key of the pair + * @param value The value of the pair + */ + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + /** + * Gets the key of the pair. + * @return The key of the pair + */ + public K getKey() { + return key; + } + + /** + * Gets the value of the pair. + * @return The value of the pair + */ + public V getValue() { + return value; + } + + /** + * Sets the key of the pair. + * @param key The key of the pair + */ + public void setKey(K key) { + this.key = key; + } + + /** + * Sets the value of the pair. + * @param value The value of the pair + */ + public void setValue(V value) { + this.value = value; + } + } +} diff --git a/src/main/java/com/kattis/ncpc26/p3/pending/D.java b/src/main/java/com/kattis/ncpc26/p3/pending/D.java new file mode 100644 index 0000000..8fca1e8 --- /dev/null +++ b/src/main/java/com/kattis/ncpc26/p3/pending/D.java @@ -0,0 +1,91 @@ +package com.kattis.ncpc26.p3.pending; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class D { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String in; + int num = 0; + while(!(in = reader.readLine()).equals("0 0")) + { + Map> knownNumbers = new HashMap<>(); + int p = Integer.parseInt(in.split(" ")[0]); + int c = Integer.parseInt(in.split(" ")[1]); + if(p == 1) + { + System.out.println("No"); + continue; + } + for(int i = 0; i < c; i++) + { + in = reader.readLine(); + int a = Integer.parseInt(in.split(" ")[0]); + int b = Integer.parseInt(in.split(" ")[1]); + + if(!(a < p || b < p || a == b)) + { + continue; + } + + Set numbersKnown = knownNumbers.getOrDefault(a, new HashSet<>()); + numbersKnown.add(b); + knownNumbers.put(a, numbersKnown); + + numbersKnown = knownNumbers.getOrDefault(b, new HashSet<>()); + numbersKnown.add(a); + knownNumbers.put(b, numbersKnown); + } + + Set reached = new HashSet<>(); + + ArrayList toTraverse = new ArrayList<>(); + + toTraverse.add(0); + + while(!toTraverse.isEmpty()) + { + int node = toTraverse.getFirst(); + toTraverse.removeFirst(); + if(reached.contains(node)) continue; + knownNumbers.getOrDefault(node, new HashSet<>()).forEach( + (num1) -> { + if(!toTraverse.contains(num1) && !reached.contains(num1)) + { + toTraverse.add(num1); + } + } + ); + reached.add(node); + } + + if(reached.size() < p) + { + System.out.println("Yes"); + continue; + } + + boolean prematureExit = false; + + for(Map.Entry> e : knownNumbers.entrySet()) + { + if(e.getValue().size() <= 1) + { + System.out.println("Yes"); + prematureExit = true; + break; + } + } + + if(!prematureExit) + { + System.out.println("No"); + } + } + } + +} + diff --git a/src/test/java/ATest.java b/src/test/java/ATest.java deleted file mode 100644 index 6aaedf8..0000000 --- a/src/test/java/ATest.java +++ /dev/null @@ -1,39 +0,0 @@ -import com.kattis.ncpc25.log.rider.A; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class ATest { - @Test - public void ATests() - { - assertTrue(test(-4)); - assertTrue(test(57)); - assertTrue(test(-302)); - assertTrue(test(476)); - assertTrue(test(999)); - assertTrue(test(-999)); - assertTrue(test(0)); - } - - public boolean test(int in) - { - int[] nums = A.getComponents(in); - int num = nums[0] + nums[1]; - if(nums[0] == 0 || nums[1] == 0){ - System.out.println("etleast one is 0"); - System.out.println(in + " = " + nums[0] + " + " + nums[1]); - return false; - } - if((""+Math.abs(nums[0])).length() >= 4 || (""+Math.abs(nums[1])).length() >= 4){ - System.out.println(in + " = " + nums[0] + " + " + nums[1]); - return false; - } - if(num != in) - { - System.out.println(in + " = " + nums[0] + " + " + nums[1]); - return false; - } - return true; - } -} diff --git a/src/test/java/CTest.java b/src/test/java/CTest.java deleted file mode 100644 index 57404c7..0000000 --- a/src/test/java/CTest.java +++ /dev/null @@ -1,18 +0,0 @@ -import com.kattis.ncpc25.log.rider.C; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class CTest { - @Test - public void CTestCases() - { - assertEquals("7 hours", C.countTime("Mon 08:00", "Mon 15:00")); - assertEquals("7 days", C.countTime("Mon 08:00", "Mon 08:00")); - assertEquals("2 minutes", C.countTime("Mon 08:00", "Mon 08:02")); - assertEquals("1 hour and 59 minutes", C.countTime("Mon 22:00", "Mon 23:59")); - assertEquals("7 days", C.countTime("Mon 08:00", "Mon 08:00")); - assertEquals("7 days", C.countTime("Mon 08:00", "Mon 08:00")); - assertEquals("7 days", C.countTime("Mon 08:00", "Mon 08:00")); - } -} diff --git a/src/test/java/DTest.java b/src/test/java/DTest.java deleted file mode 100644 index 8f8ce8e..0000000 --- a/src/test/java/DTest.java +++ /dev/null @@ -1,22 +0,0 @@ -import com.kattis.ncpc25.log.rider.D; -import org.junit.jupiter.api.Test; - -import java.awt.*; - -import static org.junit.jupiter.api.Assertions.*; - -public class DTest { - @Test - public void DTests() - { - assertTrue(testMaxDiff(D.getTotalLength(new Point[]{new Point(-1, -7), new Point(-1, -11), new Point(0, -9), new Point(2, 2), new Point(1, -2), new Point(-2, -1), new Point(3, 1), new Point(-1, -5), new Point(0, -3), new Point(-3, -11)}), 17.186912)); - assertTrue(testMaxDiff(D.getTotalLength(new Point[]{new Point(1, 0), new Point(0,0), new Point(1,1)}), 2)); - - } - - public boolean testMaxDiff(double value, double excpected) - { - if(value == excpected) return true; - return value <= excpected + Math.pow(10, -6) && value >= excpected - Math.pow(10, -6); - } -} diff --git a/src/test/java/JTest.java b/src/test/java/JTest.java deleted file mode 100644 index 862dbf7..0000000 --- a/src/test/java/JTest.java +++ /dev/null @@ -1,60 +0,0 @@ -import com.kattis.ncpc25.log.rider.J; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class JTest { - @Test - public void JTest1() - { - assertEquals("59",J.jump(7, 9)); - } - - @Test - public void JTest2() - { - assertEquals("infinity", J.jump(7,4)); - } - - @Test - public void JTest9() - { - assertEquals("infinity", J.jump(7,4)); - } - - @Test - public void JTest3() - { - assertEquals("7581167638793024", J.jump(100001, 123123123)); - } - - @Test - public void JTest4() - { - assertEquals("infinity", J.jump(5, 3)); - } - - @Test - public void JTest5() - { - assertEquals("0", J.jump(1, 0)); - } - - @Test - public void JTest6() - { - assertEquals("21", J.jump(16, 6)); - } - - @Test - public void JTest7() - { - assertEquals("10", J.jump(11, 4)); - } - - @Test - public void JTest8() - { - assertEquals("210", J.jump(67, 20)); - } -}