Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n,both=0,prgrm=0,english=0,none=0;
cin>>n;
string s,t;
cin>>s>>t;
for(int i=0;i<n;i++)
{
if(s[i]=='1'&&t[i]=='1')
both++;
else if(s[i]=='1'&&t[i]=='0')
prgrm++;
else if(s[i]=='0'&&t[i]=='1')
english++;
else
none++;
}
// cout<<prgrm<<english<<endl;
int pair=min(prgrm,english);
int rem=max(prgrm,english)-min(prgrm,english)+none;
if(rem>=both)
{
pair+=min(rem,both);
}
else
{
pair+=((both-rem)/2)+rem;
}
cout<<pair<<endl;
}
return 0;
}
#include <stdio.h>
#include<bits/stdc++.h>
// #include <sstream>
#include <iostream>
using namespace std;
#define ld long double
#define ll long long int
// #define int long long
// #define ll int
#define EE endl
#define RR return
#define pb push_back
const int MOD = 1e9+7;
// cout<<ceil(1.0*n/x); || cout<<((n+x-1)/x);
//-----------------------------------------
//m1=0
// stringstream temp1(in1.substr(3,5));
// temp1 >> m1;
//-----------------------------------------
//to_string(23).size();
//----------------------------------------
//1000000007
//--------------------------------------
//count(s.begin(),s.end(),'0');
//--------------------------------------
//if(!is_sorted(a[i].begin(),a[i].end()))
//-------------------------------------------
//set<pair<int,int>>::reverse_iterator rit;
//for(rit = st1.rbegin(); rit!=st1.rend();rit++)
ll mod(ll x)
{
return ( ( x % MOD) + MOD ) % MOD;
}
ll mul(ll x,ll y)
{
return mod(mod(x)*mod(y));
}
ll add(ll x,ll y)
{
return mod(mod(x)+mod(y));
}
ll bexp(ll a,ll b)
{
if(a==0) return 0;
if(b==0) return 1LL;
if(b==1) return mod(a);
ll res=1;
while(b)
{
if(b%2==1) res = mul(res,a);
a = mul(a,a);
b/=2;
}
return res;
}
//----pre-compute-------------------------------
//----------------------------------------------
void solve()
{
int n;
cin>>n;
string s,t;
cin>>s>>t;
int p=0,e=0,b=0,none=0;
for(int i=0;i<n;i++)
{
if(s[i]=='1' && t[i]=='1') b++;
else if(s[i]=='1') p++;
else if(t[i]=='1') e++;
else none++;
}
int ans=0;
int temp = min(p,e);
ans+=temp;
p-=temp,e-=temp;
temp = min(b,p+e+none);
ans+=temp;
b-=temp;
ans+= b/2;
cout<<ans<<EE;
}
// signed main()
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//--pre-compute------------
//-------------------------
int t=1;
cin>>t;
for(int i=1;i<=t;i++)
{
solve();
}
// cout<<"mic_check";
return 0;
}
# cook your dish here
T=int(input())
for i in range(T):
N=int(input())
S=input()
T=input()
res=min(S.count('1'),T.count('1'),N//2)
print(res)
#include <stdio.h>
#include<stdlib.h>
typedef struct{
int a;
int b;
} node;
int main(void) {
// your code goes here
int a;
scanf("%d",&a);
while(a--)
{
int n;
scanf("%d",&n);
// printf("%d = a, %d = n\n",a,n);
node* arr= (node*)malloc(n*sizeof(node));
char*input=(char*)malloc((n+1)*sizeof(char));
scanf("%s",input);
for(int i=0;i<n;i++)
arr[i].a= input[i]-48;
scanf("%s",input);
for(int i=0;i<n;i++)
arr[i].b=input[i]-48;
int count[4]={0};
for(int i=0;i<n;i++)
{
if(arr[i].a==1)
{
if(arr[i].b==1)
count[0]++;
else
count[1]++;
// printf("%d = count[1],%d= count[0]\n",count[1],count[0]);
}
else
{
if(arr[i].b==1)
count[2]++;
else
count[3]++;
//printf("%d = count[2],%d = count[3]\n",count[2],count[3]);
}
}
int team=0;
if(count[0]>count[3])
{
team+=count[3];
count[0]-=count[3];
count[3]=0;
}
else
{
team+=count[0];
count[3]-=count[0];
count[0]=0;
}
if(count[1]<count[2])
{
team+=count[1];
count[2]-=count[1];
if(count[0]>count[2])
{
team+=count[2];
count[0]-= count[2];
}
else
{
team+=count[0];
count[0]=0;
}
}
else
{
team+=count[2];
count[1]-=count[2];
if(count[1]>count[0])
{
team+=count[0];
count[0]=0;
}
else
{
team+=count[1];
count[0]-=count[1];
}
}
if(count[0]/2>0)
team+=count[0]/2;
printf("%d\n",team);
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
{
if(sc.hasNext())
{
int t=sc.nextInt();
List<Integer> output=new ArrayList<>();
for(int i=0;i<t;i++)
{
int count1=0,count2=0;
int n=sc.nextInt();
String s=sc.next();
String x=sc.next();
if(n<=1)
{
output.add(0);
continue;
}
for(int j=0;j<n;j++)
{
if(s.charAt(j)=='1')
{
count1++;
}
}
for(int j=0;j<n;j++)
{
if(x.charAt(j)=='1')
{
count2++;
}
}
output.add(Math.min(Math.min(count1,count2),n/2));
}
/* Failed T.C)-1
1
1
1 Max team can be formed:- 0 only
Failed T.C)-1
2
1 1
1 1 Max team can be formed:- 1 only
*/
for(int i=0;i<t;i++)
{
System.out.println(output.get(i));
}
}
}
}
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
from sys import setrecursionlimit
from bisect import bisect_left
from bisect import bisect_right
from getopt import getopt
from re import sub
import re
from os import path
import random
from math import gcd
from typing import DefaultDict
import math
from collections import defaultdict
from math import sqrt
import collections
from sys import maxsize
from itertools import combinations_with_replacement
import sys
import copy
import heapq
from collections import deque
mod1 = 998244353
mod = 10**9 + 7
sys.setrecursionlimit(10**7)
vowels="aeiou"
MAX = float('inf')
MIN = float('-inf')
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if(path.exists('INPUT.txt')):
sys.stdin = open("INPUT.txt","r")
sys.stdout = open("OUTPUT.txt","w")
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#CHECK PRIME
def isprime(n):
prime_flag = 0
if(n > 1):
for i in range(2, int(sqrt(n)) + 1):
if (n % i == 0):
prime_flag = 1
break
if (prime_flag == 0):
return True
else:
return False
else:
return True
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#LCM
def lcm(a,b):
return a*b//(math.gcd(a,b))
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#SUM OF DIGITS
def countdigit(n):
ans=0
while n:
ans+=n%10
n//=10
return ans
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#RETURN NUMBER OF PRIME FACTORS
def number_of_primefactor(n):
l = []
while n % 2 == 0:
l.append(2)
n = n // 2
for i in range(3, int(math.sqrt(n))+1, 2):
while (n % i == 0):
l.append(i)
n = n // i
if n > 2:
l.append(n)
return list(set(l))
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#COUNT FACTORS
def count_factors(n):
i = 1
c = 0
ans=[]
while i <= math.sqrt(n):
if n % i == 0:
if n//i == i:
c += 1
ans.append(n//i)
else:
c += 2
ans.append(i)
ans.append(n//i)
i += 1
return ans
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#LIST TO STRING
def ListToStr(s):
str1 = ""
for ele in s:
str1 += ele
return str1
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#STRING TO LIST
def StrtoList(string):
li = list(string.split(" "))
return li
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# STRING TO LIST CHARACTER WISE
def Convert(string):
list1 = []
list1[:0] = string
return list1
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#AND OF ALL ELEMENTS OF ARRAY
def find_and(arr):
ans = arr[0]
for i in range(1, len(arr)):
ans = ans&arr[i]
return ans
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# RETURNS 2D LIST OF ELEMENTS AND ITS COUNT
def element_count(s):
# returns 2-D list of elements and its count
l = []
k = s[0]
c = 0
for ele in s:
if ele == k:
c += 1
else:
l.append([k, c])
k = ele
c = 1
l.append([k, c])
return l
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#SUBSEQUENCE
def printSubsequences(arr, index, subarr):
if index == len(arr):
if len(subarr) != 0:
print(subarr)
else:
printSubsequences(arr, index + 1, subarr)
printSubsequences(arr, index + 1,
subarr+[arr[index]])
return
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#SUBARRAYS
def subarray(arr):
sub_arr = [[]]
for i in range(len(arr) + 1):
for j in range(i + 1, len(arr) + 1):
sub = arr[i:j]
sub_arr.append(sub)
return sub_arr
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
def answer(t):
n=int(input())
s1=input()
s2=input()
#s1,s2=input().split()
#a,b=map(int,input().split())
#n,k=map(int,input().split())
#d=defaultdict(list)
#s1,s2=input().split()
#bool=True'''
#lst1=list(map(int,input().split()))
#lst2 = list(map(int,input().split()))
#l2=list(map(int,input().split()))'''
p =[]
cnt = 0
cnt1 = 0
cnt2 = 0
t1 =s1.count('1')
t2= s2.count('1')
total = min(t1,t2,n//2)
return total
for t in range(int(input())):
print(answer(t))
t = int(raw_input())
for i in range(t):
N = int(raw_input())
S = raw_input().strip()
T = raw_input().strip()
A = [0 for x in range(4)]
for k in range(N):
c = 0
if S[k] == '1':
c += 1
# endif
if T[k] == '1':
c += 2
# endif
A[c] += 1
# endfor k
r = min(A[1],A[2])
d = A[0] + abs(A[1]-A[2])
r += min(A[3],d)
if A[3] > d:
r += (A[3]-d)/2
# endif
print r
# endfor i
using System;
using System.Linq;
public class Test
{
public static void Main()
{
int test = int.Parse(Console.ReadLine());
while(test-- >0){
int n = int.Parse(Console.ReadLine());
char[] s = Console.ReadLine().ToCharArray();
char[] t = Console.ReadLine().ToCharArray();
var both =0;
var prog = 0;
var eng = 0;
for(int i=0;i<n;i++){
if(s[i]=='1' && t[i]=='1'){
both++;
}
else if(s[i]=='1' && t[i]=='0'){
prog++;
}
else if(s[i]=='0' && t[i]=='1'){
eng++;
}
}
both+=Math.Min(prog,eng);
both= Math.Min(both,n/2);
Console.WriteLine(both);
}
}
}
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');
// your code goes here
let inputString = '';
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
let t = inputString[0];
let i=1; let ii =0;
for (; ii<t; i += 3, ii++) {
const n = inputString[i];
let b=0;
let p=0;
let e=0;
for(let j=0;j<n;j++){
if(inputString[i+1][j] === '1' && inputString[i+2][j] === '1'){
b++;
} else if(inputString[i+1][j] === '1'){
p++;
} else if(inputString[i+2][j] === '1') {
e++;
}
}
const ms= Math.floor(n/2);
const team = p > e ? e : p;
const totalTeam = b + team;
if(b > ms || totalTeam > ms) {
console.log(ms);
}else {
console.log(totalTeam);
}
}
});
package main
import (
"bufio"
"bytes"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
tc := readNum(reader)
var buf bytes.Buffer
for tc > 0 {
tc--
n := readNum(reader)
S := readString(reader)
T := readString(reader)
res := solve(n, S, T)
buf.WriteString(fmt.Sprintf("%d\n", res))
}
fmt.Print(buf.String())
}
func readUint64(bytes []byte, from int, val *uint64) int {
i := from
var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp
return i
}
func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}
func readString(reader *bufio.Reader) string {
s, _ := reader.ReadString('\n')
for i := 0; i < len(s); i++ {
if s[i] == '\n' {
return s[:i]
}
}
return s
}
func readNum(reader *bufio.Reader) (a int) {
bs, _ := reader.ReadBytes('\n')
readInt(bs, 0, &a)
return
}
func readTwoNums(reader *bufio.Reader) (a int, b int) {
res := readNNums(reader, 2)
a, b = res[0], res[1]
return
}
func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
res := readNNums(reader, 3)
a, b, c = res[0], res[1], res[2]
return
}
func readNNums(reader *bufio.Reader, n int) []int {
res := make([]int, n)
x := 0
bs, _ := reader.ReadBytes('\n')
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
x = readInt(bs, x, &res[i])
}
return res
}
func solve(n int, S string, T string) int {
cnt := make([]int, 4)
for i := 0; i < n; i++ {
var x int
if S[i] == '1' {
x += 2
}
if T[i] == '1' {
x += 1
}
cnt[x]++
}
var res int
x := min(cnt[1], cnt[2])
res += x
cnt[1] -= x
cnt[2] -= x
if cnt[1] > 0 {
res += min(cnt[1], cnt[3])
cnt[3] -= min(cnt[1], cnt[3])
}
if cnt[2] > 0 {
res += min(cnt[2], cnt[3])
cnt[3] -= min(cnt[2], cnt[3])
}
if cnt[0] > 0 {
res += min(cnt[0], cnt[3])
cnt[3] -= min(cnt[0], cnt[3])
}
res += cnt[3] / 2
return res
}
func min(a, b int) int {
if a <= b {
return a
}
return b
}
In our experience, we suggest you solve this Team Formation 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 Team Formation CodeChef Solution.
I hope this Team Formation 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!