epolozero Posted March 9, 2015 at 06:14 PM Report Share #579031 Posted March 9, 2015 at 06:14 PM (edited) Boas, estou a resolver um problema das olimpiadas ( http://www.dcc.fc.up.pt/oni/problemas/2014/qualificacao/probA.html ) mas esta a dar-me 88 pontos com invalid function, Resolvi o problema com o conceito de buckets (acho...). #include <stdio.h> #define MAX_VALUE 1000000 #define MAX_BUCKET 1000 //sqrt(max_value) unsigned long values[MAX_VALUE] = {0}; unsigned long bucket[MAX_VALUE]; unsigned long sum[MAX_BUCKET] = {0}; int main(void){ unsigned long n, k, i, j, l, cnt; char op[4]; scanf("%lu", &n); //buckets for (i=0, j=0; i< MAX_VALUE; i++, j = i / MAX_BUCKET){ bucket[i] = j; } while(n--){ scanf("%s", op); scanf("%lu", &k); switch(op[0]){ //inserir case 'I': values[--k]++; sum[bucket[k]]++; break; //remover case 'R': values[--k]--; sum[bucket[k]]--; break; //k-esima melhor carta case 'P': for (i=MAX_BUCKET-1, j=0; i>=0; i--){ j += sum[i]; if (j >= k){ for ( l = (i + 1) * MAX_BUCKET - 1 , cnt = j - sum[i] ; ; l--){ cnt += values[l]; if (cnt >= k){ printf("%lu\n", l+1); break; } } break; } } break; } } return 0; } Queria que alguem me dissesse o que tenho que melhorar, ou o que estou a fazer errado. Edited March 9, 2015 at 06:15 PM by epolozero Link to comment Share on other sites More sharing options...
Warrior Posted March 9, 2015 at 10:12 PM Report Share #579037 Posted March 9, 2015 at 10:12 PM Parece-me ser o //sqrt() dentro do define Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now