4 条题解

  • 3
    @ 2023-10-12 21:31:39
    #include <bits/stdc++.h>
    using namespace std;
    struct F
    {
        int id,score;
    }a[5005];
    bool cmp(F x,F y)//简单排序
    {   
        if(x.score != y.score)
        {
            return x.score > y.score;
        }
        else
        {
            return x.id < y.id;
        }
    }
    int main()
    {
        int n,m;
        cin >> n >> m;
        int q = floor(m * 1.5);
        for(int i = 1; i <= n; i++)
        {
            cin >> a[i].id >> a[i].score;
        }
        sort(a + 1,a + n + 1,cmp);
        int op = a[q].score,num = 0;
        for(int i = 1; i <= n; i++)
        {
            if(a[i].score >= op)//统计人数
            {
                num++;
            }
        }
        cout << op << " " << num << endl;
        for(int i = 1; i <= num; i++)
        {
            cout << a[i].id << " " << a[i].score << endl;
        }
        return 0;
    }
    
    • 1
      @ 2022-12-27 9:15:26

      唯一需要注意的就是成绩相同并不是并列名次,只是和面试成绩线相同的时候才算并列哈。

      上代码!

      #include <bits/stdc++.h>
      using namespace std;
      int n, m, t, k[5005], s[5005], r[5005];
      bool cmp(int a, int b)
      {
          if (s[a] != s[b])
              return s[a] > s[b];
          return k[a] < k[b];
      }
      int main()
      {
          cin >> n >> m;
          for (int i = 1; i <= n; ++i)
          {
              cin >> k[i] >> s[i];
              r[i] = i;
          }
          t = m = m * 1.5;
          sort(r + 1, r + n + 1, cmp);
          while (s[r[t]] >= s[r[m]])
              t++;
          cout << s[r[m]] << " " << t - 1 << endl;
          for (int i = 1; i < t; ++i)
              cout << k[r[i]] << " " << s[r[i]] << endl;
          return 0;
      } //代码已AC
      
      • 0
        @ 2022-10-20 22:17:35

        题解

        学过我的题解的都知道,这是一个结构体排序,然后计算一下分数线,统计一下人数,输出,完成。

        #include <bits/stdc++.h>
        using namespace std;
        int n, m, pass, s = 0;
        struct mark
        {
            int a, h;
        };
        mark mn[5000];
        bool cmp(mark x, mark y)
        {
            if (x.a > y.a) return true;
        	if (x.a == y.a && x.h < y.h) return 1;
            return 0;  
        }
        int main()
        {
            scanf("%d%d", &n, &m);
            for (int i = 1; i <= n; i++)
                scanf("%d%d", &mn[i].h, &mn[i].a);
            sort(mn + 1, mn + n + 1, cmp);
        	pass = mn[m * 3 / 2].a;
            for (int i = 1; i <= n; i++)
            	if (mn[i].a >= pass) s++;
        	printf("%d %d\n", pass, s);
        	for (int i = 1; i <= s; i++)
                printf("%d %d\n", mn[i].h, mn[i].a);
            return 0;
        }
        

        简单的没话说。

        ACAC CodeCode

        #include <bits/stdc++.h>
        using namespace std;
        int n, m, pass, s = 0;
        struct mark
        {
            int a, h;
        };
        mark mn[5000];
        bool cmp(mark x, mark y)
        {
            if (x.a > y.a) return true;
        	if (x.a == y.a && x.h < y.h) return 1;
            return 0;  
        }
        int main()
        {
            scanf("%d%d", &n, &m);
            for (int i = 1; i <= n; i++)
                scanf("%d%d", &mn[i].h, &mn[i].a);
            sort(mn + 1, mn + n + 1, cmp);
        	pass = mn[m * 3 / 2].a;
            for (int i = 1; i <= n; i++)
            	if (mn[i].a >= pass) s++;
        	printf("%d %d\n", pass, s);
        	for (int i = 1; i <= s; i++)
                printf("%d %d\n", mn[i].h, mn[i].a);
            return 0;
        }
        
        • 0
          @ 2022-8-28 18:48:47
          #include<iostream>
          #include<string.h>
          #include<algorithm>
          #include<math.h>
          using namespace std;
          struct node{//定义结构体 
          	int num;
          	int grade;
          };
          bool cmp(node a,node b){//编写cmp函数,实现成绩从大到小排序,成绩相同,编号从小到大 
          	if(a.grade!=b.grade)
          	return a.grade>b.grade;
          	else
          	return a.num<b.num;
          }
          int n,m;
          node a[5000]; 
          int mian(){
              cin>>n>>m;
              int i,temp,j;
              for(i=0;i<n;i++){
              	cin>>a[i].num>>a[i].grade;
          	}
          	sort(a,a+n,cmp);//排序 
          	temp=m*1.5;
          	cout<<a[temp-1].grade<<" ";
          	for(i=temp;a[i].grade==a[temp-1].grade;i++);//精髓for循环 
          	
          		cout<<i<<endl;
          		for(j=0;j<i;j++){
          			cout<<a[j].num<<" "<<a[j].grade<<endl;
          		}
          	
              
              return -1;
          }
          

          PS:请勿复制此题解,其中有小错误,建议自己理解

          • 1

          [普及][NOIP2009 普及组] 分数线划定

          信息

          ID
          1623
          时间
          1000ms
          内存
          256MiB
          难度
          4
          标签
          递交数
          140
          已通过
          69
          上传者