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 )$$$:
If $$$( x_i = 0 )$$$, then both $$$( a_i )$$$ and $$$( b_i )$$$ must be $$$0$$$.
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.
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 a = 0, b = 0;
int flag = 0;
for (int i = 0; i < 32; i++) {
if ((x & (1 << i)) == 0) {
// Case: xi = 0
a |= (0 << i);
b |= (0 << i);
} else {
// Case: xi = 1
if (!flag) {
// For the minimum value of i, set ai = 0, bi = 1
b |= (1 << i);
flag = 1;
} else {
// Set ai = 1, bi = 0 for maximum a and minimum b
a |= (1 << i);
b |= (0 << i);
}
}
}
if (a == 0 || b == 0) {
printf("-1\n");
} else {
printf("%d %d\n", a, b);
}
return 0;
}
To determine the minimum time required, we explore all possible array partitions, with $$$n-1$$$ options for partitioning an array of size $$$n$$$ into two subarrays. For each partition, we compute the greatest common divisor $$$gcd$$$ of the elements.
Efficient gcd calculation for all partitions is achieved by leveraging the fact that $$$\text{gcd}(x_1, x_2, .., x_i)$$$ = $$$\text{gcd}(x_i, \text{gcd}(x_1, x_2, .., x_{i-1}))$$$. We maintain two arrays: $$$\text{pref}(i)$$$ representing the gcd of $$$(x_1, x_2, .., x_i)$$$, and $$$\text{suff}(i)$$$ representing the gcd of $$$(x_{i+1}, x_{i+2}, .., x_n)$$$.
By comparing $$$\text{pref}(i)$$$ and $$$\text{suff}(i)$$$ for $$$i$$$ from $$$1$$$ to $$$n$$$, we can identify the minimum time required for a valid partition. If no such partition exists, we return $$$-1$$$.
#include <stdio.h>
// Recursive function to calculate gcd
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
// Function to find the maximum of two numbers
int max(int a, int b) {
return (a > b) ? a : b;
}
// Function to find the minimum of two numbers
int min(int a, int b) {
return (a < b) ? a : b;
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int pre = 0, suf = 0;
int pref[n + 1];
int suff[n + 1];
pref[0] = 0;
suff[n] = 0;
for (int i = 1; i < n + 1; i++) {
pref[i] = gcd(pref[i - 1], arr[i - 1]);
}
for (int i = n - 1; i >= 0; i--) {
suff[i] = gcd(suff[i + 1], arr[i]);
}
int ans = n + 1;
for (int i = 1; i < n; i++) {
if (pref[i - 1] == suff[i]) {
ans = min(ans, max(i, n - i));
}
}
if (ans == n + 1) {
printf("-1\n");
return 0;
}
printf("%d\n", ans);
return 0;
}
Auto comment: topic has been updated by H_a_r_M_i_t (previous revision, new revision, compare).