Ada Bishop 2 - ADASHOP2 – CODECHEF MARCH LONG CHALLENGE(EASY)
Ada Bishop 2 Problem Code: ADASHOP2 – Codechef march long challenge(easy)
Given a cell in which Ada placed the bishop first. We have
to say the path which covers all the black cells in a chess.
Easily we can just type the coordinates of cells for the
required path.
For the subtask1 we can type the path which covers all black
cells.
For subtask2:
Wherever the cell Ada placed first, if we first move the
bishop on to the diagonal and next if we move to the cell (1,1) now we can just
print the path which we got in subtask1.
This is my path from (1,1) which covers all black cells.
Look at this c code for clarification:
#include <stdio.h>
int main(void) {
// your
code goes here
int t;
scanf("%d",&t);
while(t--)
{
int r,c;
scanf("%d%d",&r,&c);
if(r==1 && c==1) //first subtask
{
printf("34\n2 2\n3 1\n4 2\n5 1\n6
2\n7 1\n8 2\n7 3\n8 4\n7 5\n6 4\n5 3\n4 4\n3 3\n2 4\n1 3\n2 4\n1 5 \n2 6\n3 5\n4
6\n5 5\n6 6\n7 7\n8 6\n7 7\n8 8\n7 7\n6 8\n5 7\n4 8\n3 7\n2 8\n1 7\n");
}
else //second subtask
{
if(r==c) // if r and c are same then it is
on diagonal so moving to (1,1) is enough
{
printf("35\n1 1\n2 2\n3 1\n4
2\n5 1\n6 2\n7 1\n8 2\n7 3\n8 4\n7 5\n6 4\n5 3\n4 4\n3 3\n2 4\n1 3\n2 4\n1 5
\n2 6\n3 5\n4 6\n5 5\n6 6\n7 7\n8 6\n7 7\n8 8\n7 7\n6 8\n5 7\n4 8\n3 7\n2 8\n1
7\n");
}
else //if r!=c first we need to go on
to diagonal then to (1,1)
{
printf("36\n%d %d\n1 1\n2 2\n3
1\n4 2\n5 1\n6 2\n7 1\n8 2\n7 3\n8 4\n7 5\n6 4\n5 3\n4 4\n3 3\n2 4\n1 3\n2 4\n1
5 \n2 6\n3 5\n4 6\n5 5\n6 6\n7 7\n8 6\n7 7\n8 8\n7 7\n6 8\n5 7\n4 8\n3 7\n2
8\n1 7\n",(r+c)/2,(r+c)/2);
}
}
}
return
0;
}
Ok, Here is my solution- (maximum steps -21)
ReplyDeleteimport java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=Integer.parseInt(sc.nextLine());
for(int z=0;z<t;z++){
String[] s=sc.nextLine().split(" ");
int r0=Integer.parseInt(s[0]);
int c0=Integer.parseInt(s[1]);
boolean moved=false;
String steps="";
int nsteps=19;
if (!(r0==1&&c0==1))
{
if(r0-c0==0){
steps+="1 1\n";
moved=true;
}
else if(r0+c0==4){
steps+="2 2\n";
}
else if(r0+c0==6){
steps+="3 3\n";
}
else if(r0+c0==8){
steps+="4 4\n";
}
else if(r0+c0==10){
steps+="5 5\n";
}
else if(r0+c0==12){
steps+="6 6\n";
}
else if(r0+c0==14){
steps+="7 7\n";
}
if(moved){
nsteps=20;
}
else{
nsteps=21;
steps+="1 1\n";
}
}
System.out.println(nsteps);
steps+="2 2\n3 1\n8 6\n7 7\n2 2\n1 3\n6 8\n7 7\n8 8\n6 6\n8 4\n5 1\n1 5\n4 8\n3 7\n2 8\n1 7\n7 1\n8 2";
System.out.println(steps);
}
}
}