diff --git a/10.4 b/10.4 new file mode 100755 index 0000000..5819f5f Binary files /dev/null and b/10.4 differ diff --git a/10.4.cpp b/10.4.cpp new file mode 100644 index 0000000..1d2ed8b --- /dev/null +++ b/10.4.cpp @@ -0,0 +1,57 @@ +#include +using namespace std; + +const int INF = ~(1<<31); + +void swap(int &a, int &b){ + a = a^b; + b = a^b; + a = a^b; +} +int flipsign(int a){ + int d = a < 0 ? 1 : -1; + int opa = 0; + while(a != 0){ + a += d; + opa += d; + } + return opa; +} +int abs(int a){ + if(a < 0) a = flipsign(a); + return a; +} +bool opsign(int a, int b){ + return (a>0 && b<0) || (a<0 && b>0); +} +int times(int a, int b){ + int aa = abs(a), bb = abs(b); + int res = 0; + if(aa < bb) swap(aa, bb); + for(int i=0; i=0; ++res); + if(opsign(a, b)) res = flipsign(res); + return res; +} +int main(){ + int a[] = { + 8, 0, -8, -5, 9 + }; + int b[] = { + 3, 5, 3, 0, -3 + }; + for(int i=0; i<5; ++i){ + cout< +#include +#include +#include +#include +using namespace std; + +struct point{ + double x, y; +}; +class line{ +public: + double epsilon, slope, intercept; + bool bslope; +public: + line(){} + line(point p, point q){ + epsilon = 0.0001; + if(abs(p.x - q.x) > epsilon){ + slope = (p.y-q.y) / (p.x-q.x); + intercept = p.y - slope * p.x; + bslope = true; + } + else{ + bslope = false; + intercept = p.x; + } + } + void print(){ + cout<<"y = "< line_count; + for(int i=0; i line_count[bestline]) + bestline = l; + } + } + } + cout<