thedevs_c | Неотсортированное

Telegram-канал thedevs_c - C / C++

2525

Rules: @rulesforthedevs Other @thedevs groups: https://thedevs.network

Подписаться на канал

C / C++

Why are you calling it elo when it's CF?

Читать полностью…

C / C++

⚠️ ‎Thomas warned ‎Itachi Uchina [9131868747].
3/3 (🚫 banned): ‎[C / C++] use @thehire for jobs
This warning expires on 2027-06-01

Читать полностью…

C / C++

What can we do other than reduce the surface area of software we use and keep upgrading

Читать полностью…

C / C++

We have CVEs coming out

Читать полностью…

C / C++

Then the 4x loop runs twice, and the 1x loop runs twice

Читать полностью…

C / C++

But it does run faster

Читать полностью…

C / C++

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;
}

Читать полностью…

C / C++

scanf("%d%d%d%d", xs + 0, xs + 1, xs + 2, xs + 3);
sum += xs[0] + xs[1] + xs[2] + xs[3];

Читать полностью…

C / C++

You just amortize it

Читать полностью…

C / C++

sum += xs[i] is also very easy to vectorize

Читать полностью…

C / C++

Oh right, but the difference is folded into the loop kinda

Читать полностью…

C / C++

2, 3, 1, 5 could have a different result from
5, 3, 1, 2 ?

Читать полностью…

C / C++

This I have to think about, probably easiest to write up a few testcases and just see if they pass with both

Читать полностью…

C / C++

Or you could xor everything

Читать полностью…

C / C++

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

Читать полностью…

C / C++

the right hand is still a hand for a reason

Читать полностью…

C / C++

Back to paper and pen 😊

Читать полностью…

C / C++

And u are here discussing groundbreaking theories on this 800 elo codeforces question

Читать полностью…

C / C++

1x loop at the end runs 0-3 times

Читать полностью…

C / C++

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.

Читать полностью…

C / C++

The code is way more ugly and complex

Читать полностью…

C / C++

I wrote a "wide" version of this

Читать полностью…

C / C++

It's the same, you just replace sum += i - num with sum^=i^num

Читать полностью…

C / C++

Maybe, but in this case you cannot avoid it

Читать полностью…

C / C++

Well I mean, if you think about perf, scanf in the loop is the most egregious perf issue

Читать полностью…

C / C++

No, the i is just to sum from 1 to n

Читать полностью…

C / C++

I'm very unsure how this would work, won't this make the position of each num significant?

Читать полностью…

C / C++

I don't think this works, but would be interesting to be proven wrong

Читать полностью…

C / C++

#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;
}

Читать полностью…

C / C++

⚠️ ‎Sharuzzaman warned ‎pk [1284169250].
3/3 (🚫 banned): ‎[C / C++] promotion and selling
This warning expires on 2027-05-31

Читать полностью…
Подписаться на канал