2525
Rules: @rulesforthedevs Other @thedevs groups: https://thedevs.network
⚠️ Thomas warned Itachi Uchina [9131868747].
3/3 (🚫 banned): [C / C++] use @thehire for jobs
This warning expires on 2027-06-01
What can we do other than reduce the surface area of software we use and keep upgrading
Читать полностью…
Then the 4x loop runs twice, and the 1x loop runs twice
Читать полностью…
Try this one
typedef struct {
long long x;
long long y;
long long z;
long long _;
} Vec;
static void add(Vec *sum, Vec v) {
sum->x += v.x;
sum->y += v.y;
sum->z += v.z;
sum->_ += v._;
}
static unsigned is_zero(Vec v) { return v.x == 0 && v.y == 0 && v.z == 0; }
#include <stdio.h>
int main(void) {
Vec sum = {0, 0, 0};
unsigned long long count = 0;
scanf("%llu", &count);
Vec v[4] = {0};
while (count >= 4) {
scanf("%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld", &v[0].x, &v[0].y, &v[0].z, &v[1].x, &v[1].y, &v[1].z, &v[2].x, &v[2].y, &v[2].z, &v[3].x, &v[3].y, &v[3].z);
add(&v[0], v[1]);
add(&v[2], v[3]);
add(&sum, v[0]);
add(&sum, v[2]);
count -= 4;
}
for (unsigned long long i = 0; i < count; i++) {
scanf("%lld%lld%lld", &v[0].x, &v[0].y, &v[0].z);
add(&sum, v[0]);
}
puts(is_zero(sum) ? "YES" : "NO");
return 0;
}
Читать полностью…
scanf("%d%d%d%d", xs + 0, xs + 1, xs + 2, xs + 3);
sum += xs[0] + xs[1] + xs[2] + xs[3];
Oh right, but the difference is folded into the loop kinda
Читать полностью…
2, 3, 1, 5 could have a different result from
5, 3, 1, 2 ?
This I have to think about, probably easiest to write up a few testcases and just see if they pass with both
Читать полностью…
Sorry for necroposting, but you could remove the muliplication and division if you start with sum=n and add i - xs[i] on each iteration
Читать полностью…
And u are here discussing groundbreaking theories on this 800 elo codeforces question
Читать полностью…
You'd bd hardcoding the amount of numbers. I think we are not talking about the same problem. I'm talking about the one where you need to find the missing number.
Читать полностью…
It's the same, you just replace sum += i - num with sum^=i^num
Well I mean, if you think about perf, scanf in the loop is the most egregious perf issue
Читать полностью…
I'm very unsure how this would work, won't this make the position of each num significant?
Читать полностью…
I don't think this works, but would be interesting to be proven wrong
Читать полностью…
#include <stdio.h>Читать полностью…
int main() {
int n;
scanf("%d", &n);
int sum = n;
int num;
for (int i = 1; i < n; i++) {
scanf("%d", &num);
sum += i - num;
}
printf("%d\n", sum);
return 0;
}
⚠️ Sharuzzaman warned pk [1284169250].
3/3 (🚫 banned): [C / C++] promotion and selling
This warning expires on 2027-05-31