-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added solution of some codeforces problems
- Loading branch information
1 parent
e859dc4
commit 6675803
Showing
102 changed files
with
3,065 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Eclipse | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Intellij | ||
.idea/ | ||
*.iml | ||
*.iws | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# Maven | ||
log/ | ||
target/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
**/DO_NOT_MAKE* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>CODEFORCES</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
</project> |
48 changes: 48 additions & 0 deletions
48
CODEFORCES/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/AmusingJoke.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class AmusingJoke { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
char[] aA = br.readLine().toCharArray(); | ||
char[] bA = br.readLine().toCharArray(); | ||
char[] cA = br.readLine().toCharArray(); | ||
HashMap<Character,Integer> hM = new HashMap<>(); | ||
for(char c : aA){ | ||
if(hM.containsKey(c)){ | ||
hM.put(c,hM.get(c)+1); | ||
}else{ | ||
hM.put(c,1); | ||
} | ||
} | ||
for(char c : bA){ | ||
if(hM.containsKey(c)){ | ||
hM.put(c,hM.get(c)+1); | ||
}else{ | ||
hM.put(c,1); | ||
} | ||
} | ||
for(char c : cA){ | ||
if(hM.containsKey(c)){ | ||
if(hM.get(c) ==1){ | ||
hM.remove(c); | ||
}else{ | ||
hM.put(c,hM.get(c)-1); | ||
} | ||
}else{ | ||
System.out.println("NO"); | ||
return; | ||
} | ||
} | ||
|
||
System.out.println(hM.size()==0 ?"YES" : "NO"); | ||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/141/A |
27 changes: 27 additions & 0 deletions
27
...ORCES/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/AntonAndLetters.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class AntonAndLetters { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
String a = br.readLine(); | ||
if(a.equals("{}")){ | ||
System.out.println("0"); | ||
return; | ||
} | ||
String[] sA = a.replaceAll("[{}]","").split(", "); | ||
HashSet<String> hs = new HashSet<>(Arrays.asList(sA)); | ||
System.out.println(hs.size()); | ||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/443/A | ||
//https://codeforces.com/problemset/submission/443/9135498 | ||
//https://codeforces.com/problemset/submission/443/71889288 |
27 changes: 27 additions & 0 deletions
27
...S/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/AntonAndPolyhedrons.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class AntonAndPolyhedrons { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
int t = Integer.parseInt(br.readLine()),tetrahedronCount = 0,cubeCount = 0,octahedronCount=0, | ||
dodecahedronCount = 0,icosahedronCount = 0; | ||
while (t-- > 0){ | ||
String temp = br.readLine(); | ||
if(temp.charAt(0) == 'T') tetrahedronCount++; | ||
if(temp.charAt(0) == 'C') cubeCount++; | ||
if(temp.charAt(0) == 'O') octahedronCount++; | ||
if(temp.charAt(0) == 'D') dodecahedronCount++; | ||
if(temp.charAt(0) == 'I') icosahedronCount++; | ||
} | ||
System.out.println(tetrahedronCount*4+cubeCount*6+octahedronCount*8+ | ||
dodecahedronCount*12+icosahedronCount*20); | ||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/785/A |
27 changes: 27 additions & 0 deletions
27
CODEFORCES/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/Boredom.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class Boredom { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
int n = Integer.parseInt(br.readLine()); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
long[] dp = new long[100001]; | ||
long[] count = new long[100001]; | ||
while (st.hasMoreTokens()){ | ||
count[Integer.parseInt(st.nextToken())]++; | ||
} | ||
dp[0] = 0; | ||
dp[1] = count[1]; | ||
for (int i = 2; i <=100000 ; i++) { | ||
dp[i] = Math.max(dp[i-1],dp[i-2]+i*count[i]); | ||
} | ||
System.out.println(dp[100000]); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
CODEFORCES/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/BuyAShovel.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class BuyAShovel { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
String[] nm = br.readLine().split("\\s+"); | ||
int k = Integer.parseInt(nm[0]); | ||
int l = Integer.parseInt(nm[1]); | ||
int ans = 1,temp = k; | ||
do{ | ||
k = temp * ans; | ||
ans++; | ||
}while(!(k%10 == 0 || k%10 == l)); | ||
System.out.println(ans-1); | ||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/732/A | ||
//https://codeforces.com/problemset/submission/732/31230583 |
21 changes: 21 additions & 0 deletions
21
.../src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/CandiesAndTwoSisters.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class CandiesAndTwoSisters { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
int t = Integer.parseInt(br.readLine()); | ||
while (t-- > 0){ | ||
int n = Integer.parseInt(br.readLine()); | ||
System.out.println((n-1)/2); | ||
} | ||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/1335/A | ||
//https://codeforces.com/problemset/submission/1335/76633824 |
28 changes: 28 additions & 0 deletions
28
CODEFORCES/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/CheapTravel.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class CheapTravel { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
int n = Integer.parseInt(st.nextToken()); | ||
int m = Integer.parseInt(st.nextToken()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
System.out.println( | ||
m*a >= b ? | ||
(n/m)*b+( b < (n%m)*a ? b : (n%m)*a) | ||
:n*a | ||
); | ||
|
||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/466/A | ||
//https://codeforces.com/problemset/submission/466/9272194 |
65 changes: 65 additions & 0 deletions
65
CODEFORCES/src/main/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/CutRibbon.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class CutRibbon { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
String[] nm = br.readLine().split("\\s+"); | ||
int n = Integer.parseInt(nm[0]); | ||
int a = Integer.parseInt(nm[1]); | ||
int b = Integer.parseInt(nm[2]); | ||
int c = Integer.parseInt(nm[3]); | ||
// System.out.println(iterativeSolution(n,a,b,c)); | ||
System.out.println(dpSolution(n,a,b,c)); | ||
} | ||
|
||
private static int dpSolution(int n, int a, int b, int c) { | ||
int[] dp = new int[n+1]; | ||
Arrays.fill(dp,-1); | ||
dp[0] = 0; | ||
for (int i = 0; i <= n; i++) { | ||
if(dp[i] != -1){ | ||
if(i+a<=n){ | ||
dp[i+a] = Math.max(dp[i]+1,dp[i+a]); | ||
} | ||
if(i+b<=n){ | ||
dp[i+b] = Math.max(dp[i]+1,dp[i+b]); | ||
} | ||
if(i+c<=n){ | ||
dp[i+c] = Math.max(dp[i]+1,dp[i+c]); | ||
} | ||
} | ||
} | ||
return dp[n]; | ||
} | ||
|
||
private static int iterativeSolution(int n, int a, int b, int c) { | ||
int ans = 0; | ||
for(int x = 0;x <= 4000;x++){ | ||
for (int y = 0; y <=4000 ; y++) { | ||
int zc = n - (x*a+y*b); | ||
if(zc<0){ | ||
break; | ||
} | ||
double z = (zc/(double)c); | ||
if(z == (int)z){ | ||
ans = Math.max(ans,(int) (x+y+z)); | ||
} | ||
} | ||
} | ||
return ans; | ||
} | ||
} | ||
|
||
/* | ||
https://pythontutor.com/visualize.html#code=%0Aimport%20java.util.*%3B%0A%0Apublic%20class%20GFG%0A%7B%0A%20%20%20%20%0A%20%20%20%20//%20function%20to%20find%20the%20maximum%0A%20%20%20%20//%20number%20of%20segments%0A%20%20%20%20static%20int%20maximumSegments%28int%20n,%20int%20a,%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int%20b,%20int%20c%29%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20//%20stores%20the%20maximum%20number%20of%0A%20%20%20%20%20%20%20%20//%20segments%20each%20index%20can%20have%0A%20%20%20%20%20%20%20%20int%20dp%5B%5D%20%3D%20new%20int%5Bn%20%2B%2010%5D%3B%0A%0A%20%20%20%20%20%20%20%20//%20initialize%20with%20-1%0A%20%20%20%20%20%20%20%20Arrays.fill%28dp,%20-1%29%3B%0A%0A%20%20%20%20%20%20%20%20//%200th%20index%20will%20have%200%20segments%0A%20%20%20%20%20%20%20%20//%20base%20case%0A%20%20%20%20%20%20%20%20dp%5B0%5D%20%3D%200%3B%0A%0A%20%20%20%20%20%20%20%20//%20traverse%20for%20all%20possible%0A%20%20%20%20%20%20%20%20//%20segments%20till%20n%0A%20%20%20%20%20%20%20%20for%20%28int%20i%20%3D%200%3B%20i%20%3C%20n%3B%20i%2B%2B%29%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20%28dp%5Bi%5D%20!%3D%20-1%29%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20//%20conditions%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%28i%20%2B%20a%20%3C%3D%20n%20%29%20//avoid%20buffer%20overflow%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dp%5Bi%20%2B%20a%5D%20%3D%20Math.max%28dp%5Bi%5D%20%2B%201,%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dp%5Bi%20%2B%20a%5D%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%28i%20%2B%20b%20%3C%3D%20n%20%29%20//avoid%20buffer%20overflow%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dp%5Bi%20%2B%20b%5D%20%3D%20Math.max%28dp%5Bi%5D%20%2B%201,%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dp%5Bi%20%2B%20b%5D%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%28i%20%2B%20c%20%3C%3D%20n%20%29%20//avoid%20buffer%20overflow%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dp%5Bi%20%2B%20c%5D%20%3D%20Math.max%28dp%5Bi%5D%20%2B%201,%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dp%5Bi%20%2B%20c%5D%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20return%20dp%5Bn%5D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20//%20Driver%20code%0A%20%20%20%20public%20static%20void%20main%28String%20arg%5B%5D%29%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20int%20n%20%3D%207,%20a%20%3D%205,%20b%20%3D%202,%20c%20%3D%205%3B%0A%20%20%20%20%20%20%20%20System.out.print%28maximumSegments%28n,%20a,%20b,%20c%29%29%3B%0A%20%20%20%20%7D%0A%7D%0A%0A//%20This%20code%20is%20contributed%20by%20Anant%20Agarwal.&cumulative=false&curInstr=57&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=java&rawInputLstJSON=%5B%5D&textReferences=false | ||
https://codeforces.com/problemset/problem/189/A | ||
https://codeforces.com/problemset/submission/189/71926332 | ||
*/ |
45 changes: 45 additions & 0 deletions
45
...in/java/com/mishra/aman/problemlevelA/fiftytoseventyfive/DesignTutorialLearnFromMath.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.mishra.aman.problemlevelA.fiftytoseventyfive; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
import static java.lang.System.in; | ||
|
||
public class DesignTutorialLearnFromMath { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | ||
int n = Integer.parseInt(br.readLine()); | ||
/*boolean[] primalityArray = new boolean[n+1]; | ||
Arrays.fill(primalityArray,true); | ||
sieveofEratosthenes(primalityArray,n+1); | ||
for (int i = 4; i < n; i+=2) { | ||
if(!primalityArray[n-i]){ | ||
System.out.println(i+ " "+ (n-i)); | ||
break; | ||
} | ||
}*/ | ||
solution(n); | ||
} | ||
|
||
private static void solution(int n) { | ||
if(n%2 == 0){ | ||
System.out.println(n-4+" "+4); | ||
}else{ | ||
System.out.println(n-9 +" " + 9); | ||
} | ||
} | ||
|
||
private static void sieveofEratosthenes(boolean[] primalityArray,int n) { | ||
for (int i = 2; i < Math.sqrt(n); i++) { | ||
if(primalityArray[i]){ | ||
for (int j = i*i; j < n; j+=i) { | ||
primalityArray[j] = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//https://codeforces.com/problemset/problem/472/A |
Oops, something went wrong.