diff --git a/Day6Problem1.cpp b/Day6Problem1.cpp new file mode 100644 index 0000000..dc4c315 --- /dev/null +++ b/Day6Problem1.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +// Sort and compare. +// Do as you are told. +int main() +{ + int n; + int arr[100000]; + scanf("%d",&n); + for (int i=0;i diff; + for (int i=0;i +#include +#include +#include +#include +#include +#include + +int main(){ + int n,c_i,count=0; + scanf("%d",&n); + int *c = malloc(sizeof(int) * n); + for(c_i = 0; c_i < n-1; c_i++){ + scanf("%d",&c[c_i]); + } + for(c_i = 0; c_i < n-1; c_i++) + { + if(c[(c_i)+2]==0) + { + c_i++; + count++; + } + else if(c[(c_i)+1]==0) + { + count++; + } + } + printf("%d",count); + return 0; +} diff --git a/Day6Problem3.cpp b/Day6Problem3.cpp new file mode 100644 index 0000000..f18214f --- /dev/null +++ b/Day6Problem3.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +int main() { + int t; + scanf("%d",&t); + while (t--) + { + int n; + int arr[1000]; + scanf("%d",&n); + for (int i=0;i arr[j]) + inv ++; + if (inv%2==0) + printf("YES\n"); + else + printf("NO\n"); + } + return 0; +} diff --git a/Day6Problem4.cpp b/Day6Problem4.cpp new file mode 100644 index 0000000..4d7d393 --- /dev/null +++ b/Day6Problem4.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +using namespace std; + +// Main algorithm: in order to rotate the whole matrix, we'll just rotate one ring at a time +// We can do this in-place to achieve O(1) additional space complexity +int main() { + int M, N, R; + cin>>M>>N>>R; + int **matrix = new int*[M]; + for(int i = 0; i < M; i++) { + matrix[i] = new int[N]; + for(int j = 0; j < N; j++) { + cin>>matrix[i][j]; + } + } + + int numRings = min(M,N)/2; + for(int i = 0; i < numRings; i++) { + // Subtract the number of 360 degree rotations from R + // A 360 degree rotation = rotating the same number of times as the perimeter of the current ring + int numRotations = R%(2*(M + N - 4*i) - 4); + for(int rotation = 0; rotation < numRotations; rotation++) { + // Rotate the ring (see the clockwise algorithm for an in-depth example of how this is done) + // Rotate top row + for(int j = i; j < N-i-1; j++) { + int tmp = matrix[i][j]; + matrix[i][j] = matrix[i][j+1]; + matrix[i][j+1] = tmp; + } + // Rotate right column + for(int j = i; j < M-i-1; j++) { + int tmp = matrix[j][N-i-1]; + matrix[j][N-i-1] = matrix[j+1][N-i-1]; + matrix[j+1][N-i-1] = tmp; + } + // Rotate bottom row + for(int j = N-i-1; j > i; j--) { + int tmp = matrix[M-i-1][j]; + matrix[M-i-1][j] = matrix[M-i-1][j-1]; + matrix[M-i-1][j-1] = tmp; + } + // Rotate left column + for(int j = M-i-1; j > i+1; j--) { + int tmp = matrix[j][i]; + matrix[j][i] = matrix[j-1][i]; + matrix[j-1][i] = tmp; + } + } + } + // Output final matrix + for(int i = 0; i < M; i++) { + for(int j = 0; j < N; j++) { + cout< edges; + + Node(int val) { + this.value = val; + total = 0; + edges = new ArrayList<>(); + } + + @Override + public String toString() { + return "Val: " + value + " | Total: " + total; //+ " | Edges: " + edges.toString(); + } + } + + private static HashSet visited = new HashSet<>(); + + private static void findTotal(Node n) { + visited.add(n); + if(n.edges.isEmpty()) { + n.total = n.value; + } else { + int total = n.value; + for(Node edge : n.edges) { + if(visited.contains(edge)) continue; + visited.add(edge); + findTotal(edge); + total+=edge.total; + } + n.total = total; + } + } + + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + int N = input.nextInt(); + + Node[] nodeArr = new Node[N]; + for(int i=0; i valSet = new HashSet<>(); + for (int i=0; i modSet = new HashSet<>(valSet); + int pairs = 0; + for(int val : valSet) { + if(modSet.contains(val+K) || modSet.contains(val-K)) { + pairs++; + } + modSet.remove(val); + } + System.out.print(pairs); + } +} diff --git a/Raghavtroublemaker/Day5Problem4.java b/Raghavtroublemaker/Day5Problem4.java new file mode 100644 index 0000000..4fbc71d --- /dev/null +++ b/Raghavtroublemaker/Day5Problem4.java @@ -0,0 +1,25 @@ +public class ANewHope { + + /* + * The strategy will be to create a new week and try to swap shirt values to + * look more like the last week until the conditions are met, or we until + * we can no longer move shirts around without violating the conditions. + */ + public int count(int[] firstWeek, int[] lastWeek, int D) { + int N = firstWeek.length; + + boolean same = true; + for(int i=0; i temp = new HashSet<>(); + temp.add(target); + + while(initial.length() != len) { + Set nTemp = new HashSet<>(); + for(String t : temp) { + if(t.endsWith("A")) nTemp.add(t.substring(0,t.length()-1)); + else if(t.endsWith("B")) nTemp.add(reverse(t.substring(0,t.length()-1))); + } + len--; + + temp.clear(); + temp.addAll(nTemp); + } + + if(temp.contains(initial)) return PASS; + else return FAIL; + } + + private static String reverse(String initial) { + int len = initial.length(); + char[] arr = initial.toCharArray(); + for(int i=0; i