Problem:
Problem E:
Mickle's Beam
Major Mickle is commanded to protect a secret base which is being attacked by
N
tanks. Mickle has an ultimate laser rifle called
Mickle's beam
. Any object shot by this beam will be immediately destroyed, and there is no way for protection. Furthermore, the beam keeps going through even after destroying objects. The beam is such a powerful and horrible weapon, but there is one drawback: the beam consumes a huge amount of energy. For this reason, the number of shots should be always minimized.
Your job is to write a program that calculates the minimum number of shots required to destroy all the enemy tanks.
You can assume the following:
the base is located on the origin (0, 0);
each tank has a rectangular shape with edges parallel to the
x
- and
y
-axes;
no tank may touch or include the origin;
no two tanks share the same point;
the width of beam is negligible; and
a beam destroys every tank it touches or crosses.
Input
The input consists of an integer sequence.
The first integer indicates
N
(
N
≤ 2,000). Each of the following
N
lines contains four integers which indicates the
x
- and
y
-coordinates of the lower-left corner and the upper-right corner of a tank respectively. You can assume that every coordinate may not exceed 10,000 in absolute value.
Output
Output the minimum number of shots of the beam.
Sample Input and Output
Input #1
4
2 -1 3 1
-1 2 1 3
-3 -1 -2 1
-1 -3 1 -2
Output #1
4
Input #2
2
1 0 2 1
3 -1 4 0
Output #2
1

Submitted solutions:

code_snippet: #include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define sgn(v) (abs((v))<eps?0:((v)<0?-1:1))
#define sqr(v) ((v)*(v))
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define debug 0
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double,int> PDI;
typedef pair<double,double> PDD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
const double eps=1e-9;
const double pi=acos(-1);
vector<PDD> it,tp;
double ag[4];
bool cmpSE(PDD p,PDD q)
{
	if(sgn(p.SE-q.SE))return p.SE<q.SE;
	else return p.FI<q.FI;
}
bool cmpFI(PDD p,PDD q)
{
	if(sgn(p.FI-q.FI))return p.FI<q.FI;
	else return p.SE<q.SE;
}
bool In(double v,double l,double r)
{
	for(int k=-3;k<=3;++k)
		if((sgn(l-v-k*2*pi)<=0&&sgn(v+k*2*pi-r)<=0))return true;
	return false;
}
int main()
{
	//cout <<pi/4*3<<endl;
	int n,i,j,con;
	int x1,y1,x2,y2;
	double l,r,nr;
	scanf("%d",&n);
	for(i=0;i<n;++i)
	{
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		ag[0]=atan2(y1,x1);ag[1]=atan2(y1,x2);
		ag[2]=atan2(y2,x1);ag[3]=atan2(y2,x2);
		sort(ag,ag+4);
		l=ag[0],r=ag[3];
		//cout <<ag[0]<<" "<<ag[1]<<" "<<ag[2]<<" "<<ag[3]<<endl;cout <<l<<" "<<r<<endl;
		if(sgn(r-l-pi)>0)
		{
			for(j=0;j<4;++j)if(sgn(ag[j])<0)ag[j]+=2*pi;
			sort(ag,ag+4);
			l=ag[0],r=ag[3];
		}
		//cout <<l<<" "<<r<<endl;
		if(sgn(l-r)>0)while(1);
		it.PB(MP(l,r));
	}
	sort(it.begin(),it.end());
	//for(i=0;i<it.size();++i)cout <<it[i].FI<<" "<<it[i].SE<<endl;
	int ans=n;
	for(i=0;i<it.size();++i)
	{
		nr=it[i].FI;
		tp.clear();
		con=1;
		for(j=0;j<i;++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(MP(it[j].FI+2*pi,it[j].SE+2*pi));
		}
		for(j=i+1;j<it.size();++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(it[j]);
		}
		sort(tp.begin(),tp.end(),cmpSE);
		//cout <<"This is l:"<<nr<<" "<<tp.size()<<endl;for(j=0;j<tp.size();++j)cout <<tp[j].FI<<" "<<tp[j].SE<<endl;
		for(j=0;j<tp.size();++j)
		{
			if(j==0||!(In(nr,tp[j].FI,tp[j].SE)))
				nr=tp[j].SE,++con;
		}
		ans=min(ans,con);
		nr=it[i].FI;
		tp.clear();
		con=1;
		for(j=0;j<i;++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(MP(it[j].FI+2*pi,it[j].SE+2*pi));
		}
		for(j=i+1;j<it.size();++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(it[j]);
		}
		sort(tp.begin(),tp.end(),cmpFI);
		//cout <<"This is l:"<<nr<<" "<<tp.size()<<endl;for(j=0;j<tp.size();++j)cout <<tp[j].FI<<" "<<tp[j].SE<<endl;
		for(j=0;j<tp.size();++j)
		{
			if(j==0||!(In(nr,tp[j].FI,tp[j].SE)))
				nr=tp[j].FI,++con;
		}
		ans=min(ans,con);
		//-----------------------------------------------use L-----------------------------------------------------
		nr=it[i].SE;
		tp.clear();
		con=1;
		for(j=0;j<i;++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(MP(it[j].FI+2*pi,it[j].SE+2*pi));
		}
		for(j=i+1;j<it.size();++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(it[j]);
		}
		sort(tp.begin(),tp.end(),cmpSE);
		//cout <<"This is r:"<<nr<<" "<<tp.size()<<endl;for(j=0;j<tp.size();++j)cout <<tp[j].FI<<" "<<tp[j].SE<<endl;
		for(j=0;j<tp.size();++j)
		{
			if(j==0||!(In(nr,tp[j].FI,tp[j].SE)))
				nr=tp[j].SE,++con;
		}
		ans=min(ans,con);
		nr=it[i].SE;
		tp.clear();
		con=1;
		for(j=0;j<i;++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(MP(it[j].FI+2*pi,it[j].SE+2*pi));
		}
		for(j=i+1;j<it.size();++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp.PB(it[j]);
		}
		sort(tp.begin(),tp.end(),cmpFI);
		//cout <<"This is r:"<<nr<<" "<<tp.size()<<endl;for(j=0;j<tp.size();++j)cout <<tp[j].FI<<" "<<tp[j].SE<<endl;
		for(j=0;j<tp.size();++j)
		{
			if(j==0||!(In(nr,tp[j].FI,tp[j].SE)))
				nr=tp[j].FI,++con;
		}
		ans=min(ans,con);
	}
	printf("%d\n",ans);
	return 0;
}
accuracy: 1
time_ms: 870
memory_kb: 4020
final_rank: 6

code_snippet: #include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define input freopen("/Users/peteryuanpan/data.txt","r",stdin)

const double eps = 1e-9, pi = acos(-1.0);
int sgn(double x){
    if(abs(x) < eps) return 0;
    else return x > 0 ? 1 : -1;
}

#define N 10010
int n;
struct Maze{
    int x1, y1;
    int x2, y2;
}ma[N];

struct Seg{
    double l, r;
}seg[N << 1], seg1[N << 1];
bool cmp1(const Seg a, const Seg b){
    if(sgn(a.r - b.r) != 0) return sgn(a.r - b.r) < 0;
    else return sgn(a.l - b.l) < 0;
}

double getangle(int x1, int y1){
    double a = atan2(y1, x1);
    if(sgn(a) < 0) a += 2 * pi;
    return a;
}

int solve(Seg *seg, int fr, int to){
    int ans = 0;
    for(int i = fr, j = fr; i <= to;){
        for(; j <= to && sgn(seg[j].l - seg[i].r) <= 0; j++);
        ans++;
        i = j;
    }
    return ans;
}

int main(){
    //input;
    while(scanf("%d",&n) == 1){
        for(int i = 1; i <= n; i++){
            scanf("%d%d%d%d",&ma[i].x1, &ma[i].y1, &ma[i].x2, &ma[i].y2);
        }
        for(int i = 1; i <= n; i++){
            double rad[10];
            rad[1] = getangle(ma[i].x1, ma[i].y1);
            rad[2] = getangle(ma[i].x1, ma[i].y2);
            rad[3] = getangle(ma[i].x2, ma[i].y1);
            rad[4] = getangle(ma[i].x2, ma[i].y2);
            sort(rad + 1, rad + 1 + 4);
            double d = 0.0;
            int w1 = 1, w2 = 2;
            for(int i1 = 1; i1 <= 4; i1++){
                for(int i2 = i1 + 1; i2 <= 4; i2++){
                    double d1 = abs(rad[i1] - rad[i2]);
                    d1 = min(d1, 2 * pi - d1);
                    if(sgn(d1 - d) > 0){
                        d = d1;
                        w1 = i1, w2 = i2;
                    }
                }
            }
            double a1 = rad[w1], a2 = rad[w2];
            if(sgn(a1 - a2) > 0) swap(a1, a2);
            if(sgn((a2 - a1) - d) != 0) swap(a1, a2);
            if(sgn(a1 - a2) > 0) a2 += 2 * pi;
            seg[i].l = a1, seg[i].r = a2;
        }
        
        sort(seg + 1, seg + 1 + n, cmp1);
        for(int i = n + 1; i <= 2 * n; i++){
            if(sgn(seg[i - n].r - 2 * pi) < 0 && sgn(seg[i - n].l - 2 * pi) < 0){
                seg[i].l = seg[i - n].l + 2 * pi;
                seg[i].r = seg[i - n].r + 2 * pi;
            }
            else{
                seg[i].l = seg[i - n].l;
                seg[i].r = seg[i - n].r;
            }
            
            seg[i].l = seg[i - n].l + 2 * pi;
            seg[i].r = seg[i - n].r + 2 * pi;
        }
        int ans = n;
        for(int i = 1; i <= n; i++){
            for(int j = i; j <= i + n - 1; j++) seg1[j] = seg[j];
            sort(seg1 + i, seg1 + i + n, cmp1);
            int ans1 = solve(seg1, i, i + n - 1);
            ans = min(ans, ans1);
        }
        printf("%d\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 4088
final_rank: 3

code_snippet: //#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))

using namespace std;

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

double sqr(double x){return x*x;}
int sign(double x){return (x>eps)-(x<-eps);}
int sign(int x){return x/abs(x);}

struct Point{
    int x,y;
    Point(){}
    Point(int x,int y):x(x),y(y){}
    void input(){
        scanf("%d%d",&x,&y);
    }
}p[2222][4];

struct Event{
    double l,r;
    Event(){}
    Event(double l,double r):l(l),r(r){}
    bool friend operator<(const Event &a,const Event &b){
        return a.r<b.r;
    }
}eve[2222],res[2222];

int mult(Point a,Point b,Point c){
    return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}

int n;

bool cmp(Event a,Event b){
    return sign(a.l-a.r-b.l+b.r)<0;
}

bool vis[2222<<2];

int main(){
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++){
            p[i][0].input();p[i][2].input();
            p[i][1]=Point(p[i][2].x,p[i][0].y);
            p[i][3]=Point(p[i][0].x,p[i][2].y);
        }
        for(int i=0;i<n;i++){
            if(p[i][0].x>=0&&p[i][0].y>=0){
                eve[i]=Event(atan2(p[i][3].y+0.0,p[i][3].x+0.0),atan2(p[i][1].y+0.0,p[i][1].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].x>=0&&p[i][2].y<=0){
                eve[i]=Event(atan2(p[i][2].y+0.0,p[i][2].x+0.0),atan2(p[i][0].y+0.0,p[i][0].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].x>=0&&p[i][0].y<0&&p[i][2].y>0){
                eve[i]=Event(atan2(p[i][3].y+0.0,p[i][3].x+0.0),atan2(p[i][0].y+0.0,p[i][0].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][2].x<=0&&p[i][2].y<=0){
                eve[i]=Event(atan2(p[i][1].y+0.0,p[i][1].x+0.0),atan2(p[i][3].y+0.0,p[i][3].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].x<0&&p[i][2].x>0&&p[i][2].y<=0){
                eve[i]=Event(atan2(p[i][2].y+0.0,p[i][2].x+0.0),atan2(p[i][3].y+0.0,p[i][3].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][2].x<=0&&p[i][0].y>=0){
                eve[i]=Event(atan2(p[i][0].y+0.0,p[i][0].x+0.0),atan2(p[i][2].y+0.0,p[i][2].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][2].x<=0&&p[i][0].y<0&&p[i][2].y>0){
                eve[i]=Event(atan2(p[i][1].y+0.0,p[i][1].x+0.0),atan2(p[i][2].y+0.0,p[i][2].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].y>=0&&p[i][0].x<0&&p[i][2].x>0){
                eve[i]=Event(atan2(p[i][0].y+0.0,p[i][0].x+0.0),atan2(p[i][1].y+0.0,p[i][1].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }
        }
        sort(eve,eve+n,cmp);
        int m=0;
        for(int i=0;i<n;i++){
            bool ok=1;
            for(int j=0;j<i;j++){
                if(sign(eve[i].l-eve[j].l)>=0&&sign(eve[i].r-eve[j].r)<=0){
                    ok=0;break;
                }
            }
            if(ok) res[m++]=eve[i];
        }
        sort(res,res+m);
        for(int i=0;i<m;i++) res[m+i]=Event(res[i].l+2.0*pi,res[i].r+2.0*pi);
        for(int i=0;i<m*2;i++)  swap(res[i].l,res[i].r);
        int ans=200000;
        memset(vis,0,sizeof(vis));
        for(int i = 0; i < m; i ++)
        {
            int cnt = 0; double R = -1000;
            for(int j = 0; j < m; j ++)
            {
                if(res[i + j].l > R)
                {
                    cnt ++;
                    R = res[i + j].r;
                }
            }
            ans = min(ans, cnt);
        }
        for(int i = 0; i < m; i ++)
        {
            int cnt = 0; double L = 1000;
            for(int j = m - 1; j >= 0; j --)
            {
                if(res[i + j].r < L)
                {
                    cnt ++;
                    L = res[i + j].l;
                }
            }
            ans = min(ans, cnt);
        }
        printf("%d\n", ans);
    }
    return 0;
}
accuracy: 0.5769230769230769
time_ms: 10
memory_kb: 4056
final_rank: 9

code_snippet: //#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))

using namespace std;

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

double sqr(double x){return x*x;}
int sign(double x){return (x>eps)-(x<-eps);}
int sign(int x){return x/abs(x);}

struct Point{
    int x,y;
    Point(){}
    Point(int x,int y):x(x),y(y){}
    void input(){
        scanf("%d%d",&x,&y);
    }
}p[2222][4];

struct Event{
    double l,r;
    Event(){}
    Event(double l,double r):l(l),r(r){}
    bool friend operator<(const Event &a,const Event &b){
        return a.r<b.r;
    }
}eve[2222],res[2222];

bool check(int i,int j){
    double l1=eve[i].l,r1=eve[i].r;
    double l2=res[j].l,r2=res[j].r;
    if(sign(l1-pi)>=0&&sign(l2-pi)>=0){
        if(sign(l1-l2)>=0&&sign(r1-r2)<=0) return 1;
    }else if(sign(l1-pi)>=0){
        if(sign(l1-2.0*pi-l2)>=0) return 1;
    }else if(sign(l2-pi)>=0){
        return 0;
    }else{
        if(sign(l1-l2)>=0&&sign(r1-r2)<=0) return 1;
    }
    return 0;
}

int n;

bool cmp(Event a,Event b){
    return sign(a.l-a.r-b.l+b.r)<0;
}

bool vis[2222<<2];

int main(){
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++){
            p[i][0].input();p[i][2].input();
            p[i][1]=Point(p[i][2].x,p[i][0].y);
            p[i][3]=Point(p[i][0].x,p[i][2].y);
        }
        for(int i=0;i<n;i++){
            if(p[i][0].x>=0&&p[i][0].y>=0){
                eve[i]=Event(atan2(p[i][3].y+0.0,p[i][3].x+0.0),atan2(p[i][1].y+0.0,p[i][1].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].x>=0&&p[i][2].y<=0){
                eve[i]=Event(atan2(p[i][2].y+0.0,p[i][2].x+0.0),atan2(p[i][0].y+0.0,p[i][0].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].x>=0&&p[i][0].y<0&&p[i][2].y>0){
                eve[i]=Event(atan2(p[i][3].y+0.0,p[i][3].x+0.0),atan2(p[i][0].y+0.0,p[i][0].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][2].x<=0&&p[i][2].y<=0){
                eve[i]=Event(atan2(p[i][1].y+0.0,p[i][1].x+0.0),atan2(p[i][3].y+0.0,p[i][3].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].x<0&&p[i][2].x>0&&p[i][2].y<=0){
                eve[i]=Event(atan2(p[i][2].y+0.0,p[i][2].x+0.0),atan2(p[i][3].y+0.0,p[i][3].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][2].x<=0&&p[i][0].y>=0){
                eve[i]=Event(atan2(p[i][0].y+0.0,p[i][0].x+0.0),atan2(p[i][2].y+0.0,p[i][2].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][2].x<=0&&p[i][0].y<0&&p[i][2].y>0){
                eve[i]=Event(atan2(p[i][1].y+0.0,p[i][1].x+0.0),atan2(p[i][2].y+0.0,p[i][2].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }else if(p[i][0].y>=0&&p[i][0].x<0&&p[i][2].x>0){
                eve[i]=Event(atan2(p[i][0].y+0.0,p[i][0].x+0.0),atan2(p[i][1].y+0.0,p[i][1].x+0.0));
                if(sign(eve[i].l-eve[i].r)<0) eve[i].l+=2.0*pi;
            }
        }
        sort(eve,eve+n,cmp);
        int m=0;
        for(int i=0;i<n;i++){
            bool ok=1;
            for(int j=0;j<m;j++){
                if(check(i,j)){
                    ok=0;break;
                }
            }
            if(ok) res[m++]=eve[i];
        }
        sort(res,res+m);
        for(int i=0;i<m;i++) res[m+i]=Event(res[i].l+2.0*pi,res[i].r+2.0*pi);
        for(int i=0;i<m*2;i++)  swap(res[i].l,res[i].r);
        int ans=200000;
        memset(vis,0,sizeof(vis));
        for(int i = 0; i < m; i ++)
        {
            int cnt = 0; double R = -1000;
            for(int j = 0; j < m; j ++)
            {
                if(sign(res[i + j].l - R) > 0)
                {
                    cnt ++;
                    R = res[i + j].r;
                }
            }
            ans = min(ans, cnt);
        }
        for(int i = 0; i < m; i ++)
        {
            int cnt = 0; double L = 1000;
            for(int j = m - 1; j >= 0; j --)
            {
                if(sign(res[i + j].r - L) < 0)
                {
                    cnt ++;
                    L = res[i + j].l;
                }
            }
            ans = min(ans, cnt);
        }
        printf("%d\n", ans);
    }
    return 0;
}
/*
2
-100 0 -50 50
-49 -49 -1 0
*/
accuracy: 0.5
time_ms: 20
memory_kb: 4056
final_rank: 10

code_snippet: #include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define input freopen("/Users/peteryuanpan/data.txt","r",stdin)

const double eps = 1e-10, pi = acos(-1.0);
int sgn(double x){
    if(abs(x) < eps) return 0;
    else return x > 0 ? 1 : -1;
}

#define N 10010
int n;
struct Maze{
    int x1, y1;
    int x2, y2;
}ma[N];

struct Seg{
    double l, r;
}seg[N << 1];
bool cmp1(const Seg a, const Seg b){
    if(sgn(a.r - b.r) != 0) return sgn(a.r - b.r) < 0;
    else return sgn(a.l - b.l) < 0;
}

double getangle(int x1, int y1){
    double a = atan2(y1, x1);
    if(sgn(a) < 0) a += 2 * pi;
    return a;
}

int solve(int fr, int to){
    int ans = 0;
    for(int i = fr, j = fr; i <= to;){
        for(; j <= to && sgn(seg[j].l - seg[i].r) <= 0; j++);
        ans++;
        i = j;
    }
    return ans;
}

int main(){
    //input;
    while(scanf("%d",&n) == 1){
        for(int i = 1; i <= n; i++){
            scanf("%d%d%d%d",&ma[i].x1, &ma[i].y1, &ma[i].x2, &ma[i].y2);
        }
        for(int i = 1; i <= n; i++){
            double rad[10];
            rad[1] = getangle(ma[i].x1, ma[i].y1);
            rad[2] = getangle(ma[i].x1, ma[i].y2);
            rad[3] = getangle(ma[i].x2, ma[i].y1);
            rad[4] = getangle(ma[i].x2, ma[i].y2);
            double d = 0.0;
            int w1 = 1, w2 = 2;
            for(int i1 = 1; i1 <= 4; i1++){
                for(int i2 = i1 + 1; i2 <= 4; i2++){
                    double d1 = abs(rad[i1] - rad[i2]);
                    d1 = min(d1, 2 * pi - d1);
                    if(sgn(d1 - d) > 0){
                        d = d1;
                        w1 = i1, w2 = i2;
                    }
                }
            }
            double a1 = rad[w1], a2 = rad[w2];
            if(sgn(a1 - a2) > 0) swap(a1, a2);
            if(sgn((a2 - a1) - d) != 0) swap(a1, a2);
            if(sgn(a1 - a2) > 0) a2 += 2 * pi;
            seg[i].l = a1, seg[i].r = a2;
        }
        
        sort(seg + 1, seg + 1 + n, cmp1);
        for(int i = n + 1; i <= 2 * n; i++){
            seg[i].l = seg[i - n].l + 2 * pi;
            seg[i].r = seg[i - n].r + 2 * pi;
        }
        int ans = n;
        for(int i = 1; i <= n; i++){
            int ans1 = solve(i, i + n - 1);
            ans = min(ans, ans1);
        }
        printf("%d\n", ans);
    }
    return 0;
}
accuracy: 0.3076923076923077
time_ms: 10
memory_kb: 4020
final_rank: 13

code_snippet: // AOJ #2472 Mickle's Beam
// 2025.4.17

#include <bits/stdc++.h>
using namespace std;
const double PI = acosl(-1.0);

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<double,double>> iv(n);
    for(int i = 0; i < n; i++){
        double x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        double a[4] = {
            atan2(y1,x1), atan2(y2,x1),
            atan2(y1,x2), atan2(y2,x2)
        };
        for(int k = 0; k < 4; k++) if(a[k] < 0) a[k] += 2*PI;
        sort(a, a+4);
        double maxg = a[0] + 2*PI - a[3];
        int bi = 3;
        for(int k = 0; k < 3; k++){
            double g = a[k+1] - a[k];
            if(g > maxg) maxg = g, bi = k;
        }
        double l, r;
        if(bi == 3) l = a[0], r = a[3];
        else l = a[bi+1], r = a[bi] + 2*PI;
        iv[i] = {l, r};
    }

    int ans = n;
    vector<pair<double,double>> v(n);

    for(int i = 0; i < n; i++){
        double cut = fmod(iv[i].second, 2*PI);
        for(int j = 0; j < n; j++){
            double l2 = iv[j].first - cut;
            double r2 = iv[j].second - cut;
            if(l2 < 0) l2 += 2*PI;
            if(r2 < 0) r2 += 2*PI;
            if(r2 < l2) r2 += 2*PI;
            v[j] = {l2, r2};
        }
        sort(v.begin(), v.end(),
             [](auto &A, auto &B){ return A.second < B.second; });

        double cur = -1e100;
        int cnt = 0;
        for(auto &p : v){
            if(p.first > cur) cnt++, cur = p.second;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 3936
final_rank: 4

code_snippet: // AOJ #2472 Mickle's Beam
// 2025.4.17

#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const ld PI = acosl(-1.0L);
const ld EPS = 1e-15L;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<ld,ld>> iv(n);
    for(int i = 0; i < n; i++){
        ld x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ld a[4] = {
            atan2l(y1,x1), atan2l(y2,x1),
            atan2l(y1,x2), atan2l(y2,x2)
        };
        for(int k = 0; k < 4; k++) if(a[k] < 0) a[k] += 2*PI;
        sort(a, a+4);
        ld maxg = a[0] + 2*PI - a[3];
        int bi = 3;
        for(int k = 0; k < 3; k++){
            ld g = a[k+1] - a[k];
            if(g > maxg) maxg = g, bi = k;
        }
        ld l, r;
        if(bi == 3) l = a[0], r = a[3];
        else l = a[bi+1], r = a[bi] + 2*PI;
        iv[i] = {l, r};
    }

    int ans = n;
    vector<pair<ld,ld>> v(n);

    for(int i = 0; i < n; i++){
        ld cut = fmodl(iv[i].second, 2*PI);
        for(int j = 0; j < n; j++){
            ld l2 = iv[j].first - cut;
            ld r2 = iv[j].second - cut;
            if(l2 < 0) l2 += 2*PI;
            if(r2 < 0) r2 += 2*PI;
            if(r2 < l2) r2 += 2*PI;
            v[j] = {l2, r2};
        }
        sort(v.begin(), v.end(),
             [](auto &A, auto &B){ return A.second < B.second; });

        ld cur = -1e100;
        int cnt = 0;
        for(auto &p : v){
            if(p.first > cur){
                cnt++;
                cur = p.second;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 3708
final_rank: 5

code_snippet: #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
const double INF=1e14;
const double eps=1e-8;
const double Pi=acos(-1.0);
int cmp (double A){
	if(fabs(A)<eps)return 0;
	else return A>0?1:-1;
}
bool equal(double A,double B){
	return cmp(A-B)==0;
}
struct Point{
	double x,y;
	Point(double _x=0,double _y=0):x(_x),y(_y){}
	friend Point operator + (const Point &A,const Point &B){return Point(A.x+B.x,A.y+B.y);}
	friend Point operator - (const Point &A,const Point &B){return Point(A.x-B.x,A.y-B.y);}
	friend double operator * (const Point &A,const Point &B){return A.x*B.x+A.y*B.y;}
	friend double operator ^ (const Point &A,const Point &B){return A.x*B.y-A.y*B.x;}
	double ang(){
		return atan2(y,x);
	}
	void read(){
		scanf("%lf%lf",&x,&y);
	}
	void write(){
		printf("%lf %lf\n",x,y);
	}
};
struct Square{
	Point A,B,C,D;
	void read(){
		A.read();C.read();
		B.x=C.x;B.y=A.y;
		D.x=A.x;D.y=C.y;
	}
	void write(){
		cout<<"Print\n";
		A.write();
		B.write();
		C.write();
		D.write();
		cout<<'\n';
	}
}A[3001];
struct area{
	double l,r;
	int Id;
}L[6001];
int n;
bool Check(Square A){
	return cmp(A.A.x)==-1&&cmp(A.C.x)==-1&&cmp(A.A.y)==-1&&(cmp(A.C.y)>=0);
}
bool cmpL (area A,area B){
	return cmp(A.l-B.l)==-1||(equal(A.l,B.l)&&A.r>B.r);
}
bool vis[2001];
int main(){
//	freopen("Aizu2472.in","r",stdin);
//	freopen("Aizu2472.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		A[i].read();
		if(Check(A[i])){
			L[i].r=A[i].B.ang();
			L[i].l=A[i].C.ang()-2*Pi;
			L[i].Id=i;
//			cout<<A[i].B.ang()<<" "<<A[i].C.ang()<<'\n';
			continue;
		}
		L[i].l=INF;
		L[i].r=-INF;
		
		L[i].l=min(L[i].l,A[i].A.ang());
		L[i].r=max(L[i].r,A[i].A.ang());
		
		L[i].l=min(L[i].l,A[i].B.ang());
		L[i].r=max(L[i].r,A[i].B.ang());
		
		L[i].l=min(L[i].l,A[i].C.ang());
		L[i].r=max(L[i].r,A[i].C.ang());
		
		L[i].l=min(L[i].l,A[i].D.ang());
		L[i].r=max(L[i].r,A[i].D.ang());
		
		L[i].Id=i;
	}
	for(int i=1;i<=n;++i){
		L[i+n].l=L[i].l+2*Pi;
		L[i+n].r=L[i].r+2*Pi;
		L[i+n].Id=L[i].Id;
	}
	sort(L+1,L+1+2*n,cmpL);
//	for(int i=1;i<=2*n;++i){
//		cout<<fixed<<setprecision(12)<<L[i].l<<" "<<L[i].r<<" "<<L[i].Id<<'\n';
//	}
	int ans=n+1;
	for(int i=1;i<=n;++i){
		int cost=1;
		double R=L[i].r;
		memset(vis,0,sizeof(vis));
		vis[L[i].Id]=1;
		for(int j=i+1;j<=2*n;++j){
//			if(cmp((L[j].l-L[i].l)-2*Pi)>=0)break;
			if(vis[L[j].Id])continue;
			vis[L[j].Id]=1;
			if(cmp(L[j].l-R)<=0)R=min(R,L[j].r);
			else cost++,R=L[j].r;
//			cout<<L[j].l<<" "<<L[j].r<<'\n';
//			cout<<fixed<<setprecision(10)<<R<<" "<<L[j].l<<'\n';
		}
//		for(int i=1;i<=n;++i){
//			if(!vis[i])cerr<<i<<" ";
//		}
		ans=min(ans,cost);
//		cout<<ans<<" "<<cost<<'\n';
	}
	cout<<ans<<'\n';
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3880
final_rank: 2

code_snippet: #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
const double INF=1e14;
const double eps=1e-14;
const double Pi=acos(-1.0);
int cmp (double A){
	if(fabs(A)<eps)return 0;
	else return A>0?1:-1;
}
bool equal(double A,double B){
	return cmp(A-B)==0;
}
struct Point{
	double x,y;
	Point(double _x=0,double _y=0):x(_x),y(_y){}
	friend Point operator + (const Point &A,const Point &B){return Point(A.x+B.x,A.y+B.y);}
	friend Point operator - (const Point &A,const Point &B){return Point(A.x-B.x,A.y-B.y);}
	friend double operator * (const Point &A,const Point &B){return A.x*B.x+A.y*B.y;}
	friend double operator ^ (const Point &A,const Point &B){return A.x*B.y-A.y*B.x;}
	double ang(){
		return atan2(y,x);
	}
	void read(){
		scanf("%lf%lf",&x,&y);
	}
	void write(){
		printf("%lf %lf\n",x,y);
	}
};
struct Square{
	Point A,B,C,D;
	void read(){
		A.read();C.read();
		B.x=C.x;B.y=A.y;
		D.x=A.x;D.y=C.y;
	}
	void write(){
		cout<<"Print\n";
		A.write();
		B.write();
		C.write();
		D.write();
		cout<<'\n';
	}
}A[3001];
struct area{
	double l,r;
}L[6001];
int n;
bool Check(Square A){
	return cmp(A.A.x)==-1&&cmp(A.C.x)==-1&&cmp(A.A.y)==-1&&(cmp(A.C.y)>=0);
}
bool cmpL (area A,area B){
	return cmp(A.l-B.l)==-1||(equal(A.l,B.l)&&A.r>B.r);
}
int main(){
//	freopen("Aizu2472.in","r",stdin);
//	freopen("Aizu2472.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		A[i].read();
		if(Check(A[i])){
			L[i].r=A[i].B.ang();
			L[i].l=A[i].C.ang()-2*Pi;
//			cout<<A[i].B.ang()<<" "<<A[i].C.ang()<<'\n';
			continue;
		}
		L[i].l=INF;
		L[i].r=-INF;
		
		L[i].l=min(L[i].l,A[i].A.ang());
		L[i].r=max(L[i].r,A[i].A.ang());
		
		L[i].l=min(L[i].l,A[i].B.ang());
		L[i].r=max(L[i].r,A[i].B.ang());
		
		L[i].l=min(L[i].l,A[i].C.ang());
		L[i].r=max(L[i].r,A[i].C.ang());
		
		L[i].l=min(L[i].l,A[i].D.ang());
		L[i].r=max(L[i].r,A[i].D.ang());
	}
	for(int i=1;i<=n;++i){
		L[i+n].l=L[i].l+2*Pi;
		L[i+n].r=L[i].r+2*Pi;
	}
	sort(L+1,L+1+2*n,cmpL);
//	for(int i=1;i<=2*n;++i){
//		cout<<fixed<<setprecision(12)<<L[i].l<<" "<<L[i].r<<'\n';
//	}
	int ans=n+1;
	for(int i=1;i<=n;++i){
		int cost=1;
		double R=L[i].r;
		for(int j=i+1;j<=i+n-1;++j){
//			if(cmp((L[j].l-L[i].l)-2*Pi)>=0)break;
			if(cmp(L[j].l-R)<=0)R=min(R,L[j].r);
			else cost++,R=L[j].r;
//			cout<<fixed<<setprecision(10)<<R<<" "<<L[j].l-L[i].l<<'\n';
		}
		ans=min(ans,cost);
//		cout<<ans<<" ";
	}
	cout<<ans<<'\n';
	return 0;
}
accuracy: 0.25
time_ms: 10
memory_kb: 3796
final_rank: 14

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
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;
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
}

bool revcomp(const pair<double, double> &a, const pair<double, double> &b){
    return !EQ(a.second, b.second)? a.second<b.second: a.first<b.first;
}

int main(){
    int n;
    cin >> n;
    //ビームで破壊できる区間
    vector<pair<double, double> > range(n);
    for(int i=0; i<n; i++){
        int xs,ys,xt,yt;
        cin >> xs >> ys >> xt >> yt;
        VP sq(4);
        sq[0] = P(xs, ys);
        sq[1] = P(xt, ys);
        sq[2] = P(xt, yt);
        sq[3] = P(xs, yt);
        for(int j=0; j<4; j++){
            bool fs=true, sc=true;
            for(int k=0; k<4; k++){
                double cr = cross(sq[j], sq[k]);
                if(cr > EPS) sc = false;
                if(cr < -EPS) fs = false;
            }
            if(fs) range[i].first = arg(sq[j]);
            if(sc) range[i].second = arg(sq[j]);
        }
        if(range[i].first > range[i].second){
            range[i].first -= 2*PI;
        }
    }
    sort(range.begin(), range.end(), revcomp);

    //円環スケジューリング(最小点カバー)
    int ans = 1e9;
    vector<double> plist;
    plist.push_back(range[0].second);
    for(int i=0; i<n; i++){
        vector<pair<double, double> > tmp = range;
        for(int j=0; j<i; j++){
            if(tmp[j].second +EPS < tmp[i].second){
                tmp[j].first += 2*PI;
                tmp[j].second += 2*PI;
            }
        }
        sort(tmp.begin(), tmp.end(), revcomp);
        int count = 1;
        double now = tmp[0].second;
        for(int j=0; j<n; j++){
            if(tmp[j].first > now +EPS){
                now = tmp[j].second;
                count++;
                plist.push_back(now);
            }
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 36204
final_rank: 7

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
const double EPS = 1e-10;
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;
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
}

bool revcomp(const pair<double, double> &a, const pair<double, double> &b){
    return !EQ(a.second, b.second)? a.second<b.second: a.first<b.first;
}

int main(){
    int n;
    cin >> n;
    //ビームで破壊できる区間
    vector<pair<double, double> > range(n);
    for(int i=0; i<n; i++){
        int xs,ys,xt,yt;
        cin >> xs >> ys >> xt >> yt;
        VP sq(4);
        sq[0] = P(xs, ys);
        sq[1] = P(xt, ys);
        sq[2] = P(xt, yt);
        sq[3] = P(xs, yt);
        for(int j=0; j<4; j++){
            bool fs=true, sc=true;
            for(int k=0; k<4; k++){
                double cr = cross(sq[j], sq[k]);
                if(cr > EPS) sc=false;
                if(cr < -EPS) fs=false;
            }
            if(fs) range[i].first = arg(sq[j]);
            if(sc) range[i].second = arg(sq[j]);
        }
        if(range[i].first > range[i].second){
            range[i].first -= 2*PI;
        }
    }
    sort(range.begin(), range.end(), revcomp);

    //円環スケジューリング(最小点カバー)
    int ans = 1e9;
    for(int i=0; i<n; i++){
        vector<pair<double, double> > tmp = range;
        for(int j=0; j<i; j++){
            if(tmp[j].first +EPS < tmp[i].first){
                tmp[j].first += 2*PI;
                tmp[j].second += 2*PI;
            }
        }
        sort(tmp.begin(), tmp.end());
        int count = 1;
        double now = tmp[0].second;
        for(int j=1; j<n; j++){
            if(tmp[j].first > now +EPS){
                now = tmp[j].second;
                count++;
            }
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 0.019230769230769232
time_ms: 80
memory_kb: 3392
final_rank: 16

code_snippet: #include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i<=(b);++i)
typedef long long LL;
typedef long double LD;
inline int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const int MAXN=200005;
const double INF=1e20,eps=1e-8,PI=3.1415926535897932384626433832;
int n,m;
struct P{
	double x,y;
	P(double v=0,double u=0):x(v),y(u){}
	P operator +(const P &E)const{ return P(x+E.x,y+E.y); }
	P operator -(const P &E)const{ return P(x-E.x,y-E.y); }
	P operator *(const double &z)const{ return P(x*z,y*z); }
	P operator /(const double &z)const{ return P(x/z,y/z); }
	inline double len(){ return sqrt(x*x+y*y); }
	double operator *(const P &E)const{ return x*E.x+y*E.y; }
}A[MAXN],B[MAXN];
inline int sgn(double x){ if (fabs(x)<=eps) return 0; return x>eps?1:-1; }
inline double cross(P a,P b){ return a.x*b.y-a.y*b.x; }
inline double deg(P p){ double tmp=atan2(p.y,p.x); return tmp<0?tmp+PI*2:tmp; }
inline double dist(P a,P b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); }
inline P rot(P p,double a){ return P(cos(a)*p.x-sin(a)*p.y,sin(a)*p.x+cos(a)*p.y); }
int main(){
	int i,j,k;
	n=read();
	FOR(i,1,n) {
		double x1,y1,x2,y2;
		x1=read(); y1=read(); x2=read(); y2=read();
		P p(x1,y1),q(x1,y2),l(x2,y1),r(x2,y2);
		A[i]=B[i]=p;
		if (sgn(cross(q,A[i]))>=0) A[i]=q;
		if (sgn(cross(l,A[i]))>=0) A[i]=l;
		if (sgn(cross(r,A[i]))>=0) A[i]=r;
		if (sgn(cross(B[i],q))>=0) B[i]=q;
		if (sgn(cross(B[i],l))>=0) B[i]=l;
		if (sgn(cross(B[i],r))>=0) B[i]=r;
	}
	FOR(i,1,n-1)
		FOR(j,i+1,n)
		if (deg(A[i])>deg(A[j])+eps||deg(A[i])==deg(A[j])&&deg(B[i])>deg(B[j])) swap(A[i],A[j]),swap(B[i],B[j]);
	FOR(i,n+1,n+n) A[i]=A[i-n],B[i]=B[i-n];
	int ans=n,tmp;
	FOR(i,1,n) {
		for (j=i,tmp=0;j<=i+n;j=k+1) {
			for (k=j;k<i+n&&sgn(cross(A[k+1],B[j]))>=0;++k);
			tmp++;
		}
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
	
	return 0;
}

/*
4
2 -1 3 1
-1 2 1 3
-3 -1 -2 1
-1 -3 1 -2
2
1 0 2 1
3 -1 4 0
*/
accuracy: 0.019230769230769232
time_ms: 180
memory_kb: 9512
final_rank: 17

code_snippet: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#define maxn 2005
using namespace std;
const double pi = acos(0.0l)*2.0l;
int n;
struct Data{
		double ang;
		int id;
		int kind;
		Data(double ang,int id,int kind):ang(ang),id(id),kind(kind){}
		friend bool operator < (const Data &a, const Data &b){
				if(a.ang == b.ang) return a.kind > b.kind;
				return a.ang < b.ang;
		}
};
vector <Data> vec;
int vis[maxn];
vector <int> now;
void work(int whe){
		int ans_all = 0x3f3f3f3f;
		for(int i = 0; i < whe; i++)if(vec[i].kind == 1){
				memset(vis,0,sizeof(vis));
				int ans = 0;
				for(int j = 0; i+j < vec.size(); j++)if(!vis[vec[i+j].id]){
						if(vec[i+j].kind == 1) now.push_back(vec[i+j].id);
						if(vec[i+j].kind == -1){
								for(int k = 0; k < now.size(); k++) {
										vis[now[k]] = 1;
								}
								ans++;
								now.clear();
						}
				}
				ans_all = min(ans,ans_all);
		}
		cout << ans_all << endl;
}
double ang[4];
int main(){
		//freopen("main.in","r",stdin);
		cin >> n;
		for(int i = 1; i <= n; i++){
				int x1,y1,x2,y2;
				cin >> x1 >> y1 >> x2 >> y2;
				if(x2 < 0 && y1 < 0 && y2 >= 0){
						vec.push_back(Data(atan2(y2,x2),i,1));
						vec.push_back(Data(atan2(y1,x2)+2*pi,i,-1));
				}
				else {
						ang[0] = atan2(y1,x1);
						ang[1] = atan2(y2,x1);
						ang[2] = atan2(y1,x2);
						ang[3] = atan2(y2,x2);
						sort(ang,ang+4);
						vec.push_back(Data(ang[0],i,1));
						vec.push_back(Data(ang[3],i,-1));
				}
		}
		int tmp = vec.size();
		for(int i = 0; i < tmp; i++){
				vec.push_back(Data(vec[i].ang+2*pi,vec[i].id,vec[i].kind));
		}
		sort(vec.begin(),vec.end());
		work(tmp);
		return 0;
}
accuracy: 0.6153846153846154
time_ms: 30
memory_kb: 3580
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
struct angle
{
    double minx,maxx;
}p[4010];
bool cmp(angle a,angle b)
{
    if (fabs(a.maxx-b.maxx)<1e-6) return a.minx<b.minx;
    return a.maxx<b.maxx;
}
double ang(double y,double x)
{
    double ans;
    ans=atan2(y,x);
    if (ans<0) ans+=2*pi;
    return ans;
}
int main()
{
    double x1,x2,y1,y2,light;
    int n,i,j,ans,res;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        if (x2>0 && y2>=0 && y1<0)
        {
            p[i].minx=ang(y1,x1);
            p[i].maxx=ang(y2,x1)+2*pi;
        }
        else
        {
            p[i].minx=min(min(ang(y1,x1),ang(y2,x1)),min(ang(y1,x2),ang(y2,x2)));
            p[i].maxx=max(max(ang(y1,x1),ang(y2,x1)),max(ang(y1,x2),ang(y2,x2)));
        }
    }
    for(i=1;i<=n;i++)
    {
        p[i+n].minx=p[i].minx+2*pi;
        p[i+n].maxx=p[i].maxx+2*pi;
    }
    sort(p+1,p+1+2*n,cmp);ans=0x3f3f3f3f;
    for(i=1;i<=n;i++)
    {
        light=-1;res=0;
        for(j=i;j<=i+n-1;j++)
        {
            if (light<p[j].minx)
            {
                res++;
                light=p[j].maxx;
            }
            else continue;
        }
        if (res<ans) ans=res;
    }
    cout<<ans<<endl;
    return 0;
}
accuracy: 0.3076923076923077
time_ms: 10
memory_kb: 3652
final_rank: 12

code_snippet: #include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
const int inf=2000000000;
struct haha
{
     int x1,y1,x2,y2;
     double max_angle,min_angle;
}a[4010];
double angle(int y,int x)
{
    double ang;
    ang=atan2(y,x);
    if (ang<0) ang+=2*pi;
    return ang;
}
double min4(double a,double b,double c,double d)
{
    double min0;
    min0=a;
    if (b<min0) min0=b;
    if (c<min0) min0=c;
    if (d<min0) min0=d;
    return min0;
}
double max4(double a,double b,double c,double d)
{
    double max0;
    max0=a;
    if (b>max0) max0=b;
    if (c>max0) max0=c;
    if (d>max0) max0=d;
    return max0;
}
bool cmp(haha a,haha b)
{
    if (fabs(a.min_angle-b.min_angle)<1e-6) return a.max_angle<b.max_angle;
    else return a.min_angle<b.min_angle;
}
int main()
{
     int n,i,j,cot;
     double answer,light;
     cin>>n;
     for(i=0;i<n;i++)
     {
           cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
           if (a[i].x1>0 && a[i].y1<0 && a[i].y2>=0)
           {
               a[i].min_angle=angle(a[i].y1,a[i].x1);
               a[i].max_angle=angle(a[i].y2,a[i].x1)+2*pi;
           }
           else
           {
                a[i].min_angle=min4(angle(a[i].y1,a[i].x1),angle(a[i].y2,a[i].x1),angle(a[i].y1,a[i].x2),angle(a[i].y2,a[i].x2));
                a[i].max_angle=max4(angle(a[i].y1,a[i].x1),angle(a[i].y2,a[i].x1),angle(a[i].y1,a[i].x2),angle(a[i].y2,a[i].x2));
           }
     }
     sort(a,a+n,cmp);answer=inf;
     for(i=0;i<n;i++)
     {
         a[i+n].min_angle=a[i].min_angle+2*pi;
         a[i+n].max_angle=a[i].max_angle+2*pi;
     }
     for(i=0;i<n;i++)
     {
          light=-inf;cot=0;
          for(j=0;j<n;j++)
            if (light<a[i+j].min_angle)
            {
                light=a[i+j].max_angle;
                cot++;
            }
            else light=min(light,a[i+j].max_angle);
        if (cot<answer) answer=cot;
     }
     cout<<answer<<endl;
     return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1464
final_rank: 1

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

using namespace std;

const double eps = 1e-6;
const double pi = acos(-1);
pair<double, double> deg[2000];
double tmp[4];

int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
	{
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		tmp[0] = atan2(y1, x1);
		tmp[1] = atan2(y1, x2) - pi * 2;
		while (fabs(tmp[1] - tmp[0]) > pi) tmp[1] += pi * 2;
		tmp[2] = atan2(y2, x1) - pi * 2;
		while (fabs(tmp[2] - tmp[0]) > pi) tmp[2] += pi * 2;
		tmp[3] = atan2(y2, x2) - pi * 2;
		while (fabs(tmp[3] - tmp[0]) > pi) tmp[3] += pi * 2;
		sort(tmp, tmp + 4);
		deg[i].second = tmp[0] - pi * 2;
		deg[i].first = tmp[3] - pi * 2;
		while (deg[i].second < 0) deg[i].second += pi * 2;
		while (deg[i].first < deg[i].second) deg[i].first += pi * 2;
	}
	sort(deg, deg + N);
	int ans = N;
	for (int i = 0; i < N; ++i)
	{
		int cnt = 0;
		double last = -1e9;
		for (int j = i; j < i + N && cnt < ans; ++j)
		{
			if (deg[j % N].second + j / N * 2 * pi > last + eps)
			{
				cnt++;
				last = deg[j % N].first + j / N * 2 * pi;
			}
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}
accuracy: 0.038461538461538464
time_ms: 10
memory_kb: 2996
final_rank: 15

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

using namespace std;

const double eps = 1e-12;
const double pi = acos(-1);
pair<double, double> deg[2000];
double tmp[4];

int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
	{
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		tmp[0] = atan2(y1, x1);
		tmp[1] = atan2(y1, x2) - pi * 2;
		while (fabs(tmp[1] - tmp[0]) > pi) tmp[1] += pi * 2;
		tmp[2] = atan2(y2, x1) - pi * 2;
		while (fabs(tmp[2] - tmp[0]) > pi) tmp[2] += pi * 2;
		tmp[3] = atan2(y2, x2) - pi * 2;
		while (fabs(tmp[3] - tmp[0]) > pi) tmp[3] += pi * 2;
		sort(tmp, tmp + 4);
		deg[i].second = tmp[0] - pi * 2;
		deg[i].first = tmp[3] - pi * 2;
		while (deg[i].second < 0) deg[i].second += pi * 2;
		while (deg[i].first < deg[i].second) deg[i].first += pi * 2;
	}
	sort(deg, deg + N);
	int ans = N;
	for (int i = 0; i < N; ++i)
	{
		int cnt = 0;
		double last = -1e9;
		for (int j = i; j < i + N && cnt < ans; ++j)
		{
			if (deg[j % N].second + j / N * 2 * pi > last + eps)
			{
				cnt++;
				last = deg[j % N].first + j / N * 2 * pi;
			}
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}
accuracy: 0.3076923076923077
time_ms: 20
memory_kb: 2988
final_rank: 11