The simulation, player 2 will always play according to the same strategy.
Method getPlayer2Move below is completed by assigning the correct value to result to be returned.
Explanation:
- You will write method getPlayer2Move, which returns the number of coins that player 2 will spend in a given round of the game. In the first round of the game, the parameter round has the value 1, in the second round of the game, it has the value 2, and so on.
#include <bits/stdc++.h>
using namespace std;
bool getplayer2move(int x, int y, int n)
{
int dp[n + 1];
dp[0] = false;
dp[1] = true;
for (int i = 2; i <= n; i++) {
if (i - 1 >= 0 and !dp[i - 1])
dp[i] = true;
else if (i - x >= 0 and !dp[i - x])
dp[i] = true;
else if (i - y >= 0 and !dp[i - y])
dp[i] = true;
else
dp[i] = false;
}
return dp[n];
}
int main()
{
int x = 3, y = 4, n = 5;
if (findWinner(x, y, n))
cout << 'A';
else
cout << 'B';
return 0;
}
Answer:
Here is the Python program:
d = {5:3, 4:1, 12:2}
val_of_max = d[max(d.keys())]
print(val_of_max)
Explanation:
The program works as follows:
So we have a dictionary named d which is not empty and has the following key-value pairs:
5:3
4:1
12:2
where 5 , 4 and 12 are the keys and 3, 1 and 2 are the values
As we can see that the largest key is 12. So in order to find the largest key we use max() method which returns the largest key in the dictionary and we also use keys() which returns a view object i.e. the key of dictionary. So
max(d.keys()) as a whole gives 12
Next d[max(d.keys())] returns the corresponding value of this largest key. The corresponding value is 2 so this entire statement gives 2.
val_of_max = d[max(d.keys())] Thus this complete statement gives 2 and assigns to the val_of_max variable.
Next print(val_of_max) displays 2 on the output screen.
The screenshot of program along with its output is attached.
Answer:
#include<ios>// HEADER FILe
#include<iomanip> // HEADER FILE
using namespace std;// namespace
int main() // main function
{
double tem=103.45632; // variable declaration
cout<<" The outside Temperature is:";
cout<<fixed<<setprecision(2)<<tem; // display
return 0;
}
Explanation:
<u>The following are the description of the program</u>.
- set the required header files and namespaces, then declare the main method and inside the main function.
- Set the double data type variable 'tem' and initialize the value '103.45632'.
- Finally, print the following message and print the output through the cout that is predefined function.
Answer:
Classless Inter-Domain Routing
Explanation:
Classless Inter-Domain Routing (CIDR), pronounced “cider” or “sidder,” gets its name from the notion that it ignores the traditional A, B, and C class designations for IPv4 addresses and sets the network-host ID boundary wherever it wants to, in a way that simplifies routing across the resulting IP address spaces.
Keeping the fact in mind that network access has been found to be slow and after questioning the employees, the network administrator learns that an employee downloaded a third-party application which turns out to be a scanning program for the printer.
<u>Explanation:</u>
The employee must have been unaware of the fact that the application was accompanied by a worm or a computer worm.
A computer worm is a type of malware that has a property to replicate itself and after infecting a particular computer increases its range and gets in the other computers working on the same network which is the main reason for reduced processing speed.