Codeforces 69A: Young Physicist The Problem: A boy is given a boy with a set of forces acting on it in x, y and z space. He needs to find out if the body is in equilibrium or not. For a body to be in equilibrium, all forces on it must be balanced ( Σ(F) == 0 ). So, we need to find out if the forces in x, y, z plane individually are 0. The Solution: The Algorithm: 1) Take n input. Declare sums of x, y, z and set them to 0. 2) Take a loop and make it run n times. 3) Take the x, y, z inputs and sum them up with their respective sum variables. 4) Check to see if all of them are zero. If true, print YES. Else print NO The Code: #include <bits/stdc++.h> #define fastio ios :: sync_with_stdio ( 0 ); cin . tie ( 0 ); cout . tie ( 0 ); using namespace std ; int main () { fastio ; int n ; cin >> n ; int x_sum , y_sum ,...
Codeforces 263A: A Beautiful Matrix What the problem wants? The problem states that a 5x5 matrix is given. It is full of 0's except one position has the number 1. We need to find the minimum moves needed to shift 1 from its current position to the center of the matrix. How to solve it? The Algorithm: 1) take a matrix and its input. 2) search for 1. If found, then find the absolute value from where it is to the center of the matrix. Do this for both i & j position. ***NOTE: The logic here is that the minimum moves made will only be through the horizontal or vertical movement. not cross movements. So we take the i at that position and subtract it to the i of the center element. Same for j. The Code: #include <bits/stdc++.h> using namespace std ; #define fastio ios :: sync_with_stdio ( 0 ); cin . tie ( 0 ); cout . tie ( 0 ); void minMoves ( int matrix [ 5 ][ 5 ]) { int i_idx = ...
Codeforces 71A: Way Too Long Words You might've heard of codeforces. If not, let me tell you that they are one of the most challenging online judges in the internet right now. Their problem sets are very unique and will pick your brain a lot. Today, I'll walk you through such a problem. Problem 71A: Way Too Long Words. What the problem wants? The problem basically tells us to take a word and if it is way too long we need to convert it to a shorter form (a guideline which they have given). The author states that any word bigger than 10 is a long word and must be shortened in the way that: the first letter will be its starting letter. The next will be the number of characters present between the starting and ending letter, and finally, the last letter will be its ending letter. Example: initialization i12n There are 12 letter between i and n. The Solution: Algorithm: 1) Take the word input 2) check if it's less than or equal to 10. 3) If yes, simple print the word. 4) Else, ...
Comments
Post a Comment