Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==================================================================//
- // Name : flash7even //
- // Author : Tarango Khan //
- // Codeforces : flash_7 //
- // Topcoder : flash_7 //
- // Hackerrank : flash_7 //
- // Email : [email protected] //
- // Facebook : flash7even //
- //==================================================================//
- //==================================================================//
- #include <bits/stdc++.h> //
- using namespace std; //
- #define read(nm) freopen(nm, "r", stdin) //
- #define write(nm) freopen(nm, "w", stdout) //
- #define pb push_back //
- #define MP make_pair //
- #define ff first //
- #define ss second //
- #define FABS(x) ((x)+eps<0?-(x):(x)) //
- #define POPCOUNT __builtin_popcountll //
- #define RIGHTMOST __builtin_ctzll //
- #define LEFTMOST(x) (63-__builtin_clzll((x))) //
- #define NUMDIGIT(x,y) (((int)(log10((x))/log10((y))))+1) //
- #define SQ(x) ((x)*(x)) //
- #define pf printf //
- #define sf scanf //
- #define phl printf("hello\n") //
- #define SZ(x) ((int)(x).size()) //
- #define mems(x,v) memset(x,v,sizeof(x)) //
- #define CLR(x,y) memset(x,y,sizeof(x)) //
- #define ALL(x) (x).begin(),(x).end() //
- #define NORM(x) if(x>=mod)x-=mod; //
- #define MOD(x,y) (((x)*(y))%mod) //
- #define fills(v,n) fill(v.begin(), v.end(), n) //
- #define LL long long //
- #define LLU long long unsigned int //
- #define vlong long long //
- #define uvlong unsigned long long //
- #define debug1(v1) cout<<"1@ Debug Val 1 = "<<v1<<endl; //
- #define debug2(v2) cout<<" 2@ Debug Num 2 = "<<v2<<endl; //
- #define debug3(v3) cout<<" 3@ Debug Res 3 = "<<v3<<endl; //
- #define UB(v,a) upper_bound(v.begin(),v.end(),a)-v.begin() //
- #define LB(v,a) lower_bound(v.begin(),v.end(),a)-v.begin() //
- #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL) //
- //==================================================================//
- //==================================================================//
- void make_unique(vector<int> &a){ sort(a.begin(), a.end()); //
- a.erase(unique(a.begin(), a.end()), a.end()); } //
- void printDouble(double f,int p){ cout << fixed; //
- cout << setprecision(p) << f <<endl; } //
- int Set(int N,int cur){ return N = N | (1<<cur); } //
- int Reset(int N,int cur){ return N = N & ~(1<<cur); } //
- bool Check(int N,int cur){ return (bool)(N & (1<<cur)); } //
- LL GCD(LL a,LL b){ if(b == 0) return a; return GCD(b,a%b);} //
- LL LCM(LL a,LL b){ return a*b/GCD(a,b);} //
- LL POW(LL a,LL p){ LL res = 1,x = a;while(p){if(p&1) //
- res = (res*x); x = (x*x);p >>= 1;} return res;} //
- //==================================================================//
- //==================================================================//
- //int knightDir[8][2] = {{-2,1},{-1,2},{1,2},{2,1}, //
- // {2,-1},{-1,-2},{1,-2},{-2,-1}}; //
- //int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1}, //
- // {-1,-1},{1,1},{1,-1},{-1,1}}; //
- //int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; //
- //==================================================================//
- #ifdef forthright48
- #include <ctime>
- clock_t tStart = clock();
- #define debug(args...) {dbg,args; cerr<<endl;}
- #define timeStamp printf("Exc Time: %.2fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC)
- #else
- #define debug(args...)
- #define timeStamp
- #endif
- struct debugger{
- template<typename T> debugger& operator , (const T& v){
- cerr << v << " ";
- return *this;
- }
- }dbg;
- typedef pair <LL,LL> pll;
- typedef vector<pll> vll;
- typedef vector<LL> vl;
- const LL inf = 2147383647;
- const LL MOD = 1000000007;
- const double pi = 2*acos(0.0);
- const double eps = 1e-9;
- #define Size 100005
- //=======// Done With The Shortcut Stuffs! Now Let's Code! //=======//
- struct Point {
- LL x, y;
- };
- Point pointList[Size];
- Point hullPoints[Size];
- stack<Point> S;
- int N,cnt;
- LL dist(Point P, Point Q) {
- return SQ(P.x - Q.x) + SQ(P.y - Q.y);
- }
- LL orientation(Point P, Point Q, Point R) {
- LL ret = (Q.y - P.y) * (R.x - Q.x) - (Q.x - P.x) * (R.y - Q.y);
- if (ret > 0) return 1;
- if (ret < 0) return 2;
- return ret;
- }
- bool cmp(Point X, Point Y) {
- LL ret = orientation(pointList[0], X, Y);
- if (ret == 0) {
- LL dist1 = dist(pointList[0], X);
- LL dist2 = dist(pointList[0], Y);
- return (dist1 < dist2);
- } else if (ret == 2){
- return true;
- } else {
- return false;
- }
- }
- Point nextToTop() {
- Point P = S.top();
- S.pop();
- Point res = S.top();
- S.push(P);
- return res;
- }
- void convexHull(int N) {
- int ymin = pointList[0].y, index = 0;
- for (int i = 1; i < N; i++) {
- if (pointList[i].y < ymin || (pointList[i].y == ymin &&
- pointList[i].x < pointList[index].x)) {
- ymin = pointList[i].y;
- index = i;
- }
- }
- swap(pointList[0], pointList[index]);
- sort(&pointList[1], &pointList[N], cmp);
- S.push(pointList[0]);
- for (int i = 1; i < N; i++) {
- while (S.size() > 1){
- if(orientation(nextToTop(),S.top(), pointList[i]) == 2) break;
- S.pop();
- }
- S.push(pointList[i]);
- }
- cnt = 0;
- while (!S.empty()) {
- hullPoints[cnt++] = S.top();
- S.pop();
- }
- }
- double angle(Point a, Point o, Point b) {
- Point t1, t2;
- t1.x = a.x - o.x;
- t1.y = a.y - o.y;
- t2.x = b.x - o.x;
- t2.y = b.y - o.y;
- double theta = atan2((double)t2.y, (double)t2.x) -
- atan2((double)t1.y, (double)t1.x);
- if(theta < 0) theta += (2.0 * pi); /// If theta negative, we add 2*180 degree to make positive.
- return theta;
- }
- double getMaxAngelInPolygon(){
- if(cnt<3) return 0;
- double res = angle(hullPoints[cnt-1], hullPoints[0], hullPoints[1]);
- hullPoints[cnt] = hullPoints[0];
- for(int i = 1; i < cnt; i++) {
- double ang = angle(hullPoints[i-1], hullPoints[i], hullPoints[i+1]);
- if(ang < res) res = ang;
- }
- return res;
- }
- int main() {
- int N,nCase;
- sf("%d",&nCase);
- for(int cs = 1;cs<=nCase;cs++){
- scanf("%d", &N);
- for (int i = 0; i < N; i++) {
- scanf("%lld %lld", &pointList[i].x, &pointList[i].y);
- }
- convexHull(N);
- double res = getMaxAngelInPolygon();
- res = res*180.0/pi;
- pf("Case %d: %.7lf\n",cs,res);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment