diff --git a/src/2189 - Point Location Test b/src/2189 - Point Location Test new file mode 100644 index 0000000..713e718 --- /dev/null +++ b/src/2189 - Point Location Test @@ -0,0 +1,73 @@ +/* +This is the AC code for Point Location Test on Cses +Task 2189 under Geometry +Code By Dhruv Walia +*/ + +#include +#include +#include + +using namespace std; + +typedef long long ll; +typedef vector vi; +typedef pair pi; +typedef tuple ti; +typedef vector vpi; +typedef vector vti; +typedef long long C; +typedef complex P; +#define F first +#define S second +#define PB push_back +#define mp make_pair +#define mt make_tuple +#define REP(i,a,b) for(int i=a;i,greater> q; for heap with smallest element on top +/* + bool comp(pi &a,pi &b) { + return ( (a.S > b.S) || + (!( a.S > b.S && a.F < b.F )); + } +*/ + +/* TO READ AND WRITE FROM FILES +freopen("input.txt", "r", stdin); +freopen("output.txt", "w", stdout);*/ + +long long t,n,m; +ll x[5],y[5]; + +void get_values() +{ + long long i,j,ans=0; + REP(i,1,4) + std::cin >> x[i] >> y[i]; + ll x2,y2,x1,y1,p; + x1=x[1]-x[3]; + y1=y[1]-y[3]; + x2=x[2]-x[3]; + y2=y[2]-y[3]; + p=x1*y2-x2*y1; + if(p==0) + std::cout << "TOUCH" << std::endl; + else if(p>0) + std::cout << "LEFT" << std::endl; + else std::cout << "RIGHT" << std::endl; + return; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + std::cin >> t; + while(t--) + get_values(); +} diff --git a/src/2190 - Line Segment Intersection b/src/2190 - Line Segment Intersection new file mode 100644 index 0000000..5fb1c5c --- /dev/null +++ b/src/2190 - Line Segment Intersection @@ -0,0 +1,111 @@ +/* +This is the AC code for Line Segment Intersection on Cses +Task 2190 under Geometry +Code By Dhruv Walia +*/ + +#include +#include +#include + +using namespace std; + +typedef long long ll; +typedef vector vi; +typedef pair pi; +typedef tuple ti; +typedef vector vpi; +typedef vector vti; +typedef long long C; +typedef complex P; +#define F first +#define S second +#define PB push_back +#define mp make_pair +#define mt make_tuple +#define REP(i,a,b) for(int i=a;i,greater> q; for heap with smallest element on top +/* + bool comp(pi &a,pi &b) { + return ( (a.S > b.S) || + (!( a.S > b.S && a.F < b.F )); + } +*/ + +/* TO READ AND WRITE FROM FILES +freopen("input.txt", "r", stdin); +freopen("output.txt", "w", stdout);*/ + +long long t,n,m; +vpi a; +ll x[5],y[5]; + +void get_values() +{ + long long i,j,ans=0; + REP(i,1,5) + { + std::cin >> x[i] >> y[i]; + a.PB({x[i],y[i]}); + } + if(x[1]==x[3] && y[1]==y[3]) + ans=1; + else if(x[1]==x[4] && y[1]==y[4]) + ans=1; + else if(x[2]==x[3] && y[2]==y[3]) + ans=1; + else if(x[2]==x[4] && y[2]==y[4]) + ans=1; + else + { + ll x2,y2,x1,y1,p,h,p1,h1; + x1=x[1]-x[3]; + y1=y[1]-y[3]; + x2=x[2]-x[3]; + y2=y[2]-y[3]; + p=x1*y2-x2*y1; + x1=x[1]-x[4]; + y1=y[1]-y[4]; + x2=x[2]-x[4]; + y2=y[2]-y[4]; + h=x1*y2-x2*y1; + x1=x[4]-x[1]; + y1=y[4]-y[1]; + x2=x[3]-x[1]; + y2=y[3]-y[1]; + p1=x1*y2-x2*y1; + x1=x[4]-x[2]; + y1=y[4]-y[2]; + x2=x[3]-x[2]; + y2=y[3]-y[2]; + h1=x1*y2-x2*y1; + if(((p>0 && h<0) || (p<0 && h>0)) && ((p1>0 && h1<0) || (p1<0 && h1>0))) + ans=1; + if(p==0 && (x[3]<=max(x[1],x[2]) && y[3]<=max(y[1],y[2]) && x[3]>=min(x[1],x[2]) && y[3]>=min(y[1],y[2]) )) + ans=1; + if(h==0 && (x[4]<=max(x[1],x[2]) && y[4]<=max(y[1],y[2]) && x[4]>=min(x[1],x[2]) && y[4]>=min(y[1],y[2]) )) + ans=1; + if(p1==0 && (x[1]<=max(x[3],x[4]) && y[1]<=max(y[3],y[4]) && x[1]>=min(x[3],x[4]) && y[1]>=min(y[3],y[4]) )) + ans=1; + if(h1==0 && (x[2]<=max(x[3],x[4]) && y[2]<=max(y[3],y[4]) && x[2]>=min(x[3],x[4]) && y[2]>=min(y[3],y[4]) )) + ans=1; + } + if(ans==1) + std::cout << "YES" << std::endl; + else std::cout << "NO" << std::endl; + return; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + std::cin >> t; + while(t--) + get_values(); +} diff --git a/src/2191 - Polygon Area b/src/2191 - Polygon Area new file mode 100644 index 0000000..e87bf94 --- /dev/null +++ b/src/2191 - Polygon Area @@ -0,0 +1,71 @@ +/* +This is the AC code for Polygon Area on Cses +Task 2191 under Geometry +Code By Dhruv Walia +*/ + +#include +#include +#include + +using namespace std; + +typedef long long ll; +typedef vector vi; +typedef pair pi; +typedef tuple ti; +typedef vector vpi; +typedef vector vti; +#define F first +#define S second +#define PB push_back +#define mp make_pair +#define mt make_tuple +#define REP(i,a,b) for(int i=a;i,greater> q; for heap with smallest element on top +/* + bool comp(pi &a,pi &b) { + return ( (a.S > b.S) || + (!( a.S > b.S && a.F < b.F )); + } +*/ + +/* TO READ AND WRITE FROM FILES +freopen("input.txt", "r", stdin); +freopen("output.txt", "w", stdout);*/ + +long long t,n,m; +vpi a; + +void get_values() +{ + long long i,j,ans=0,x2,y2,x1,y1; + std::cin >> n; + m=n; + while(m--) + { + cin >> i >> j; + a.PB({i,j}); + } + a.PB(a[0]); + REP(i,0,n) + { + x1=a[i].F;y1=a[i].S; + x2=a[i+1].F;y2=a[i+1].S; + ans+=(x1*y2-y1*x2); + } + std::cout << abs(ans) << std::endl; + return; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + t=1; + get_values(); + return 0; +}