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 236A: Boy or Girl The Problem: A person tries to figure out how to distinct a boy and girl in an online chat platform. A boys account will have odd number of distinct characters. Here, distinct characters mean the total number of the type of characters. Ex: string: AB distinct chars: 2 (there are two types: A and B) string: ABBAACCD distinct chars: 4 (there are four types: A, B, C and D) The Solution: The Algorithm: 1) take a string 2) take a set of chars and insert each char in string into set. 3) count the number of chars in the set 4) if odd print "IGNORE HIM", else "CHAT WITH HER!". NOTE: We used set here because it does not take ANY DUPLICATE VALUES. If a value is already in the set, it will ignore it. The Code: #include <bits/stdc++.h> #define fastio ios :: sync_with_stdio ( 0 ); cin . tie ( 0 ); cout . tie ( 0 ); using namespace std ; int main () { string str ; cin ...
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 = ...
Comments
Post a Comment