Skip to content

Commit 3331e64

Browse files
author
mustankap
committed
added solutions of random online judges
1 parent 34f4b32 commit 3331e64

File tree

126 files changed

+3671
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+3671
-40
lines changed

testJava/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4+
<classpathentry kind="src" path=""/>
5+
<classpathentry kind="output" path=""/>
6+
</classpath>

testJava/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>src_testJava</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
1.11 KB
Binary file not shown.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* package codechef; // don't place package name! */
2+
3+
import java.util.*;
4+
5+
6+
/* Name of the class has to be "Main" only if the class is public. */
7+
class BreakingBricksCodechef
8+
{
9+
public static void main (String[] args)
10+
{
11+
12+
try {
13+
Scanner sc = new Scanner(System.in);
14+
15+
int T = sc.nextInt();
16+
while(T!=0)
17+
{
18+
int ans=0;
19+
int s = sc.nextInt();
20+
int w1 = sc.nextInt();
21+
int w2 = sc.nextInt();
22+
int w3 = sc.nextInt();
23+
24+
25+
26+
if(w1<=s)
27+
{
28+
if(w1+w2+w3<=s)
29+
{
30+
ans=1;
31+
}else if(w1+w2<=s)
32+
{
33+
ans=2;
34+
}
35+
else
36+
{
37+
ans=3;
38+
}
39+
40+
}
41+
42+
43+
44+
45+
46+
System.out.println(ans);
47+
48+
T--;
49+
}
50+
51+
52+
sc.close();
53+
} catch(Exception e) {return;
54+
}
55+
56+
}
57+
}

testJava/CHEFWARS.class

537 Bytes
Binary file not shown.

testJava/CHEFWARS.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package testJava;
2+
3+
import java.util.Scanner;
4+
5+
public class CHEFWARS {
6+
7+
public static void main(String[] args) {
8+
// TODO Auto-generated method stub
9+
Scanner sc = new Scanner(System.in);
10+
int t = sc.nextInt();
11+
while(t-->0)
12+
{
13+
int h=sc.nextInt();
14+
int p=sc.nextInt();
15+
while(p>0&&h>0)
16+
{
17+
h=h-p;
18+
p=p/2;
19+
}
20+
if((p==0||p<0)&&(h>0))
21+
{
22+
System.out.println(0);
23+
}
24+
else {
25+
System.out.println(1);
26+
}
27+
28+
}
29+
30+
}
31+
32+
}

testJava/CHELADDU.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package testJava;
2+
3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
6+
public class CHELADDU {
7+
8+
public static void main(String[] args) {
9+
// TODO Auto-generated method stub
10+
Scanner sc = new Scanner(System.in);
11+
12+
int t = sc.nextInt();
13+
while(t-->0)
14+
{
15+
int n = sc.nextInt();
16+
int k = sc.nextInt();
17+
int s[]=new int[n];
18+
19+
for(int i = 0;i<n;i++)
20+
{
21+
s[i]=sc.nextInt();
22+
}
23+
24+
Arrays.parallelSort(s);
25+
int temp=0;
26+
int min=Integer.MAX_VALUE;
27+
28+
for(int i = 0;i<n-1;i++)
29+
{
30+
temp=Math.abs((s[i+1]-s[i]));
31+
if(temp<min)
32+
{
33+
min=temp;
34+
}
35+
36+
}
37+
38+
System.out.println(min);
39+
}
40+
41+
}
42+
43+
}

testJava/CHFMOT18$FastReader.class

1012 Bytes
Binary file not shown.

testJava/CHFMOT18.class

1.84 KB
Binary file not shown.

testJava/CHFMOT18.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package testJava;
2+
import java.util.*;
3+
import java.io.*;
4+
class CHFMOT18{
5+
//SOLUTION BEGIN
6+
void pre() throws Exception{}
7+
void solve(int TC) throws Exception{
8+
long S = nl(), N = nl();
9+
long ans = 0;
10+
11+
ans += S/N;
12+
S %= N;
13+
//Check 1
14+
if(S%2 == 1){
15+
S--;
16+
ans++;
17+
}
18+
//Check 2
19+
if(S > 0)ans++;
20+
//Make sure this check 2 doesn't come before check 1, or you'll fail at cases like S = N+1
21+
pn(ans);
22+
}
23+
//SOLUTION END
24+
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
25+
static boolean multipleTC = true;
26+
FastReader in;PrintWriter out;
27+
void run() throws Exception{
28+
in = new FastReader();
29+
out = new PrintWriter(System.out);
30+
//Solution Credits: Taranpreet Singh
31+
int T = (multipleTC)?ni():1;
32+
pre();for(int t = 1; t<= T; t++)solve(t);
33+
out.flush();
34+
out.close();
35+
}
36+
public static void main(String[] args) throws Exception{
37+
new CHFMOT18().run();
38+
}
39+
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
40+
void p(Object o){out.print(o);}
41+
void pn(Object o){out.println(o);}
42+
void pni(Object o){out.println(o);out.flush();}
43+
String n()throws Exception{return in.next();}
44+
String nln()throws Exception{return in.nextLine();}
45+
int ni()throws Exception{return Integer.parseInt(in.next());}
46+
long nl()throws Exception{return Long.parseLong(in.next());}
47+
double nd()throws Exception{return Double.parseDouble(in.next());}
48+
49+
class FastReader{
50+
BufferedReader br;
51+
StringTokenizer st;
52+
public FastReader(){
53+
br = new BufferedReader(new InputStreamReader(System.in));
54+
}
55+
56+
public FastReader(String s) throws Exception{
57+
br = new BufferedReader(new FileReader(s));
58+
}
59+
60+
String next() throws Exception{
61+
while (st == null || !st.hasMoreElements()){
62+
try{
63+
st = new StringTokenizer(br.readLine());
64+
}catch (IOException e){
65+
throw new Exception(e.toString());
66+
}
67+
}
68+
return st.nextToken();
69+
}
70+
71+
String nextLine() throws Exception{
72+
String str = "";
73+
try{
74+
str = br.readLine();
75+
}catch (IOException e){
76+
throw new Exception(e.toString());
77+
}
78+
return str;
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)