Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS THE C++ CODE I WROTE FOR THE SAME PROBLEM - #include using namespace std; int main() { int t; cin>>t; while(t--) { int

image text in transcribed image text in transcribed image text in transcribed THIS IS THE C++ CODE I WROTE FOR THE SAME PROBLEM -

#include using namespace std;

int main() { int t; cin>>t; while(t--) { int g; cin>>g; while(g--) { int i,n,q,c=0; cin>>i>>n>>q; int ar[n]; for(int j=1;j Little Elephant was fond of inventing new games. After a lot of research, Little Elephant came to know that most of the animals in the forest were showing less interest to play the multi-player games.Little Elephant had started to invent single player games, and succeeded in inventing the new single player game named COIN FLIP In this game the player will use N coins numbered from 1 to N, and all the coins will be facing in "Same direction" (Either Head or Tail), which will be decided by the player before starting of the game. The player needs to play N rounds. In the k-th round the player will flip the face of the all coins whose number is less than or equal to k. That is, the face of coin i will be reversed, from Head to Tail, or, from Tail to Head, for i sk. Elephant needs to guess the total number of coins showing a particular face after playing N rounds. Elephant really becomes quite fond of this game COIN FLIP, SO Elephant plays G times. Please help the Elephant to find out the answer. Input The first line of input contains an integer T, denoting the number of test cases. Then I test cases follow. The first line of each test contains an integer G, denoting the number of games played by Elephant. Each of the following G lines denotes a single game, and contains 3 space separeted integers I, N, Q, where I denotes the initial state of the coins, N denotes the number of coins and rounds, and Q, which is either 1, or 2 as explained below. Here I=1 means all coins are showing Head in the start of the game, and I=2 means all coins are showing Tail in the start of the game. Q=1 means Elephant needs to guess the total number of coins showing Head in the end of the game, and Q=2 means Elephant needs to guess the total number of coins showing Tail in the end of the game. Output For each game, output one integer denoting the total number of coins showing the particular face in the end of the game. Constraints 1STS 10 13G20000 1SN 109 13132 1 *Q2 Example Input: 1 2. 1 5 1 1 5 2 Output: 2 3 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions