3 5.0 4.0 3.1 0.1 2.0 2.0 -1
3.1 0.1 5.0 4.0 2.0 2.0
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<time.h>
typedef long long LL;
using namespace std;
/*struct node
{
double x,y;
}a[101];
int cmp(double a,double b)
{
return a>b;
}
*/
int main()
{
int t;double ans[101];
double a[101];
double b[101];
while(cin>>t)
{
if(t<0)break;
memset(ans,0,sizeof(ans));
for(int i=0;i<t;i++)
{
cin>>a[i]>>b[i];
ans[i]=a[i]/b[i];
}
for(int i=0;i<t-1;i++){
for(int j=i+1;j<t;j++)
{
if(ans[j]>ans[i])
{
swap(a[i],a[j]);
swap(b[i],b[j]);
swap(ans[i],ans[j]);
}
}
}
if(t>0)printf("%.1f %.1f",a[0],b[0]);
for(int i=1;i<t;i++)
{
printf(" %.1f %.1f",a[i],b[i]);
}
cout<<endl;
/*int maxn=ans[0];
int mark=0;
for(int j=1;j<t;j++)
{
if(maxn>ans[j])
{
maxn=ans[j];
mark=j;
}
}
printf()*/
}
return 0;
}#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<time.h>
typedef long long LL;
using namespace std;
typedef struct NODE
{
float res;
float x;
float y;
}dot;
int cmp(const void *a,const void *b)
{
return (*(dot *)b).res>(*(dot *)a).res?1:-1;
}
int main(void)
{
int n,i,k;
dot a[100];
float d,t;
while(scanf("%d",&n)&&(n>0))
{
for(i=0;i<n;i++)
{
scanf("%f%f",&a[i].x,&a[i].y);
a[i].res=a[i].x/a[i].y;
}
qsort(a,n,sizeof(a[0]),cmp);
for(i=0;i<n-1;i++)
{
printf("%.1f %.1f ",a[i].x,a[i].y);
}
printf("%.1f %.1f\n",a[n-1].x,a[n-1].y);
}
return 0;
}HDU 1785 You Are All Excellent(斜率排序+结构体)
原文:http://blog.csdn.net/liangzhaoyang1/article/details/51335911