[ create a new paste ] login | about

Link: http://codepad.org/n8k1yG7t    [ raw code | output | fork ]

C++, pasted on Sep 27:
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>

using namespace std;

typedef unsigned uint;

typedef struct dot{
        int x;
        int y;
        uint k;
        }dot;

ifstream in("input.txt");
ofstream out("output.txt");

void check(double *k, double *b, double*c, int x1,int x2,int y1,int y2){
                  *k = (y1 - y2);
                  *b = (x2 - x1);
                  *c = x1*y2 - x2*y1;
     }

int main(){
    uint n;
    in>>n;
    vector<dot> v(n);
    for(uint i = 0; i < n; i++)
             in>>v[i].x>>v[i].y, v[i].k = 0;
   for(uint j = 0; j < n; j++)
             for(uint i = 0; i < n; i++)
                 if(i != j){
                    double k,b,c;
                    check(&k, &b, &c, v[j].x, v[i].x, v[j].y, v[i].y);
                    uint count = 2;
                    for(uint q = 0; q < n; q++){
                             if(i != q && j != q) 
                                     if(k * v[q].x + b * v[q].y + c == 0) count++;//, out<<j+1<<' '<<i+1<<' '<<q+1<<' '<<count<<' '<<k<<' '<<b<<endl;
                             }
                    if(count>v[j].k) v[j].k = count;      
                 }
   uint max = 0;
   for(uint i = 0; i < n; i++){
            if(max < v[i].k) max = v[i].k;// out<<v[i].k<<endl;
            }
   out<<max;
return 0;
}


Output:
1
2
std::bad_alloc: St9bad_alloc
Aborted.


Create a new paste based on this one


Comments: