CCPC2018-湖南全国邀请赛-重现赛F题sorting

Sorting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Bobo has  n tuples  (a1,b1,c1),(a2,b2,c2),,(an,bn,cn).
He would like to find the lexicographically smallest permutation  p1,p2,,pn of  1,2,,n such that for  i{2,3,,n} it holds that
api1+bpi1api1+bpi1+cpi1api+bpiapi+bpi+cpi.

 

Input
The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains an integer  n.
The  i-th of the following  n lines contains  3 integers  ai bi and  ci.
 

Output
For each test case, print  n integers  p1,p2,,pn seperated by spaces.
DO NOT print trailing spaces.

## Constraint

1n103
1ai,bi,ci2×109
* The sum of  n does not exceed  104.
 

Sample Input
 
 
2 1 1 1 1 1 2 2 1 1 2 1 1 1 3 1 3 1 2 2 1 3 1 1
 

Sample Output
 
 
2 1 1 2

1 2 3

题解:相邻两组的a[i-1],b[i-1],c[i-1]和a[i],b[i],c[i]满足上面的公式,如果相等的话就不交换两组的顺序。

代码:一开始我把大于和小于两种情况一起考虑,在排序的时候把相等的交换了位置,然后一直在wa。。。,果然还是太菜了。。

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

const int MAX=10010;

struct node{
    long double x,y,z;
}a[MAX];
int b[MAX];

int main(){
    int n;
    while(cin >> n){
        for(int i = 1;i<=n;++i){
            cin >> a[i].x >> a[i].y >> a[i].z;
            b[i] = i;
        }
        for(int i = 1;i<=n;++i){
            for(int j = i+1;j<=n;++j){
                if(a[j].z*(a[i].x+a[i].y)>a[i].z*(a[j].x+a[j].y)){
                    swap(b[i],b[j]);
                    swap(a[i],a[j]); 
                }
                else if(a[j].z*(a[i].x+a[i].y)==a[i].z*(a[j].x+a[j].y) && b[i]>b[j]){
                    swap(b[i],b[j]);
                    swap(a[i],a[j]);
                }
        }
    }
        for(int i = 1;i<=n;++i){
            printf(i==1?"%d":" %d",b[i]);
        }
        cout << endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值