File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ * Add any license header using tools << templates << licenses << default license
3+ */
4+
5+ package Implementation ;
6+
7+ /**
8+ * @author mukul goyal
9+ */
10+ import java .util .Scanner ;
11+
12+ public class AngryProfessor {
13+ public static void main (String [] args ) {
14+ Scanner sc = new Scanner (System .in );
15+ int t = sc .nextInt ();
16+ while (t !=0 ){
17+ int count =0 ;
18+ int n = sc .nextInt ();
19+ int k = sc .nextInt ();
20+ while (n !=0 ){
21+ if (sc .nextInt ()<=0 )
22+ count ++;
23+ n --;
24+ }
25+ if (count >=k )
26+ System .out .println ("NO" );
27+ else
28+ System .out .println ("YES" );
29+ t --;
30+ }
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ package Implementation ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+
7+ public class BiggerIsGreater {
8+ public static void main (String [] args ) throws IOException {
9+ BufferedReader br =new BufferedReader (new InputStreamReader (System .in ));
10+ int t =Integer .parseInt (br .readLine ());
11+ while (t -->0 ){
12+ String s =br .readLine ();
13+ char arr []=s .toCharArray ();
14+ if (!hasNext (arr ))
15+ System .out .println ("no answer" );
16+ }
17+ }
18+ public static boolean hasNext (char arr []){
19+ int n =arr .length ;
20+ int i ,j ;
21+ for (i =n -2 ;i >=0 ;i --)
22+ if (arr [i ]<arr [i +1 ])
23+ break ;
24+ if (i ==-1 )
25+ return false ;
26+ j =n -1 ;
27+ while (arr [i ]>=arr [j ])
28+ j --;
29+ char temp =arr [i ];
30+ arr [i ]=arr [j ];
31+ arr [j ]=temp ;
32+
33+ for (int r =n -1 ,s =i +1 ;r >s ;r --,s ++){
34+ temp =arr [r ];
35+ arr [r ]=arr [s ];
36+ arr [s ]=temp ;
37+ }
38+
39+ System .out .println (arr );
40+ return true ;
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Add any license header using tools << templates << licenses << default license
3+ */
4+
5+ package Implementation ;
6+
7+ /**
8+ * @author mukul goyal
9+ */
10+ import java .util .Scanner ;
11+ public class CutTheSticks {
12+ public static void main (String [] args ) {
13+ Scanner sc = new Scanner (System .in );
14+ int n = sc .nextInt ();
15+ int a [] = new int [n ];
16+ int i ;
17+ for (i =0 ;i <n ;i ++)
18+ a [i ] = sc .nextInt ();
19+ int count ;
20+ do {
21+ int min = 1000 ;
22+ for (i =0 ;i <n ;i ++){
23+ if (a [i ]<min && a [i ]!=0 )
24+ min = a [i ];
25+ }
26+ count =0 ;
27+ for (i =0 ;i <n ;i ++){
28+ if (a [i ]!=0 ){
29+ a [i ] = a [i ] - min ;
30+ count ++;
31+ }
32+ }
33+ if (count ==0 )
34+ break ;
35+ System .out .println (count );
36+ }
37+ while (count !=1 );
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Add any license header using tools << templates << licenses << default license
3+ */
4+
5+ package Implementation ;
6+
7+ import java .util .Scanner ;
8+
9+ /**
10+ * @author mukul goyal
11+ */
12+
13+ public class Encryption {
14+ public static void main (String [] args ){
15+ Scanner sc = new Scanner (System .in );
16+ char [] s = sc .next ().toCharArray ();
17+ int l = s .length ;
18+ char [] b = new char [l ];
19+ int rows = (int ) Math .floor (Math .sqrt (l ));
20+ int columns = (int ) Math .ceil (Math .sqrt (l ));
21+ int min =0 ;
22+ int min1 = rows *columns ;
23+ int min2 = rows *(columns -1 );
24+ int min3 = (rows +1 )*columns ;
25+ if (min2 <min1 && min2 >=l ){
26+ columns --;
27+ min = rows *columns ;
28+ }
29+ else if (min1 <min3 && min1 >=l )
30+ min = rows *columns ;
31+ else if (min3 >=l ){
32+ rows ++;
33+ min = rows *columns ;
34+ }
35+ for (int i =0 ;i <columns ;i ++){
36+ for (int j =i ;j <l ;j +=columns ){
37+ if (s [j ]!='\0' )
38+ System .out .print (s [j ]);
39+ }
40+ System .out .print (" " );
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ package Implementation ;
2+
3+ import java .util .Arrays ;
4+ import java .util .Scanner ;
5+
6+ public class FlatlandSpaceStations {
7+ public static void main (String [] args ) {
8+ Scanner in = new Scanner (System .in );
9+ int n = in .nextInt ();
10+ int m = in .nextInt ();
11+ int c [] = new int [m ];
12+ for (int c_i =0 ; c_i < m ; c_i ++){
13+ c [c_i ] = in .nextInt ();
14+ }
15+ Arrays .sort (c );
16+ int a []=new int [n ];
17+ int i =0 ;
18+ int max =0 ;
19+ while (i ==c [0 ]){
20+ a [i ]=Math .abs (c [0 ]-i );
21+ if (a [i ]>max ){
22+ max =a [i ];
23+ }
24+ i ++;
25+ }
26+ int curr =0 ,next =1 ;
27+ while (next <m &&i <n ){
28+ a [i ]=Math .min (Math .abs (c [next ]-i ),Math .abs (i -c [curr ]));
29+ if (a [i ]>max ){
30+ max =a [i ];
31+ }
32+ if (c [next ]<=i ){
33+ curr ++;
34+ next ++;
35+ }
36+ i ++;
37+ }
38+ while (i <n ){
39+ a [i ]=Math .abs (c [curr ]-i );
40+ if (a [i ]>max ){
41+ max =a [i ];
42+ }
43+ i ++;
44+ }
45+ System .out .println (max );
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Add any license header using tools << templates << licenses << default license
3+ */
4+
5+ package Implementation ;
6+
7+ /**
8+ * @author mukul goyal
9+ */
10+ import java .util .Scanner ;
11+
12+ public class JumpingOnClouds {
13+ public static void main (String [] args ) {
14+ Scanner in = new Scanner (System .in );
15+ int n = in .nextInt ();
16+ int c [] = new int [n ];
17+ for (int c_i =0 ; c_i < n ; c_i ++){
18+ c [c_i ] = in .nextInt ();
19+ }
20+ int i =0 ,j =0 ;
21+ while (i <n -1 ){
22+ if (i +2 <n &&c [i +2 ]==0 )
23+ i +=2 ;
24+ else
25+ i ++;
26+ j ++;
27+ }
28+ System .out .println (j );
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package Implementation ;
2+
3+ import java .util .Scanner ;
4+
5+ public class JumpingOnCloudsRevisited {
6+ public static void main (String [] args ) {
7+ Scanner in = new Scanner (System .in );
8+ int n = in .nextInt ();
9+ int k = in .nextInt ();
10+ int c [] = new int [n ];
11+ for (int c_i =0 ; c_i < n ; c_i ++){
12+ c [c_i ] = in .nextInt ();
13+ }
14+ int e =100 ;
15+ int i =0 ;
16+ while (true ){
17+ i =(i +k )%n ;
18+ e --;
19+ if (c [i ]==1 )
20+ e -=2 ;
21+ if (i ==0 )
22+ break ;
23+ }
24+ System .out .println (e );
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ package Implementation ;
2+
3+ import java .util .Scanner ;
4+
5+ public class LisaWorkbook {
6+ public static void main (String [] args ) {
7+ Scanner sc =new Scanner (System .in );
8+ int n =sc .nextInt ();
9+ int k =sc .nextInt ();
10+ int t []=new int [n ];
11+ for (int i =0 ;i <n ;i ++){
12+ t [i ]=sc .nextInt ();
13+ }
14+ int page =1 ;
15+ int p ,s ,count =0 ;
16+ for (int i =0 ;i <n ;i ++){
17+ p =t [i ]/k ;
18+ s =1 ;
19+ while (p --!=0 ){
20+ if (page >=s &&page <=s +k -1 )
21+ count ++;
22+ s +=k ;
23+ page ++;
24+ }
25+ if (t [i ]%k !=0 ){
26+ if (page >=s &&page <=t [i ])
27+ count ++;
28+ page ++;
29+ }
30+ }
31+ System .out .println (count );
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ package Implementation ;
2+
3+ import java .util .Scanner ;
4+
5+ public class MinimumDistances {
6+ public static void main (String [] args ) {
7+ Scanner in = new Scanner (System .in );
8+ int n = in .nextInt ();
9+ int A [] = new int [n ];
10+ for (int A_i =0 ; A_i < n ; A_i ++){
11+ A [A_i ] = in .nextInt ();
12+ }
13+ int min =n ;
14+ for (int i =0 ;i <n ;i ++){
15+ for (int j =i +1 ;j <n ;j ++){
16+ if (A [i ]==A [j ])
17+ if (j -i <min )
18+ min =j -i ;
19+ }
20+ }
21+ System .out .println ((min ==n )?"-1" :min );
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package Implementation ;
2+
3+ import java .util .Scanner ;
4+
5+ public class SaveThePrisoner {
6+ public static void main (String [] args ) {
7+ Scanner sc =new Scanner (System .in );
8+ int t =sc .nextInt ();
9+ while (t -->0 ){
10+ int n =sc .nextInt ();
11+ int m =sc .nextInt ();
12+ int s =sc .nextInt ()-1 ;
13+ while (m -->0 ){
14+ s ++;
15+ if (s >n )
16+ s =s %n ;
17+ }
18+ System .out .println (s );
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments