码迷,mamicode.com
首页 > 其他好文 > 详细

1100 final standings

时间:2018-09-22 12:52:31      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:problem   ret   end   HERE   output   objects   asp   col   ace   

http://acm.timus.ru/problem.aspx?space=1&num=1100 link to the problem

make a fast stable sorting algorithm. 

what is sort in c, quick sort.

what is a stable sort?

a sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input array to be sorted.

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

struct node
{
  int id;
  int m;
}a[150005];

bool temp(node a, node b)
{
  return a.m > b.m;
}

int main(){
  //freopen("input.txt","r",stdin);
  int N = 0;
  cin >> N;
  for(int i = 0; i<N; i++)
    cin >>a[i].id >> a[i].m;
  stable_sort(a, a+N, temp);//using stable sort here instead od quick sort
  for(int i = 0; i<N; i++)
    cout << a[i].id <<" "<< a[i].m << endl;
  return 0;
}

 

1100 final standings

标签:problem   ret   end   HERE   output   objects   asp   col   ace   

原文地址:https://www.cnblogs.com/stiles/p/timus1100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!