Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水过,如果排序不大会,开四个数组就可以了

Posted by finalhope at 2013-03-28 17:45:21 on Problem 2007
#include <stdio.h>
#include <algorithm>
using namespace std;
struct point
{
	int x;
	int y;
	point (){}
	point (int a,int b){x=a;y=b;}
	double slope()
	{
		return 	y*1.00/x;
	}
	void print()
	{
		printf("(%d,%d)\n",x,y);
	}
};

bool cmp(point a,point b)
{
	return a.slope()<b.slope();	
}

point p1[50];
point p2[50];
point p3[50];
point p4[50];

int main()
{
	int a,b;
	int size;
	scanf("%d%d",&a,&b);
	int n1=0,n2=0,n3=0,n4=0;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		if(a>0&&b>0)p1[n1++]=point(a,b);
		if(a<0&&b>0)p2[n2++]=point(a,b);
		if(a<0&&b<0)p3[n3++]=point(a,b);
		if(a>0&&b<0)p4[n4++]=point(a,b);
	}
	
	sort(p1,p1+n1,cmp);
	sort(p2,p2+n2,cmp);
	sort(p3,p3+n3,cmp);
	sort(p4,p4+n4,cmp);
	printf("(0,0)\n");
	if(n1==0)
	{
		for(int i=0;i<n2;i++)p2[i].print();
		for(int i=0;i<n3;i++)p3[i].print();
		for(int i=0;i<n4;i++)p4[i].print();
		
	}else if(n2==0)
	{
		for(int i=0;i<n3;i++)p3[i].print();
		for(int i=0;i<n4;i++)p4[i].print();
		for(int i=0;i<n1;i++)p1[i].print();
	}else if(n3==0)
	{
		for(int i=0;i<n4;i++)p4[i].print();
		for(int i=0;i<n1;i++)p1[i].print();
		for(int i=0;i<n2;i++)p2[i].print();
	}else
	{
		for(int i=0;i<n1;i++)p1[i].print();
		for(int i=0;i<n2;i++)p2[i].print();
		for(int i=0;i<n3;i++)p3[i].print();
	}
	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator