Skip to content

Commit

Permalink
Merge pull request Rohit0301#64 from v-apor/CodeForces-Problems
Browse files Browse the repository at this point in the history
CodeForces Solutions | CF Problem List
  • Loading branch information
Rohit0301 authored Oct 3, 2022
2 parents 21a8937 + f7a234c commit d4c159c
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CodeForces/Airplane.java
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));
}
}
28 changes: 28 additions & 0 deletions CodeForces/BusinessProblem.java
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);
}
}
21 changes: 21 additions & 0 deletions CodeForces/Copy.java
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());
}
}
}
28 changes: 28 additions & 0 deletions CodeForces/DeathNote.java
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(" ");
}
}
}
18 changes: 18 additions & 0 deletions CodeForces/EmployeeDivide.java
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);
}
}
16 changes: 16 additions & 0 deletions CodeForces/FourSegment.java
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]);
}
}
}
33 changes: 33 additions & 0 deletions CodeForces/Killer.java
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]);
}
}
}
18 changes: 18 additions & 0 deletions CodeForces/Points.java
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);
}
}
}
26 changes: 26 additions & 0 deletions CodeForces/Teams.java
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);
}
}
40 changes: 40 additions & 0 deletions CodeForces/TheatreSquare.java
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);
}
}

0 comments on commit d4c159c

Please sign in to comment.