Kaleido Kronos Cheers at i-Fest!
A cosmic shoutout to all the coders who rocked the FizzBuzz-Junior contest at i-Fest! Your code, like strokes on a digital canvas, is shaping the future of tech. In the dance of Fizz and Buzz, your brilliance shines. Congrats to the victors! May the spirit of Kaleido Kronos fuel your future coding adventures!
So, we're dealing with participants applying for either Fizzbuzz or Blind C. Let's represent the set of participants for Blind C as $$$S1$$$ and for Fizzbuzz as $$$S2$$$. Now, the participants who applied for either event form a set, let's call it $$$S$$$. The question boils down to finding the number of participants who applied for both events.
In the world of sets, there's this handy formula:
$$$[ N(A \cup B) = N(A) + N(B) - N(A \cap B) ]$$$
In our scenario, $$$N(A)$$$ is the number of participants for Blind C, $$$N(B)$$$ is for Fizzbuzz, and $$$N(A \cup B)$$$ is the total participants in both events. So, our answer would be the sum of participants in $$$S1$$$ and $$$S2$$$, minus the total participants in both sets. Clear as mud?
#include <stdio.h>
int main() {
// Total participants in both events (N(A ∪ B))
int totalParticipantsBothEvents;
scanf("%d", &totalParticipantsBothEvents);
// Number of participants for Fizzbuzz (N(B))
int participantsFizzbuzz;
scanf("%d", &participantsFizzbuzz);
// Number of participants for Blind C (N(A))
int participantsBlindC;
scanf("%d", &participantsBlindC);
// Calculate the number of participants who applied for both events (N(A ∩ B))
int participantsBothEvents = participantsBlindC + participantsFizzbuzz - totalParticipantsBothEvents;
printf("%d\n", participantsBothEvents);
return 0;
}
The task is to determine the minimum rotation needed to align a plane on the runway. While it might sound complex, the question essentially asks for the minimum angle between the plane and the $$$x$$$-axis. To calculate this angle, take the modulo of the angle by $$$360^\circ$$$ since the angle repeats its value after a full circle.
Now, adjust the angle accordingly to quadrants, Refer to the code below for detailed explaination.
That's the key to finding the answer. Easy, right?
#include <stdio.h>
int main() {
int angle;
scanf("%d", &angle);
// Take modulo to handle angle repetition after 360°
angle %= 360;
// Adjust the angle based on the quadrant
int minimumRotation;
if (angle >= 0 && angle < 90) {
minimumRotation = angle;
} else if (angle >= 90 && angle < 180) {
minimumRotation = 180 - angle;
} else if (angle >= 180 && angle < 270) {
minimumRotation = angle - 180;
} else {
minimumRotation = 360 - angle;
}
printf("%d\n", minimumRotation);
return 0;
}
The objective is to determine whether Meet will win or lose a game based on solving problems. For each problem Meet solves (indexed as $$$i$$$), he earns $$$a[i]^n$$$ points. The total points are the sum of all $$$n$$$ question points. If the total points are even, Meet wins; otherwise, he loses.
Here's a key observation: if a number is even, any power (>0) of that number is also even. Conversely, if a number is odd, any power (>0) of that number is odd. Therefore, the goal is to count the number of even and odd numbers in the array.
If odd numbers occur an even number of times, Meet wins (since adding even to even or odd to odd results in an even number). If odd numbers occur an odd number of times, Meet loses. The answer is "YES" if Meet wins and "NO" if he loses.
#include <stdio.h>
int main() {
int n; // size of the array
scanf("%d", &n);
int array[n];
for (int i = 0; i < n; i++) {
scanf("%d", &array[i]);
}
int evenCount = 0;
int oddCount = 0;
for (int i = 0; i < n; i++) {
if (array[i] % 2 == 0) {
evenCount++;
} else {
oddCount++;
}
}
if (oddCount % 2 == 0) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}
Consider the binary representation of a number $$$x$$$, where $$$x_i$$$ represents the bit at the $i$th position from the right.
There are two cases for each $$$x_i$$$: 1. If $$$x_i = 0$$$, then both $$$a_i$$$ and $$$b_i$$$ must be 0. 2. If $$$x_i = 1$$$, we have two choices: — Set $$$a_i = 1, b_i = 0$$$ (for maximum $$$a$$$ and minimum $$$b$$$). — For the minimum value of $$$i$$$, set $$$a_i = 0, b_i = 1$$$ to ensure $$$b$$$ is not zero at the end.
For example, with $$$x = 1001$$$: - For $$$i = 1$$$, set $$$a_1 = 0, b_1 = 1$$$. - For $$$i = 4$$$, set $$$a_4 = 1, b_4 = 0$$$. - For all other $$$i$$$, set $$$a_i = 0, b_i = 0$$$. This results in $$$a = 1000$$$ and $$$b = 0001$$$, equivalent to decimal 8 and 1, respectively.
This approach ensures the maximum value for $$$a$$$ and the minimum value for $$$b$$$ using bitwise operations. Handle the special case of $$$x_i = 1$$$ at the minimum position carefully to avoid $$$b$$$ being zero at the end.
#include <stdio.h>
int main() {
int x;
scanf("%d", &x);
int v[32];
for (int i = 0; i < 32; i++) {
v[i] = (x >> i) & 1;
}
int a = 0, b = 0;
int flag = 0;
for (int i = 0; i < 32; i++) {
if (v[i] == 1) {
if (!flag) {
b = 1 << i;
flag = 1;
} else {
a += 1 << i;
}
}
}
if (a == 0 || b == 0) {
printf("-1\n");
} else {
printf("%d %d\n", a, b);
}
return 0;
}
Solution
#include <stdio.h>
#include <limits.h>
int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int max(int a, int b){
if(a>b){
return a;
}
else{
return b;
}
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int pre[n + 1];
int suf[n + 1];
for(int i=0; i<=n; i++){
pre[i]=0;
suf[i]=0;
}
for (int i = 1; i < n + 1; i++) {
pre[i] = gcd(pre[i - 1], arr[i - 1]);
}
for (int i = n - 1; i >= 0; i--) {
suf[i] = gcd(suf[i + 1], arr[i]);
}
int ans = INT_MAX;
for (int i = 1; i < n; i++) {
if (pre[i] == suf[i]) {
ans = (ans < (max(i, n - (i + 1)))) ? ans : (max(i, n - (i + 1)));
}
}
if (ans == INT_MAX) {
printf("-1\n");
return 0;
}
printf("%d\n", ans + 1);
return 0;
}