wojiaocbj

Untitled

May 19th, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. /*
  2.  Author: 曹北健(37509)
  3.  Result: MLE    Submission_id: 4471349
  4.  Created at: Fri May 20 2022 10:34:09 GMT+0800 (China Standard Time)
  5.  Problem: 5840  Time: 314   Memory: 205780
  6. */
  7.  
  8. /*
  9.  Author: 曹北健(37509)
  10.  Result: MLE    Submission_id: 4471346
  11.  Created at: Fri May 20 2022 10:32:43 GMT+0800 (China Standard Time)
  12.  Problem: 5840  Time: 362   Memory: 206080
  13. */
  14.  
  15. /*
  16.  Author: 曹北健
  17.  Result: AC Submission_id: 3487299
  18.  Created at: Fri May 14 2021 09:02:29 GMT+0800 (China Standard Time)
  19.  Problem_id: 4425   Time: 744   Memory: 204800
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <ctype.h>
  25. #include <math.h>
  26. #include <string.h>
  27. #include <time.h>
  28. #include <assert.h>
  29. #pragma warning(disable:4996)
  30. typedef long long LL;
  31. typedef struct _data{
  32.     int age,index;
  33.     char name[1024];
  34. }data,*pdata;
  35. data arr[200010] = {0};
  36. pdata pt[200010] = {0};
  37. int compare(const void *p,const void *q){
  38.     pdata a = *(pdata *)p,b = *(pdata *)q;
  39.     if(a->age == b->age)return a->index - b->index;
  40.     else return a->age - b->age;
  41. }
  42. int main(){
  43. #ifdef _DEBUG
  44.     freopen("input.txt","r",stdin);
  45. #ifdef OFILE
  46.     freopen("test2.txt","w",stdout);
  47. #endif 
  48. #endif
  49.     int n,m,t,i;
  50.     scanf("%d%d",&n,&m);
  51.     for(i = 0;i < n;i++){
  52.         scanf("%d%s",&arr[i].age,arr[i].name);
  53.         arr[i].index = i;pt[i] = arr + i;
  54.     }
  55.     qsort(pt,n,sizeof(pdata),compare);
  56.     while(m--){
  57.         scanf("%d",&t);
  58.         printf("%d %s\n",pt[t - 1]->age,pt[t - 1]->name);
  59.     }
  60. #ifdef _DEBUG
  61.     freopen("CON","r",stdin);
  62. #ifdef OFILE
  63.     freopen("CON","w",stdout);
  64. #endif
  65.     system("pause");
  66. #endif
  67.     return 0;
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment