Problem
You have taken your kids to a amusement center in VR Mall.
One of the games in the amusement center is Bop the Munchkin.
The game is arranged in 6x6 square with 36 evenly spaced cells.
Cell (0,0) is the bottom left, cell (1, 0) is the one above and cell (0, 1) is the one to the right of the starting cell.
There are muchkins that pop out of the hole in each cell.
Munchkins pop out once every 2 seconds and stay on for the entire 2 second duration.
A mace can be used to bop a munchkin that is popping out of the hole
If a mace can move over the cell before 2 seconds are up, then it can hit the munckin.
This action is instantaneous and does not consume time.
You have three different maces to pick from. Each mace has a weight and speed.
* Mace M1 has a weight 100gms and moves at 1 cell per game second.
* Mace M2 has a weight of 75 gms and can move at a speed of 2 cells per game second.
* Mace M3 has a weight of 50 gms and can move at a speed of 3 cells per game second.
There are different types of munchkins. Munchkins of type P1 can only be destroyed by a hit with mace M1. Type P2 can only be destroyed by M2 and P3 by M3.
The maces can move horizontally or vertically. They will always move towards the munchkin that has popped up, in the direction where there is greatest distance to cover.
In the event that the distance is the same in both horizontal and vertical directions, the horizontal distance is covered first
Move the required number of cells to reach the aligned row/column and then move perpendicular to reach the required cell.
For example if you are in cell 0,0 (start of the game) and are using mace M1 and the first munchkin appears in cell (3, 2) then the mace move two cells up to (2,0) by the end of two second period and this becomes the starting point for the next 2 second cycle
Given a set of munchkins, the sequence and cells where they appear, and the choice of mace, your job is to compute how many munchkins will be bopped on the head.
Input
The first line has a single number N which is the number of munchkins that will pop out
It will be followed by N lines in the form "MunchkinType Cell"
The final line will have the type of mace to use
Eg:
6 [ N - number of munchkins that appear ]
P2 4 4 [ munchkin of type P2 will appear at cell (4, 4) at second 0 ]
P2 2 5 [ munchkin of type P2 will appear at cell (2, 5) at second 2 ]
P2 5 4
P1 5 3 [ munchkin of type P1 will appear at cell (5, 3) at second 6 ]
P3 1 0
P2 3 3
M2 [ mace of type M2 has to be used ]
Output
2 [ number of munchkins that were bopped ]
Explanation:
You start at (0, 0)
Munchkin is at (4, 4). In 2 seconds you can move to (4, 0)
Munchkin is at (2, 5). Mace moves to (4, 4) to cover the greater vertical distance first
Munchkin is at (5, 4). Mace moves to (5, 4). 1 munchkin bopped
Munchkin is at (5, 3). Mace moves to (5, 3). Cannot bop munchkin of type P1
Munchkin is at (1, 0). Mace moves to (1, 3).
Munchkin is at (3, 3). Mace moves to (3, 3). 2 munchkins bopped
What I have tried:
I COULDN'T EVEN UNDERSTAND THE PROBLEM.
[on behalf of the OP]
#include <bits/stdc++.h>
using namespace std;
int sd,nowx,nowy;
int cnt;
int dx,dy,x,y;
int up_bd;
void jao(int indx[][3],int in,int chk)
{
if((abs(dx-x))<abs(dy-y))
{
int temp = min(abs(dy-y),up_bd);
if(dy>y)y+=temp;
else y-=temp;
up_bd-=temp;
temp = min(abs(dx-x),up_bd);
if(dx>x)x+=temp;
else x-=temp;
up_bd-=temp;
}
else
{
int temp = min(abs(dx-x),up_bd);
if(dx>x)x+=temp;
else x-=temp;
up_bd-=temp;
temp = abs(dy-y);
temp = min(temp,up_bd);
if(dy>y)y+=temp;
else y-=temp;
up_bd-=temp;
}
if(x==indx[in][0]&&y==indx[in][1] && chk==indx[in][2])cnt++;
nowx=x,nowy=y;
}
int main()
{
int n;
cin>>n;
string s;
int indx[n][3];
for(int i=0;i<n;i++)
{
cin>>s;
cin>>indx[i][0]>>indx[i][1];
if(s[1]=='1')indx[i][2]=1;
else if (s[1]=='2')indx[i][2]=2;
else indx[i][2]=3;
}
cin>>s;
if(s[1]=='1')sd=1;
else if(s[1]=='2')sd=2;
else sd=3;
for(int i=0;i<n;i++)
{
up_bd = sd*2;
x=nowx;
y=nowy;
dx = indx[i][0];
dy=indx[i][1];
jao(indx,i,sd);
}
cout<<cnt<<endl;
return 0;
}
[/on behalf of the OP]