Problem:
Problem E:
Triangles
There is a group that paints an emblem on the ground to invite aliens every year. You are a member of
this group and you have to paint the emblem this year.
The shape of the emblem is described as follows. It is made of
n
regular triangles whose sides are
equally one unit length long. These triangles are placed so that their centroids coincide, and each of them
is rotated counterclockwise by 360/
n
degrees with respect to the one over it around its centroid. The
direction of the top triangle is not taken into account.
It is believed that emblems have more impact as their
n
are taken larger. So you want to paint the emblem
of
n
as large as possible, but you don’t have so much chemicals to paint. Your task is to write a program
which outputs the area of the emblem for given
n
so that you can estimate the amount of the needed
chemicals.
Figure 1: The Emblem for
n
= 2
Input
The input data is made of a number of data sets. Each data set is made of one line which contains an
integer
n
between 1 and 1000 inclusive.
The input is terminated by a line with
n
= 0. This line should not be processed.
Output
For each data set, output the area of the emblem on one line. Your program may output an arbitrary
number of digits after the decimal point. However, the error should be 10
-6
( = 0.000001) or less.
Sample Input
1
2
3
4
5
6
0
Output for the Sample Input
0.433013
0.577350
0.433013
0.732051
0.776798
0.577350

Submitted solutions:

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}

P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}
double getarea(const VP &poly){
    double ret = 0;
    for (int i=0; i<(int)poly.size(); i++){ 
        ret += cross(poly[i], poly[(i+1)%poly.size()]);
    }
    return ret*0.5;
}

int main(){
    cout << fixed << setprecision(10);
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        vector<int> angle(3*n);
        int mod = 360*n;
        for(int i=0; i<n; i++){
            angle[3*i] = 360*i %mod;
            angle[3*i +1] = (360*i +120*n) %mod;
            angle[3*i +2] = (360*i +240*n) %mod;
        }
        sort(angle.begin(), angle.end());
        angle.erase(unique(angle.begin(), angle.end()), angle.end());

        double r = 1/sqrt(3);
        VP p(angle.size());
        for(int i=0; i<(int)angle.size(); i++){
            double theta = angle[i] *2 *PI /mod;
            p[i] = P(r, 0) *P(cos(theta), sin(theta));
        }
        int m = p.size();
        if(m == 3){
            cout << getarea(p) << endl;
            continue;
        }

        P rot(cos(PI*2/3), sin(PI*2/3));
        VP poly;
        for(int i=0; i<m; i++){
            poly.push_back(p[i]);
            poly.push_back(crosspointLL(L(p[i], p[i]*rot), L(p[(i+1)%m], p[(i+1)%m]/rot)));
        }
        cout << getarea(poly) << endl;
    }    
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 3576
final_rank: 11

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Point{
	void set(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}
	double x,y;
};

int N;
Point point[5000];
double R;

Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(x1 != x2){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

double calc_S(Point a,Point b,Point c,Point d){
	return fabs((b.x*a.y - b.y*a.x)+(c.x*b.y - c.y*b.x)+(d.x*c.y - d.y*c.x)+(a.x*d.y - a.y*d.x))/2;
}

void func(){

	if(N%3 == 0)N /= 3;

	if(N == 1){
		printf("0.433013\n");
		return;
	}

	double base_degree = 360.0/(double)(3*N);

	for(int i = 0; i < 3*N; i++){
		point[i].x = R*cos(((90-base_degree*i)*M_PI)/180.0);
		point[i].y = R*sin(((90-base_degree*i)*M_PI)/180.0);
	}

	Point a,b,c,d,ret;
	a.set(point[0].x,point[0].y);

	ret = calc_Cross_Point(point[0].x,point[N].x,point[1].x,point[2*N+1].x,point[0].y,point[N].y,point[1].y,point[2*N+1].y);
	b.set(ret.x,ret.y);

	c.set(0,0);

	ret = calc_Cross_Point(point[0].x,point[2*N].x,point[3*N-1].x,point[N-1].x,point[0].y,point[2*N].y,point[3*N-1].y,point[N-1].y);
	d.set(ret.x,ret.y);

	printf("%.10lf\n",(double)3*N*calc_S(a,b,c,d));
}


int main(){

	R = 1.0/sqrt(3.0);

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}
}
accuracy: 1
time_ms: 50
memory_kb: 3480
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define PI M_PI
#define EPS 1e-14
using namespace std;
typedef complex<double> point;
namespace std {
  bool operator < (const point& a, const point& b){
    return fabs(real(a)-real(b)) <EPS  ? imag(a) < imag(b) : real(a) < real(b);
  }
  bool operator == (const point& a,const point& b){
    return abs(real(a)-real(b))<EPS&&abs(imag(a)-imag(b))<EPS;
  }
  bool operator != (const point& a,const point& b){
    return !(abs(real(a)-real(b))<EPS&&abs(imag(a)-imag(b))<EPS);
  }
  
}
int n;
double cross(point a,point b){return a.real()*b.imag()-a.imag()*b.real();}

point rot(point a,double rad){
  return a*conj(point(cos(rad),sin(rad)));
}

point crosspoint(point a,point b,point c,point d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
double getArea3(point a,point b,point c){return abs(cross(b-a,c-a)/2);}

double solve(){
  vector <point> a;
  double base=2*PI/3;
  point A=point(0,1/sqrt(3));
  a.push_back(A);
  a.push_back(rot(A,base));  
  a.push_back(rot(A,base*2));

  double rad=2*PI/n;
  for(int i=1;i<=n;i++)
    for(int j=0;j<3;j++)a.push_back(rot(a[j],rad*i));
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  
  double dis=1e9;
  point B;
  for(int i=0;i<a.size();i++)
    if(A!=a[i]&&real(a[i])>0&&abs(A-a[i])<dis)dis=abs(A-a[i]),B=a[i];
  point C=crosspoint(A,rot(A,base),B,rot(B,base*2));
  double s=getArea3(A,B,C);
  double S=(dis/2)*(dis/2)/tan(PI/a.size());
  return (S-s)*a.size();
}


int main(){
  while(cin>>n,n)printf("%.15f\n",solve());
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 3672
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);
 
P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isParallel(P a,P b,P c,P d){
  return (abs(imag( (b-a)*conj(d-c) ) )<eps);
}
 
int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}
 
int n;
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
     
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
     
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;
 
    P c=a,d=b;
 
    if(lc==3){
      printf("0.433013\n");
      continue;
    }
     
    double T=1e9;
    for(int i=1;i<=lc/3;i++){
      c=a*P(cos(ti*i),sin(ti*i));
      d=b*P(cos(ti*i),sin(ti*i));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }

      //      if(i==2)i=lc/3-2;
    }
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}
accuracy: 1
time_ms: 60
memory_kb: 1212
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);
 
P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isParallel(P a,P b,P c,P d){
  return (abs(imag( (b-a)*conj(d-c) ) )<eps);
}
 
int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}
 
int n;
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
     
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
     
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;
 
    P c=a,d=b;
 
    if(lc==3){
      printf("0.433013\n");
      continue;
    }
     
    double T=1e9;
    for(int i=0;i<lc/3;i++){
      c*=P(cos(ti),sin(ti));
      d*=P(cos(ti),sin(ti));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }
    }
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}
accuracy: 1
time_ms: 40
memory_kb: 1212
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);
 
P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isParallel(P a,P b,P c,P d){
  return (abs(imag( (b-a)*conj(d-c) ) )<eps);
}
 
int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}
 
int n;
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
     
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
     
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;
 
    P c=a,d=b;
 
    if(lc==3){
      printf("0.433013\n");
      continue;
    }
     
    double T=1e9;
    for(int i=0;i<lc;i++){
      c*=P(cos(ti),sin(ti));
      d*=P(cos(ti),sin(ti));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }
    }
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}
accuracy: 1
time_ms: 100
memory_kb: 1212
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
 
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
 
namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
};
double dot(P a, P b){ return a.real() * b.real() + a.imag() * b.imag(); }
double cross(P a, P b){ return   a.real() * b.imag() - a.imag() * b.real(); }
double area(vector<P> v){
  double sum = 0.0;
  int n = v.size();
  for(int i=0;i<n;i++) sum += (real(v[i]) - real(v[(i+1)%n])) * (imag(v[i]) + imag(v[(i+1)%n]));
  return fabs(sum) / 2;
};
P rotate(P p, double theta){
  theta = theta * M_PI / 180.0;
  double x = real(p) * cos(theta) - imag(p) * sin(theta);
  double y = real(p) * sin(theta) + imag(p) * cos(theta);
  return P(x,y);
}
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1; //テ・ツ渉催ヲツ卍づィツィツ暗・ツ崢榲」ツつ?
  if(cross(b,c) < -EPS) return -1; // テヲツ卍づィツィツ暗・ツ崢榲」ツつ?
  if(dot(b,c) < -EPS) return 2; // c -- a -- b テ」ツ?ョテ、ツクツ?ァツ崢エテァツキツ?
  if(norm(b) < norm(c)) return -2; // a -- b -- c テ」ツ?ョテ、ツクツ?ァツ崢エテァツキツ?
  return 0; // a -- c -- b テ」ツ?ョテ、ツクツ?ァツ崢エテァツキツ?
}
P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}
int N;
typedef pair<bool,double> PR;
double getA( double pi ){
  if( pi+EPS > M_PI ) return -M_PI;
  return pi;
}
int main(){
  while( ~scanf("%d",&N) && N){
    P v=P(0,1.0/sqrt(3));
    set<P> sp;
    vector< pair<PR,L> > ss;
    for(int i=0;i<N;i++){
      P v1 = v;
      for(int i=0;i<3;i++){
        P v2 = rotate( v1, 120.0 );  
        //cout << " " << v1 << " "<< v2 << endl;      
        ss.push_back( make_pair( PR(0,getA(arg(v1))), L( v1, v2 ) ) );        
        ss.push_back( make_pair( PR(1,getA(arg(v2))), L( v2, v1 ) ) );
        v1 = v2;
      }
      v = rotate( v, 360.0/(double)N );
    }    
    sort( ss.begin(), ss.end() );
    int cnt = 0;
    for(int i=0;i<(int)ss.size()-1-cnt;i++){
      // cout << ss[i].first.second << endl;
      if( ss[i].first.first == ss[i+1].first.first && abs( ss[i].first.second - ss[i+1].first.second ) < EPS ){
        cnt++;
        for(int j=i+1;j<(int)ss.size()-1;j++)
          ss[j] = ss[j+1];       
        i--;
      }
    }    
    ss.erase( ss.end()-cnt, ss.end() );    
    int n = ss.size();
    vector<P> p;
    for(int i=0;i<n/2;i++){
      L s1 = ss[i].second;
      L s2 = ss[i+1].second;
      L s3 = ss[(i+1+n/2==n)?(n/2):(i+1+n/2)].second;
      //  cout <<" x" << s1.first << " " << s1.second << endl;
      //cout << " y"<< s3.first <<" "<<s3.second << endl;
      p.push_back( s1.first );
      P mp = crossPoint( s1, s3 );      
      if( abs( mp - s2.first ) > EPS) 
        p.push_back( mp );      
    } 
    printf("%.9lf\n",area( p ) );
  }  
}
accuracy: 1
time_ms: 4830
memory_kb: 1956
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS = 1e-8;
typedef complex<double> P;
typedef pair<P,P> L;
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
bool cmp(P a,P b) {return atan2(a.imag(),a.real())<atan2(b.imag(),b.real());}
double toRad(double agl) {return agl*M_PI/180.0;}
double D(P a, P b) {
  return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}
P kaiten(P a, double r) {
  return P(a.real()*cos(r)-a.imag()*sin(r),a.real()*sin(r)+a.imag()*cos(r));
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l.S - l.F, m.S-m.F);
  double B = cross(l.S - l.F, l.S - m.F);
  if(fabs(A)<EPS&&fabs(B)<EPS) return m.F;
  return m.F+B/A*(m.S-m.F);
}
double area(vector<P> p) {
  double a=0;
  for(int i=0; i<(int)p.size(); i++) a+=cross(p[i],p[(i+1)%p.size()]);
  return fabs(a)/2;
}

int main() {
  int n;int c=1;
  while(scanf("%d",&n)==1 && n) {
    vector<P> v;
    for(int i=0; i<n; i++) {
      P p[3];
      p[0]=P(1,0);
      p[1]=kaiten(p[0],toRad(120));
      p[2]=kaiten(p[1],toRad(120));
      for(int j=0; j<3; j++) p[j]=kaiten(p[j],toRad(360.0/n*i));
      if(i) {
        bool f=0;
        for(int j=0; j<3; j++) {
          if(D(v[0],p[j])<EPS) f=1;
        }
        if(f) break;
      }
      v.push_back(p[0]);
      v.push_back(p[1]);
      v.push_back(p[2]);
    }
    sort(v.begin(),v.end(),cmp);
    int m=v.size();
    P p=crosspoint(L(v[0],v[m/3]),L(v[1],v[m/3*2+1]));
    for(int i=0; i<m; i++) {
      v.push_back(p);
      p=kaiten(p,toRad(360.0/m));
    }
    sort(v.begin(),v.end(),cmp);
    printf("%.10f\n",area(v)/3);
  }
  return 0;
}
accuracy: 1
time_ms: 5780
memory_kb: 1444
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);

bool eq(double a,double b){
  return (-eps<a-b&&a-b<eps);
}

P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

bool isParallel(P a,P b,P c,P d){
  return eq(0,imag( (b-a)*conj(d-c) ) );
}

bool onSegment(P a,P b,P p){
  return eq(abs(b-a),abs(p-a)+abs(p-b));
}


int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}

int n;

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
    
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;

    P c=a,d=b;

    if(lc==3){
      printf("0.433013\n");
      continue;
    }
    
    double T=1e9;
    for(int i=0;i<n;i++){
      c*=P(cos(ti),sin(ti));
      d*=P(cos(ti),sin(ti));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(eq(k,0))continue;
        T=min(T,k);
      }

    }
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}
accuracy: 1
time_ms: 50
memory_kb: 1212
final_rank: 5

code_snippet: /*include*/
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#include<complex>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const double inf=1e8;
using namespace std;
typedef complex<double> P;
typedef vector<P> G;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
struct C{
	P c;double r;
	C(const P &c,double r):c(c),r(r){}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
		//return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);  
	}
	bool operator == (const P& a, const P& b) {
		return a.real()==b.real()&&a.imag()==b.imag();
	}
}
P pin(){
	double x,y;
	char d;
	cin>>x>>y;
	P p(x,y);
	return p;
}
void PIN(P* a,int n){
	rep(i,n)a[i]=pin();
}
double dot(P a,P b){
	return real(conj(a)*b);
}
double cross(P a,P b){
	return imag(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
P projection(L a,P p){
	double t=dot(p-a[0],a[0]-a[1])/norm(a[0]-a[1]);
	return a[0]+t*(a[0]-a[1]);
}
P reflection(L a,P p){
	return p+2.0*(projection(a,p)-p);
}
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
double distanceLP(const L &l, const P &p) {
	return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
bool intersectCL(C c,const L &l){
    return (distanceLP(l,c.c) < c.r+EPS &&
            (c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS));
}
P crosspointSS(L a,L b){
	double t1=abs(cross(a[1]-a[0],b[0]-a[0]));
	double t2=abs(cross(a[1]-a[0],b[1]-a[0]));
	return b[0]+(b[1]-b[0])*t1/(t1+t2);
}
L crosspointCL(C c,L l){
	P pr=projection(l,c.c);
	P e=(l[1]-l[0])/abs(l[1]-l[0]);
	double t=sqrt(c.r*c.r-norm(pr-c.c));
	P a=pr+t*e;
	P b=pr-t*e;
	if(b<a)swap(a,b);
	return L(a,b);
}
L crosspointCC(C a,C b){
	P tmp=b.c-a.c;
	double d=abs(tmp);
	double q=acos((a.r*a.r+d*d-b.r*b.r)/(2*a.r*d));
	double t=arg(tmp);//atan(tmp.imag()/tmp.real());
	P p1=a.c+polar(a.r,t+q);
	P p2=a.c+polar(a.r,t-q);
	if(p2<p1)swap(p1,p2);
	return L(p1,p2);
}
P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g){
    double S =0;
    for(int i =0;i <g.size();i++){
        S +=(cross(g[i],g[(i+1)%g.size()]));
    }
    return abs(S/2.0);
}
bool isconvex(const G &g){
	int n=g.size();
	rep(i,n)if(ccw(g[(i+n-1)%n],g[i%n],g[(i+1)%n])==-1)return false;
	return true;
}
int inconvex(const G& g, const P& p) {
	bool in = false;
	int n=g.size();
	rep(i,n){
		P a=g[i%n]-p;
		P b=g[(i+1)%n]-p;
		if(imag(a)>imag(b))swap(a, b);
		if(imag(a)<=0&&0<imag(b))if(cross(a,b)<0)in=!in;
		if(cross(a,b)==0&&dot(a,b)<=0)return 1;//ON
	}
	return in?2:0;//IN : OUT;
}
G convex_hull(G &ps) {
    int n=ps.size(),k=0;
	sort(ps.begin(), ps.end());
	G ch(2*n);
	for(int i=0;i<n;ch[k++]=ps[i++])//lower-hull
		while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])==-1)--k;//<=0  ->  ==-1
	for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--])//upper-hull
		while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])==-1)--k;//
	ch.resize(k-1);
	return ch;
}
double convex_diameter(const G &pt) {
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  double maxd = norm(pt[is]-pt[js]);

  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
    else i = (i+1) % n;
    if (norm(pt[i]-pt[j]) > maxd) {
      maxd = norm(pt[i]-pt[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd); /* farthest pair is (maxi, maxj). */
}//convex_diameter(g)
G convex_cut(const G& g, const L& l) {
  G Q;
  for (int i = 0; i < g.size(); ++i) {
    P a= curr(g, i), b= next(g, i);
    if (ccw(l[0], l[1], a) != -1) Q.push_back(a);
    if (ccw(l[0], l[1], a)*ccw(l[0], l[1], b) < 0)
      Q.push_back(crosspointLL(L(a,b), l));
  }
  return Q;
}
P turn(P p,double t){
	return p*exp(P(.0,t*PI/180.0));
}
void printL(const L &out){
	printf("%.9f %.9f %.9f %.9f\n",out[0].real(),out[0].imag(),out[1].real(),out[1].imag());
}
C CIN(){
	P p=pin();
	double r;
	cin>>r;
	return C(p,r);
}
bool para(L a,L b){
	return (abs(cross(a[1]-a[0],b[1]-b[0]))<EPS);
}
int main(){
	int n;
	while(cin>>n,n){
		if(n==1){
			printf("%.6f\n",0.433013);
			continue;
		}
		double sum=0;
		P p(0,1);
		G g;
		vector<double>kak(1);kak[0]=120;
		rep(i,n){
			double q=360.0/n*(i+1);
			while(q+EPS>120)q-=120;
			kak.pb(q);
		}
		sort(all(kak));
		rep(i,kak.size())g.pb(turn(p,kak[kak.size()-i-1]));
		rep(i,n){
			L a(g[i],turn(g[i],240));
			L b(g[i+1],turn(g[i+1],120));
			G t(3);t[0]=g[i];t[1]=crosspointLL(a,b);t[2]=g[i+1];
			sum-=area(t);
			t[1]=P(0,0);
			sum+=area(t);
		}
		printf("%.6f\n",sum);
	}
}
accuracy: 1
time_ms: 230
memory_kb: 1304
final_rank: 9

code_snippet: #include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double PI=acos(-1);

int main(){
	for(int n;scanf("%d",&n),n;){
		vector<double> theta;
		rep(i,n){
			theta.push_back(2*i*PI/n+0*PI/3);
			theta.push_back(2*i*PI/n+2*PI/3);
			theta.push_back(2*i*PI/n+4*PI/3);
		}
		rep(i,theta.size()) if(theta[i]>2*PI) theta[i]-=2*PI;
		sort(theta.begin(),theta.end());

		double ans=0;
		rep(i,theta.size()){
			double t1=theta[i],t2=theta[(i+1)%theta.size()];
			if(t2<t1) t2+=2*PI;
			double phi=(t2-t1)/2;
			double h=1/(1/tan(phi)+1/tan(PI/6));
			ans+=2*(1*h/2);
		}
		printf("%.9f\n",ans/3); // 一辺が 1/√3 なので面積は 1/3 倍
	}

	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 1188
final_rank: 4

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;

typedef complex<double> P;

const double eps = 1.0e-7;
const double pi = acos(-1);

bool equals(double a, double b) { return abs(a-b) < eps; }
bool equals(P a, P b) {
  return equals(a.real(),b.real()) && equals(a.imag(),b.imag());
}

namespace std {
  bool operator < (const P& a, const P& b) {
    if(!equals(a.real(),b.real())) return a.real() < b.real();
    if(!equals(a.imag(),b.imag())) return a.imag() < b.imag();
    return false;
  }
}

P rotate(P p, double rad) {
  return P(cos(rad)*p.real() - sin(rad)*p.imag(),
	   sin(rad)*p.real() + cos(rad)*p.imag());
}

double solve(int N) {
  const static double r2 = 1.0/(2.0*(1.0-cos(pi*2.0/3.0)));
  vector<P> ps;
  vector<P> tri;
  tri.push_back(P(1.0,0.0));
  tri.push_back(rotate(P(1.0,0.0),pi*2.0/3.0));
  tri.push_back(rotate(P(1.0,0.0),-pi*2.0/3.0));
  double d = pi*2.0/(double)N;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < tri.size(); ++j) {
      ps.push_back(rotate(tri[j],pi*2.0*i/(double)N));
    }
  }

  sort(ps.begin(), ps.end());
  int n = ps.size();
  for(int i = 1; i < ps.size(); ++i)
    n -= equals(ps[i-1],ps[i]);

  double rad = pi*2.0/(double)n;
  double rad2 = (pi*(n-2)/(double)n - pi/3.0)/2.0;
  double l2 = 2.0 * r2 * (1.0-cos(rad));
  return r2*pi - n*( (rad-sin(rad))*r2/2.0 + tan(rad2)*l2/4.0 );
}

int main() {
  int n;
  while(scanf("%d",&n) != EOF && n) printf("%.6f\n", solve(n));
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 0
final_rank: 1

code_snippet: #include<iostream>
#include<cmath>
#include<set>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(ui,n)  REP(i,0,n)
#define double long double
const double r = 1./sqrt(3);
const double pi=acos(-1);
const double eps = 1e-10;

double CONVERT(double r){
  return r*pi/180.;
}

double solve(int n,double theta){
  double npolygon=0,minus=0;
  double l =2*r*sin(CONVERT(theta/2));
  npolygon=n*r*r*cos(CONVERT(theta/2))*sin(CONVERT(theta/2));
  minus=n*l*tan(CONVERT(60-theta/2))*l/4.;
  return npolygon-minus;
}

double calc(double a){
  while(a > 360-eps)a-=360;
  return a;
}

main(){
  int n;
  while(cin>>n && n){
    double now=0;
    set<double> S;
    rep(i,n){
      S.insert(calc(now));
      S.insert(calc(now+120));
      S.insert(calc(now+240));
      now+=360./n;
    }
    //printf("%.6lf\n",solve((int)S.size(),360./S.size()));

    if (n%3 == 0){
      //if (S.size()%3 != 0)cout <<"h"<<endl,exit(1);
      printf("%.6Lf\n",solve((int)n,360./n));
    }else {
      printf("%.6Lf\n",solve((int)3*n,120./n));      
    }
  }
  return false;
}
accuracy: 1
time_ms: 210
memory_kb: 1044
final_rank: 2

code_snippet: #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
static const double PI = acos(-1);
#define EPS 0.0000001
double getArea( double c, double A, double B ){
    return c*c*sin(A)*sin(B)/(2*sin(A+B));
}

bool eq( double a, double b ){
    return fabs(a-b)<EPS;
}

void compute(set<double> angle ){
    vector<double> v;
    for ( set<double>::iterator it = angle.begin(); it != angle.end(); it++ ){
	double x = *it;
	if ( v.size() == 0 ) v.push_back(x);
	else if ( fabs(v[v.size()-1]-x) > EPS ) v.push_back(x);
    }

    double r = 0.5/cos(30*PI/180);
    int n = v.size();
    double d = (v[1] - v[0])/2;
    double area = 2*getArea(r, d*PI/180, 30*PI/180);
    printf("%.16lf\n", area*n);
}

void insertP( set<double> &p, double a ){
    if ( a > 360.0 || eq(a, 360)) p.insert(a - 360.0);
    else p.insert(a);
}

main(){
    int n;
    while( cin >> n && n ){
	set<double> p;
	for ( int i = 0; i < 3; i++ ) p.insert(i*120.0);
	double cur = 0.0;
	for ( int t = 1; t < n; t++ ){
	    cur += 360.0/n;
	    for ( int i = 0; i < 3; i++ ) insertP(p, cur+i*120.0);
	}
	compute(p);
    }
}
accuracy: 1
time_ms: 360
memory_kb: 1204
final_rank: 8