Here is the problems’s prompt :
MANIPULATE
computer displays the folder under multiple rows, each containing up to m folders. Assuming drive has n directories, the folders are numbered 1 through n and are ordered from left to right and from top to bottom . I wants to copy all the folders with word numbers a to b to another drive. However, i doesn’t know that i just holds down Shift then click to select folders a and b then continue to perform copy operations, how i done is hold down the Ctrl key and drag the mouse pointer to select a group of folders by frame rectangle (with sides parallel to the screen). If the folder selection is repeated (select a folder has been selected) then the folder will no longer be selected.
- Input: Single line contains n,m,a,b (1 <= n,m <= 10^9, 1 <= a,b <= n) is the number of folders on my computer, the maximum number of folders per row horizontal, the number of the first and last directory that i want to copy.
- Output: Print out the least number of mouse drag to select the frame that i must perform is displayed when you want to select all folders from a to b.
Here is my code but it got the wrong answer
#include <stdio.h>
int main(){
unsigned int n,m,a,b;
scanf("%u %u %u %u",&n,&m,&a,&b);
unsigned int positionA, positionB;
unsigned int rowA,rowB;
// Position of B and row of B
if(b % m == 0){
//b at the end of a row
positionB = m;
rowB = (b/m)-1;
}
else{
positionB = b % m;
rowB = b/m;
}
//Position of A and row of A
if(a % m == 0){
//a at the end of a row
positionA = m;
rowA = (a/m)-1;
}
else{
positionA = a % m;
rowA = a/m;
}
//Start checking
if(rowA == rowB) printf("%d",1);
else if(rowB - rowA == 1){
if(positionA == 1 && positionB == m) printf("%d",1);
else printf("%d",2);
}
else {
if(positionA == 1 && positionB == m) printf("%d",1);
else if(positionA != 1 && positionB != m) printf("%d",3);
else printf("%d",2);
}
return 0;
}