Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 454 kb Hello world program!!
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
md




PostPosted: Fri Dec 29, 2006 2:24 pm   Post subject: (No subject)

I would like to point out that my filesizes are perhaps a little inflated; debug info was compiled in and there were no optimization at all.

I get 138K (for all) without debug, and 124K (for all) with -O3; I get 88K with -Os however. All in all I'd say that's pretty good.
Sponsor
Sponsor
Sponsor
sponsor
haskell




PostPosted: Fri Dec 29, 2006 3:05 pm   Post subject: (No subject)

I wasn't asking for help lol. Its a HelloWorld lol...

Anyways, OpenWatcom gets rid of the problem(~50kb without optimization).

Plus it has(IMO) better optimization options.

And yeah, it is the STL(iostream) that caused the huge .exe for it. But with OpenWatcom, it isn't an issue(although it shockingly said that I had included 1770~ lines with iostream). Which makes sense to the size of the included lines.

To solve the problem with GCC, in short, use OpenWatcom(Its open-source(still) and IMO, better than GCC(though I don't think its on unix-based systems yet...).
bugzpodder




PostPosted: Fri Dec 29, 2006 4:26 pm   Post subject: (No subject)

me?

code:

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;

typedef long double ld;
typedef pair<ld,ld> pt;
typedef vector<pt> poly;

ld memo[128][128][128];
poly p;

void out(pt p) {
        cout<<"("<<p.first<<","<<p.second<<")";
}

void out(poly p) {
        for (int i=0;i<p.size();i++) out(p[i]);
}

ld d(pt p1, pt p2, pt p3) {
        if (fabs(p1.first-p2.first)<1e-10) return 1e10;
        return (p3.first-p2.first)*(p1.second-p2.second)/(p1.first-p2.first)+p2.second-p3.second;
}

int orient(pt p1, pt p2, pt p3) {
        ld x=(p2.first-p1.first)*(p3.second-p1.second)-(p3.first-p1.first)*(p2.second-p1.second);
        if (fabs(x)<1e-10) return 0;
        else if (x<0) return -1; else return 1;
       
}

ld convex() {
        sort (p.begin(),p.end());
        ld ans = 0;
        vector<int> c;
        c.push_back(0);
        c.push_back(1);
        for (int i=2;i<p.size();i++)
        {
                while (c.size()>=2 && orient(p[c[c.size()-2]],p[c.back()],p[i])>0)
                        c.pop_back();
                c.push_back(i);
        }
        //cout<<"convex hull has "<<c.size()<<endl;
        for (int i=0;i<c.size()-1;i++)
        for (int j=c[i];j<c[i+1];j++) {
                ld s = d(p[c[i]],p[c[i+1]],p[j]);
                p[j].second += s;
                ans=max(ans,s);
        }

        return ans;
       
}

ld doit(int lo, int hi, int n) {
        if (n<=0 || n>=hi-lo) return 1e15;
        if (n*2 >= hi-lo) return 0;
        ld &r = memo[lo][hi][n];
        if (r>=0) return r;
        r=1e15;
        if (n==1) {
                if (p[hi-2].first == p[hi-1].first) return 0;
                for (int k=lo;k<hi-1;k++)
                {
                        ld ans = -1;
                        for (int i=lo;i<hi;i++)
                                ans = max(ans, d(p[k],p[k+1],p[i]));
                        r = min(r,ans);
                }
        }
        else {
                r = 1e15;
                for (int k=lo+2;k<hi-1;k++)
                r = min(r,max(doit(k,hi,n-1),doit(lo,k,1)));
        }
        return r;
}

int main() {
        int n,k;
        while(cin>>n>>k && n && k) {
                p.resize(n);
                for (int i=0;i<n;i++) cin>>p[i].first>>p[i].second;
                for (int i=0;i<=n;i++) for (int j=0;j<=n;j++) for (int kk=0;kk<=k;kk++) memo[i][j][kk]=-1;
                ld t = convex();
                //out(p); cout<<" "<<t<<endl;
                cout<<t<<" "<<setiosflags(ios::fixed)<<setprecision(3)<<t+doit(0,n,k)<<endl;
        }
        return 0;
}
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 18 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: