Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

K6A editorial

$
0
0

PROBLEM LINK:

Practice
Contest

Author:Chandan Boruah
Tester:Chandan Boruah
Editorialist:Chandan Boruah

DIFFICULTY:

EASY

PREREQUISITES:

Basic Maths

PROBLEM:

Given an array where elements can take only 2 values with some elements fixed, what is the number of ways in which the array can exist.

QUICK EXPLANATION:

Print 2^(number of elements not fixed). If all elements are fixed, which is a special case, print 1.

EXPLANATION:

The number of ways in which the elements can exist equals to 2^(number of elements that aren't fixed), since there are only 2 possible values of each element. The problem was intended to confuse with bitmasks and also has a special case.

AUTHOR'S SOLUTION

using System;
class some
{
    public static void Main()
    {
        int t=int.Parse(Console.ReadLine());
        for(int l=0;l<t;l++)
        {
            int c=int.Parse(Console.ReadLine());
            string[]ss=Console.ReadLine().Split();
            int cc=0;
            foreach(string kk in ss)if(kk=="*")cc++;
            if(cc==0)Console.WriteLine(1);
            else
            Console.WriteLine(Math.Pow(2,cc));
        }
    }
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>