forked from Rohit0301/Compititive_programming_code
-
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.
Merge pull request Rohit0301#64 from v-apor/CodeForces-Problems
CodeForces Solutions | CF Problem List
- Loading branch information
Showing
10 changed files
with
243 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,15 @@ | ||
//problem: https://codeforces.com/problemset/problem/965/A | ||
|
||
import java.lang.Math; | ||
import java.util.Scanner; | ||
public class Airplane{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
double k = sObj.nextDouble(); | ||
double n = sObj.nextDouble(); | ||
double s = sObj.nextDouble(); | ||
double p = sObj.nextDouble(); | ||
double total_sheet = k*Math.ceil(n/s); | ||
System.out.println((int) Math.ceil(total_sheet/p)); | ||
} | ||
} |
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 @@ | ||
// problem: https://codeforces.com/problemset/problem/981/B | ||
import java.util.Scanner; | ||
import java.util.HashMap; | ||
public class BusinessProblem{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int n = sObj.nextInt(); | ||
HashMap<Long,Long> hMap = new HashMap<Long,Long>(); | ||
Long temp; | ||
Long value; | ||
for(int z=0; z<n; z++){ | ||
temp = sObj.nextLong(); | ||
value = sObj.nextLong(); | ||
if(hMap.containsKey(temp)) if(hMap.get(temp) > value) continue; | ||
hMap.put(temp, value); | ||
} | ||
int m = sObj.nextInt(); | ||
for(int zz=0; zz<m; zz++){ | ||
temp = sObj.nextLong(); | ||
value = sObj.nextLong(); | ||
if(hMap.containsKey(temp)) if(hMap.get(temp) > value) continue; | ||
hMap.put(temp, value); | ||
} | ||
Long total = (long) 0; | ||
for(Long ele: hMap.values()) total += ele; | ||
System.out.println(total); | ||
} | ||
} |
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 @@ | ||
//problem: https://codeforces.com/problemset/problem/1325/B | ||
|
||
import java.util.HashSet; | ||
import java.util.Scanner; | ||
|
||
public class Copy{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int cases = Integer.parseInt(sObj.nextLine()); | ||
int size = 0; | ||
for(int i=0; i<cases; i++){ | ||
HashSet hSet = new HashSet(); | ||
size = Integer.parseInt(sObj.nextLine()); | ||
for(int j=0; j<size; j++){ | ||
hSet.add(sObj.nextInt()); | ||
} | ||
sObj.nextLine(); | ||
System.out.println(hSet.size()); | ||
} | ||
} | ||
} |
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 @@ | ||
//problem: https://codeforces.com/problemset/problem/1016/A | ||
|
||
import java.util.Scanner; | ||
public class DeathNote{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int days = sObj.nextInt(); | ||
int max = sObj.nextInt(); | ||
int[] arr = new int[days]; | ||
for(int z=0; z<days; z++){ | ||
arr[z] = sObj.nextInt(); | ||
} | ||
int modMax = max; | ||
for(int i=0; i<days; i++){ | ||
//System.out.println("leftInPage: " + modMax + "\nToPrintToday: " + arr[i]); | ||
|
||
if(arr[i]<modMax){ | ||
System.out.print(0); | ||
modMax = modMax - arr[i]; | ||
} | ||
else{ | ||
System.out.print((arr[i]-modMax)/max + 1); | ||
modMax = max - ((arr[i]-modMax) % max); | ||
} | ||
System.out.print(" "); | ||
} | ||
} | ||
} |
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,18 @@ | ||
//problem: https://codeforces.com/problemset/problem/935/A | ||
|
||
import java.util.Scanner; | ||
public class EmployeeDivide{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int noEmp = sObj.nextInt(); | ||
//System.out.print(noEmp); | ||
int result = 0; | ||
for(int i=1; i<=noEmp/2; i++){ | ||
if(noEmp%i==0){ | ||
//System.out.println(i); | ||
result++; | ||
} | ||
} | ||
System.out.print(result); | ||
} | ||
} |
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 @@ | ||
// Problem: https://codeforces.com/problemset/problem/1468/E | ||
|
||
import java.util.Scanner; | ||
import java.util.Arrays; | ||
public class FourSegment{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int css = sObj.nextInt(); | ||
for(int zz=0; zz<css; zz++){ | ||
int[] sides = new int[4]; | ||
for(int i=0; i<4; i++) sides[i] = sObj.nextInt(); | ||
Arrays.sort(sides); | ||
System.out.println(sides[0] * sides[2]); | ||
} | ||
} | ||
} |
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,33 @@ | ||
// problem: https://codeforces.com/problemset/problem/776/A | ||
|
||
import java.util.Scanner; | ||
|
||
public class Killer{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
String[] persons = new String[2]; | ||
String[] temp = new String[2]; | ||
int i = 0; | ||
int x = 0; | ||
for(String s: sObj.nextLine().split(" ")){ | ||
persons[i] = s; | ||
i++; | ||
} | ||
int scenarios = Integer.parseInt(sObj.nextLine()); | ||
System.out.println(persons[0] + " " + persons[1]); | ||
for(int j=0; j<scenarios; j++){ | ||
x=0; | ||
for(String z: sObj.nextLine().split(" ")){ | ||
temp[x] = z; | ||
x++; | ||
} | ||
if(persons[0].equals(temp[0])){ | ||
persons[0] = temp[1]; | ||
} | ||
else{ | ||
persons[1] = temp[1]; | ||
} | ||
System.out.println(persons[0] + " " + persons[1]); | ||
} | ||
} | ||
} |
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,18 @@ | ||
// https://codeforces.com/problemset/problem/1108/A | ||
|
||
import java.util.Scanner; | ||
public class Points{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int css = sObj.nextInt(); | ||
for(int zz=0; zz<css; zz++){ | ||
int l = sObj.nextInt(); | ||
sObj.nextInt(); | ||
sObj.nextInt(); | ||
int r = sObj.nextInt(); | ||
if(l == r) l++; | ||
System.out.print(l + " "); | ||
System.out.println(r); | ||
} | ||
} | ||
} |
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,26 @@ | ||
//problem: https://codeforces.com/problemset/problem/1092/B | ||
|
||
import java.util.Scanner; | ||
import java.util.Arrays; | ||
|
||
public class Teams{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
int n = Integer.parseInt(sObj.nextLine()); | ||
int[] arr = new int[n]; | ||
for(int i=0; i<n; i++){ | ||
arr[i] = sObj.nextInt(); | ||
} | ||
Arrays.sort(arr); | ||
int total = 0; | ||
for(int i=n-1; i>=0; i--){ | ||
if(i%2==0){ | ||
total -= arr[i]; | ||
} | ||
else{ | ||
total += arr[i]; | ||
} | ||
} | ||
System.out.println(total); | ||
} | ||
} |
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,40 @@ | ||
//problem: https://codeforces.com/problemset/problem/1/A | ||
|
||
// import java.util.Scanner; | ||
// import java.lang.Math; | ||
|
||
// public class TheatreSquare{ | ||
// public static void main(String[] args){ | ||
// Scanner sObj = new Scanner(System.in); | ||
// int l = sObj.nextInt(); | ||
// int b = sObj.nextInt(); | ||
// float side = (float) sObj.nextInt(); | ||
|
||
// System.out.println((int) (Math.ceil(l/side) + Math.ceil(b/side))); | ||
// } | ||
// } | ||
|
||
import java.util.Scanner; | ||
import java.lang.Math; | ||
|
||
public class TheatreSquare{ | ||
public static void main(String[] args){ | ||
Scanner sObj = new Scanner(System.in); | ||
long l = sObj.nextLong(); | ||
long b = sObj.nextLong(); | ||
double side = (double) sObj.nextInt(); | ||
//System.out.println("Side: " + side); | ||
long total = 0; | ||
if(l<=side && b<=side){ | ||
System.out.print(1); | ||
return; | ||
} | ||
else{ | ||
total += Math.ceil(Math.max(l,b) / side); | ||
if(Math.min(l,b) > side){ | ||
total *= Math.ceil(Math.min(l,b) / side); | ||
} | ||
} | ||
System.out.println(total); | ||
} | ||
} |