Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ code for calculation of a physics experiment
Suppose, we are performing a physics experiment. We are given n pairs of values and a threshold value k. Each the first value of the pair is added to a total value and the second value of the pair is also added to another total value. Now, we check if a total value is minimum or the (k - total) value is minimum. We do this for both the totals and then add them and print the output.
So, if the input is like n = 4, k = 20, values = {{3, 5}, {4, 3}, {2, 1}, {4, 4}}, then the output will be 14.
Steps
To solve this, we will follow these steps −
a := 0, b = 0 for initialize i := 0, when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; #define N 100 void solve(int n, int k, vector > values) { int a = 0, b = 0; for(int i = 0; i > values = {{3, 5}, {4, 3}, {2, 1}, {4, 4}}; solve(n, k, values); return 0; } Input
4, 20, {{3, 5}, {4, 3}, {2, 1}, {4, 4}}Output
14
Advertisements
