ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1028. Stars

What's wrong with my code??? Who can help me!!!
Posted by Steve Francis 22 Jul 2003 20:45
#include <iostream.h>
#define limit 15000
int a[limit]={0};
int record[32001]={0};
int work(int x){
    long l,r,mid;
        int tot=0;
    l=1; r=32000;
    while (l<=r){
        mid=(l+r)/2;
        if (x<=mid) record[mid]++;
        if (x>=mid) tot+=record[mid];
        if (x==mid) break;
        if (x<mid) r=mid-1;
        else l=mid+1;
    }
    return tot-1;
}
int main(){
    int i,n,x,y;
    cin>>n;
        for (i=1; i<=n; i++){
        cin>>x>>y;
        a[work(x)]++;
    }
    for (i=0; i<n; i++)
        cout<<a[i]<<endl;
    return 0;
}
Re: What's wrong with my code??? Who can help me!!!
Posted by GodZilla 23 Jul 2003 02:46
Sort the coordinates and use hash-table to keep it.


If you do not understand, I can to explain how you


can find star you need


Sorry for my English !!!
Re: What's wrong with my code??? Who can help me!!!
Posted by Steve Francis 23 Jul 2003 06:20
The Problem said
"Stars are listed in ascending order of Y coordinate. Stars with
equal Y coordinates are listed in ascending order of X coordinate."
so I have no need to sort the stars, I can be working while reading.
I only use array to simulate a BinTree.
Re: What's wrong with my code??? Who can help me!!!
Posted by Steve Francis 23 Jul 2003 06:28
Sorry!My code is AC now!