Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

I used to be a programmer like you

Name: Anonymous 2012-09-12 8:11

But then I got an arrow to my knee.

Name: Anonymous 2012-09-12 8:18

/prog/, the forced replyification of posts

Name: Anonymous 2012-09-12 8:19

World->Objects->Physical[1347451906]->BodyParts->Knee

Name: Anonymous 2012-09-12 8:47

>>3
What the fork?
Aren't knees the second joint of lower limbs?

Name: Anonymous 2012-09-12 11:26

Using an array of 1347451906 (*4 (pointer to BodyParts)) bytes.

Not optimizing this.
2012.

Name: Anonymous 2012-09-12 12:14

Any ideas on how I could make this program run faster?
It's supposed to run under 0.5 seconds.
In some cases it does, in others it fails.
[b]The task : [/b]

INPUT:
From the first line of the standard input read one integer (5 <= n <= 100000). Each of the following n lines will have one of the following two formats:

- 1 a - meaning that Mirko said aloud the number a, (0 <= a <= 65535).
- 2 k - meaning that Mirko asks what is the kth smallest number he has said so far. k will always be less or equal to the number of numbers Mirko has said aloud so far.

The total number of different number will not be bigger than 400, but some of the numbers can repeat!

OUTPUT:
To the standard output write one line for each of the 2 k inputs. Representing the kth smallest number at that moment.


Input:
7
1 0
1 1
1 5
2 1
2 3
1 2
2 3

Output:
0
5
2

My solution :

#include <stdio.h>
int main(){
    unsigned short int * a;
        unsigned int n,j,x,y;
    int m=-1;
    scanf("%u",&n);
    a=new unsigned short int[n];
    while (n>0){
        n=n-1;
        scanf("%u %u",&x,&y);
        if (x==1){
            m=m+1;
            j=m;
            a[j]=y;
            while((j>0)&&(a[j]<a[j-1])){
                y=a[j-1];
                a[j-1]=a[j];
                a[j]=y;
                j=j-1;
            }

        }
        else printf("%u\n",a[y-1]);
    }
    delete [] a;
    return 0;
}

Name: Anonymous 2012-09-12 12:19

>>6
using short int for boolean
not using byte for <= 256
2012.

Name: Anonymous 2012-09-12 12:20

>>6
Get a faster computer, problem solved

Name: Anonymous 2012-09-12 12:22

>>6
Mirko is a fucking faggot, tell him to get a life

Name: Anonymous 2012-09-12 13:00

>>5
>Not using meme arrows
Back to /g/ please.

Name: Anonymous 2012-09-12 14:44

>>7
yfw crappy 32-bit CISC processors are faster with 32-bit values than 8- or 16-bit ones.

Name: Anonymous 2012-09-12 15:22

>>5,7,10-11
Shitposting

Name: Anonymous 2012-09-12 17:14

>>12
Shitposting
>>5,7,10,11
Goodposting.

Name: Anonymous 2012-09-12 19:29

>>13
Back to the imageboards, ``please''.

Name: Anonymous 2012-09-12 20:16

>>14
Back to le baconwhale, ``nar''.

Don't change these.
Name: Email:
Entire Thread Thread List