Dual Nim CodeChef Solution

Problem -Dual Nim CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Dual Nim CodeChef Solution in C++14

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;

#define all(v)       v.begin(),v.end()
#define sz(x)        (int)(x).size()
#define alr(v)       v.rbegin(),v.rend()
#define pb           push_back
#define S            second
#define F            first
#define pow2(x)      (1<<(x))
#define sp(x)        cout<<fixed<<setprecision(6)<<x
#define output(x)    cout<<(x?"YES\n":"NO\n")
#define bp(x)        __builtin_popcount(x)
//#define int long long
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; (x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
// void __print(const T &x) {int f = 0; cerr << '{'; __printfor (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N=1e6+1;
const char nl='\n';
const ll mod=1e9+7;
const ll Binf=1e18;
const ll mod1=998244353;


void solve101(){
    int n;cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        ans^=x;
    }
    if(ans==0 || n%2==0){
        cout<<"First\n";
    }
    else{
        cout<<"Second\n";
    }
}
signed main() {

    ios::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
    
    int t=1;
    cin>>t; 
    for(int i=1;i<=t;i++){
        // cout<<"Case #"<<i<<": ";
        solve101();  
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}
// always check for binary search >.<

// #ifndef ONLINE_JUDGE
//     if (fopen("input.txt", "r"))
//     {
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
//     }
// #endif

Dual Nim CodeChef Solution in PYTH 3

# cook your dish here
# cook your dish here
for _ in range(int(input())):
    n=int(input())
    a=[int(x) for x in input().split()]
    t=0
    for i in range(n):
        t=t^a[i]
    if t==0:
        print("First")
    elif n%2==0:
        print("First")
    else:
        print("Second")

Dual Nim CodeChef Solution in C

#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,x,xor=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            xor^=x;
        }
        if(xor!=0 &&n%2==1)
            printf("Second\n");
        else
            printf("First\n");
    }
    return 0;
}

Dual Nim CodeChef Solution in JAVA

import java.util.*;
import java .io.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        Scanner in=new Scanner(System.in);
           int t=in.nextInt();
           while(t-->0){
           int n=in.nextInt();
           int[] a=new int[n];
           for(int i=0;i<n;i++)
           {
            
               a[i]=in.nextInt();
           }
          int ans=0;
           
            for(int i=0;i<n;i++)
           {
               ans^=a[i];
           }
           boolean a6=true;
           if(ans!=0)
           {
               if(n%2==1)
               {
                   a6=false;
                   
                   
                   
               }
           }
       
            System.out.println(a6?"First":"Second");  
           }
        }
       
}

Dual Nim CodeChef Solution in PYPY 3

for t in range(int(input())):
    n = int(input())
    nums = [int(x) for x in input().split()]
    ans = 0
    for num in nums:
        ans = ans ^ num
    if ans == 0:
        print("First")
    else:
        if n % 2 == 0:
            print("First")
        else:
            print("Second")

Dual Nim CodeChef Solution in PYTH

n_tests = input()
for tc in xrange(n_tests):
	n_piles = input()
	nums = map(int, raw_input().strip().split(' '))
	
	xorval = 0
	for num in nums:
		xorval ^= num
 
	if xorval == 0:
		print 'First'
	else:
		if n_piles % 2 == 0:
			print 'First'
		else:
			print 'Second' 

Dual Nim CodeChef Solution in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = Convert.ToInt32(Console.ReadLine());
            while(t>0)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                string[] inp;
                inp = Console.ReadLine().Split();
                int ans = 0;
                for(int i=0;i<n;i++)
                {
                    ans ^= Convert.ToInt32(inp[i]);
                }
                if (ans == 0)
                    Console.WriteLine("First");
                else
                {
                    if (n % 2 == 0)
                        Console.WriteLine("First");
                    else
                        Console.WriteLine("Second");
                }
                t--;
            }
            Console.Read();
        }
    }
}

Dual Nim CodeChef Solution in GO

package main

import "fmt"

func main() {
	var t int
	var n int
	var x int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &n)
		val := 0
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &x)
			val = x ^ val
		}
		if val == 0 {
			fmt.Println("First")
			continue
		}
		ans := "First"
		if n%2 != 0 {
			ans = "Second"
		}
		fmt.Println(ans)
	}
}
Dual Nim CodeChef Solution Review:

In our experience, we suggest you solve this Dual Nim CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Dual Nim CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Dual Nim CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *