题目链接

以前对快排不熟,不会搞结构体快排,今天正巧比赛里有这个题。。。秒杀了。。还是研究树形DP吧。。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 struct node
 5 {
 6     int x;
 7     int y;
 8     int id;
 9 }p[150001];
10 int cmp(const void *a,const void *b)
11 {
12     struct node *c = (struct node *)a;
13     struct node *d = (struct node *)b;
14     if(c->y!=d->y) return d->y-c->y;
15     else return c->id-d->id;
16 }
17 int main()
18 {
19     int n,i,sv,ev;
20     scanf("%d",&n);
21     for(i = 0;i <= n-1;i ++)
22     {
23         scanf("%d%d",&sv,&ev);
24         p[i].x = sv;
25         p[i].y = ev;
26         p[i].id = i;
27     }
28     qsort(p,n,sizeof(p[0]),cmp);
29     for(i = 0;i <= n-1;i ++)
30     {
31         printf("%d %d\n",p[i].x,p[i].y);
32     }
33     return 0;
34 }

 

相关文章:

  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2021-06-05
  • 2021-06-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-11
  • 2021-08-05
  • 2021-08-29
  • 2022-01-26
  • 2021-06-04
  • 2021-12-14
相关资源
相似解决方案