-
Notifications
You must be signed in to change notification settings - Fork 0
/
single operation part 2 october long challanges
110 lines (92 loc) · 2.89 KB
/
single operation part 2 october long challanges
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Problem
Chef has the binary representation SS of a number XX with him. He can modify the number by applying the following operation exactly once:
Make X := X \oplus \lfloor \frac{X}{2^{Y}} \rfloorX:=X⊕⌊
2
Y
X
⌋, where (1 \leq Y \leq |S|)(1≤Y≤∣S∣) and \oplus⊕ denotes the bitwise XOR operation.
Chef wants to minimize the value of XX after performing the operation. Help Chef in determining the value of YY which will minimize the value of XX after the operation.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
Each test case consists of two lines of inputs:
The first line contains the length of the binary string SS.
The second line contains the binary string SS.
Output Format
For each test case, output on a new line, the value of YY which will minimize the value of XX after the operation.
Constraints
1 \leq T \leq 5 \cdot 10^41≤T≤5⋅10
4
1 \leq |S| \leq 10^51≤∣S∣≤10
5
The sum of |S|∣S∣ over all test cases won't exceed 5 \cdot 10^55⋅10
5
.
SS contains the characters 00 and 11 only.
Sample 1:
Input
Output
4
2
10
2
11
3
101
3
110
2
1
2
1
Explanation:
Test case 11: Since S = 10S=10 is the binary representation of 22, the current value of X = 2X=2. On choosing Y = 2Y=2, XX becomes 2 \oplus \lfloor \frac{2}{2^{2}} \rfloor = 22⊕⌊
2
2
2
⌋=2. We can show that this is the minimum value of XX we can achieve after one operation.
Test case 22: Since S = 11S=11 is the binary representation of 33, the current value of X = 3X=3. On choosing Y = 1Y=1, XX becomes 3 \oplus \lfloor \frac{3}{2^{1}} \rfloor = 23⊕⌊
2
1
3
⌋=2. We can show that this is the minimum value of XX we can achieve after one operation.
Test case 33: Since S = 101S=101 is the binary representation of 55, the current value of X = 5X=5. On choosing Y = 2Y=2, XX becomes 5 \oplus \lfloor \frac{5}{2^{2}} \rfloor = 45⊕⌊
2
2
5
⌋=4. We can show that this is the minimum value of XX we can achieve after one operation.
Test case 44: Since S = 110S=110 is the binary representation of 66, the current value of X = 6X=6. On choosing Y = 1Y=1, XX becomes 6 \oplus \lfloor \frac{6}{2^{1}} \rfloor = 56⊕⌊
2
1
6
⌋=5. We can show that this is the minimum value of XX we can achieve after one operation.
soultion:
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class codechef
{
public static void main(String[] args) throws java.lang.Exception{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
String s=sc.next();
int count=1;
for(int i=1;i<n;i++){
if(s.charAt(i)=='1'){
break;
}
else{
count++;
}
}
System.out.println(count);
}
}
}