Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // #include <iostream>
- // #include <cstdio>
- // #include <cstdlib>
- // #include <algorithm>
- // #include <cmath>
- // #include <vector>
- // #include <set>
- // #include <map>
- // #include <queue>
- // #include <stack>
- // #include <ctime>
- // #include <cassert>
- // #include <complex>
- // #include <string>
- // #include <cstring>
- // #include <bitset>
- using namespace std;
- // #pragma GCC optimize("Ofast,no-stack-protector")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- // #pragma GCC optimize("unroll-loops")
- #define ll long long int
- #define vi vector< int >
- #define vll vector< ll >
- #define sc scanf
- #define pf printf
- #define cspf(i) pf("Case %d: ", i)
- #define spc pf(" ")
- #define line pf("\n")
- #define ff first
- #define ss second
- #define mp make_pair
- #define pb push_back
- #define ppb pop_back
- #define tp(v,j) get<j>(v)
- #define Log(b,x) (log(x)/log(b))
- #define FOR(i,x,y) for(int i = int(x); i < int(y); i++)
- #define ROF(i,x,y) for(int i = int(x)-1; i >= int(y); i--)
- #define clr(arr,x) memset(arr, x, sizeof arr)
- #define vout(v,sz) for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define unq(v) sort(all(v)),(v).resize(unique(all(v))-v.begin())
- #define fastIO ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
- #define sc1(x) sc("%d",&x);
- #define sc2(x,y) sc("%d %d", &x, &y)
- #define sc3(x,y,z) sc("%d %d %d", &x, &y, &z)
- #define scl1(x) sc("%lld",&x);
- #define scl2(x,y) sc("%lld %lld", &x, &y)
- #define scf1(x) sc("%lf",&x);
- #define scf2(x,y) sc("%lf %lf", &x, &y)
- #define pf1(x) pf("%d",x);
- #define pf2(x,y) pf("%d %d", x, y)
- #define pfl1(x) pf("%lld",x);
- #define pfl2(x,y) pf("%lld %lld", x, y)
- #define MOD (int)(998244353)
- #define MaxN 100000
- #define inf 0x3f3f3f3f
- #define PI acos(-1.0) // 3.1415926535897932
- #define eps 1e-9
- #ifdef ERFANUL007
- #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
- template < typename Arg1 >
- void __f(const char* name, Arg1&& arg1){
- cout << name << " = " << arg1 << std::endl;
- }
- template < typename Arg1, typename... Args>
- void __f(const char* names, Arg1&& arg1, Args&&... args){
- const char* comma = strchr(names, ',');
- cout.write(names, comma - names) << " = " << arg1 <<" | ";
- __f(comma+1, args...);
- }
- #else
- #define debug(...)
- #endif
- template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
- template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
- template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
- template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
- int dx[] = { 1,-1, 0, 0}; //graph moves
- int dy[] = { 0, 0, 1,-1}; //graph moves
- struct PT{
- double x, y;
- void scan(){ scanf("%lf %lf",&x,&y);}
- };
- double SQ(double x){ return x*x;}
- double Dis(PT a,PT b){ return SQ(a.x - b.x) + SQ(a.y - b.y);}
- double absDis(PT a,PT b){ return sqrt(Dis(a,b));}
- /*two vector lines Dot product*/
- int Dot(PT a,PT b){ return a.x*b.x + a.y*b.y;}
- /*two vector lines Cross product*/
- int Cross(PT a,PT b){ return a.x*b.y - b.x*a.y;}
- /*convert degree to radian*/
- double toRadian(double x){ return (x*(PI/180.0));}
- /*convert radian to degree*/
- double toDegree(double x){ return (x*(180.0/PI));}
- /*two point's vector line*/
- PT vect(PT a,PT b){ return {a.x-b.x, a.y-b.y};}
- /*convert a coordinate p from cartesian to polar
- r = sqrt(x*x + y*y)
- theta = atan(y/x) [in radian]*/
- PT toPolar(PT p){
- return {sqrt(SQ(p.x)+SQ(p.y)), atan(p.y/p.x)};
- }
- /*convert a coordinate p from polar to cartesian
- theta must be radian
- x = r * cos(theta)
- y = r * sin(theta)*/
- PT toCartesian(PT a){
- return {a.x * cos(a.y), a.x * sin(a.y)};
- }
- /*divide line ab into m:n and return midpoint*/
- /*For 3D add the z part same as x and y*/
- PT divideLine(PT a, PT b, double m, double n){
- return {(a.x * m + b.x * n)/(m+n),
- (a.y * m + b.y * n)/(m+n)};
- }
- /*line ab to point c
- 0 => if ab and c coliner
- + => clockwise
- - => anticlockwise
- */
- int orientation(PT a, PT b, PT c)
- {
- double val = (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);
- if(abs(val) < eps) return 0;
- if(val > eps) return 1;
- return -1;
- }
- struct Rectangle
- {
- int fig;
- PT A, B, C, D;
- void scan(int _fig){
- A.scan();
- C.scan();
- B = {C.x, A.y};
- D = {A.x, C.y};
- fig = _fig;
- }
- bool inside(PT P){
- int val1 = orientation(A, B, P);
- int val2 = orientation(B, C, P);
- int val3 = orientation(C, D, P);
- int val4 = orientation(D, A, P);
- if(val1 == val2 && val2 == val3 && val3 == val4) return true;
- return false;
- }
- };
- struct Circle
- {
- int fig;
- PT A;
- double r;
- void scan(int _fig){
- A.scan();
- scanf("%lf", &r);
- fig = _fig;
- }
- bool inside(PT P){
- double dis = absDis(A, P);
- if(dis + eps < r) return true;
- return false;
- }
- };
- struct Triangle
- {
- int fig;
- PT A, B, C;
- void scan(int _fig){
- A.scan();
- B.scan();
- C.scan();
- fig = _fig;
- }
- bool inside(PT P){
- int val1 = orientation(A, B, P);
- int val2 = orientation(B, C, P);
- int val3 = orientation(C, A, P);
- if(val1 == val2 && val2 == val3) return true;
- return false;
- }
- };
- /*line ab and line cd is parrallel if ab X cd = 0 */
- bool ifParallel(PT a,PT b,PT c,PT d)
- {
- if(Cross(vect(a,b),vect(c,d)) != 0) // for double abs(val) > eps
- return false;
- return true;
- }
- /*line ab and line cd is perpendicular if ab . cd = 0 */
- bool ifPerpendicular(PT a,PT b,PT c,PT d)
- {
- if(Dot(vect(a,b),vect(c,d)) != 0) // for double abs(val) > eps
- return false;
- return true;
- }
- /*Area*/
- double heronTriangle(double a, double b, double c){
- double s = (a + b + c) / 2.0;
- if(s - a < 0) return -1;
- if(s - b < 0) return -1;
- if(s - c < 0) return -1;
- return sqrt(s * (s - a) * (s - b) * (s - c));
- }
- double mdedianTriangle(double a, double b, double c){
- double s = (a + b + c) / 2.0;
- if(s - a < 0) return -1;
- if(s - b < 0) return -1;
- if(s - c < 0) return -1;
- return (4.0 / 3.0 ) * sqrt(s * (s - a) * (s - b) * (s - c));
- }
- double trapeziumArea(double a, double b, double h){
- return (a + b) * h / 2.0;
- }
- ///Area of irregular polygon
- double AreaOfPolygon(int n,PT a[])
- {
- double area = 0.0;
- for(int i=1;i<n;i++){
- area+=(a[i-1].x*a[i].y-a[i].x*a[i-1].y);
- }
- area+=(a[n-1].x*a[0].y-a[0].x*a[n-1].y);
- return area/2.0;
- }
- /*volumn*/
- double coneVolume(double r, double h){
- return PI * r * r * h / 3.0;
- }
- double CircumcircleR(double a, double b, double c){
- if(a + b + c < eps) return 0;
- return (a * b * c) / sqrt((a + b + c) * (b + c - a) * (c + a - b) * (a + b - c));
- }
- double IncircleR(double a, double b, double c){
- if(a + b + c < eps) return 0;
- return 2.0 * heronTriangle(a, b, c) / (a + b + c);
- }
- bool insideRectangle(PT p, PT a, PT c){
- if(p.x < a.x or p.x > c.x) return false;
- if(p.y < a.y or p.y > c.y) return false;
- return true;
- }
- /*checking shapes*/
- bool isSquare(PT *a){
- if(abs(Dis(a[0], a[1]) - Dis(a[1], a[2])) > eps
- or abs(Dis(a[1], a[2]) - Dis(a[2], a[3])) > eps
- or abs(Dis(a[2], a[3]) - Dis(a[3], a[0])) > eps)
- return false;
- if(!ifPerpendicular(a[0], a[1], a[1], a[2])) return false;
- return true;
- }
- bool isRectangle(PT *a){
- if(abs(Dis(a[0], a[1]) - Dis(a[3], a[2])) > eps
- or abs(Dis(a[1], a[2]) - Dis(a[0], a[3])) > eps)
- return false;
- if(!ifPerpendicular(a[0], a[1], a[1], a[2])) return false;
- return true;
- }
- bool isRombus(PT *a){
- if(abs(Dis(a[0], a[1]) - Dis(a[1], a[2])) > eps
- or abs(Dis(a[1], a[2]) - Dis(a[2], a[3])) > eps
- or abs(Dis(a[2], a[3]) - Dis(a[3], a[0])) > eps)
- return false;
- return true;
- }
- bool isParallelogram(PT *a){
- if(abs(Dis(a[0], a[1]) - Dis(a[3], a[2])) > eps
- or abs(Dis(a[1], a[2]) - Dis(a[0], a[3])) > eps)
- return false;
- return true;
- }
- bool isTrapezium(PT *a){
- if(!ifParallel(a[0], a[1], a[3], a[2])
- and !ifParallel(a[1], a[2], a[0], a[3])) return false;
- return true;
- }
- PT f; //init first coordinate
- //for clockwise sorting
- bool ClockCmp(PT &a,PT &b){ return (f.x-a.x)*(f.y-b.y)<(f.x-b.x)*(f.y-a.y);}
- //for anti-clockwise sorting
- bool AClockCmp(PT &a,PT &b){ return (f.x-a.x)*(f.y-b.y)>(f.x-b.x)*(f.y-a.y);}
- int main()
- {
- #ifndef ONLINE_JUDGE
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- vector<Rectangle>RR;
- vector<Circle>CC;
- vector<Triangle>TT;
- int fig=0;
- char c;
- while(scanf("%c", &c)!=EOF){
- if(c=='*') break;
- fig++;
- // debug(c, fig);
- if(c == 'r'){
- Rectangle X;
- X.scan(fig);
- RR.pb(X);
- }
- else if(c == 'c'){
- Circle X;
- X.scan(fig);
- CC.pb(X);
- }
- else if(c == 't'){
- Triangle X;
- X.scan(fig);
- TT.pb(X);
- }
- getchar();
- }
- // debug(RR.size(), CC.size(), TT.size());
- double x, y;
- int point = 0;
- while(scanf("%lf %lf", &x, &y)!=EOF){
- if(abs(x-9999.9)<eps && abs(y-9999.9)<eps) break;
- point++;
- PT P = {x, y};
- vector< int > ans;
- for(auto rec : RR){
- if(rec.inside(P)){
- ans.pb(rec.fig);
- }
- }
- for(auto rec : CC){
- if(rec.inside(P)){
- ans.pb(rec.fig);
- }
- }
- for(auto rec : TT){
- if(rec.inside(P)){
- ans.pb(rec.fig);
- }
- }
- if(ans.size()){
- sort(all(ans));
- for(auto num : ans){
- pf("Point %d is contained in figure %d\n", point, num);
- }
- }
- else pf("Point %d is not contained in any figure\n", point);
- }
- #ifndef ONLINE_JUDGE
- fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement