1 条题解

  • 0
    @ 2021-6-15 1:39:39

    C++ :

    
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    inline int read(){char ch=getchar(),w=1;int x=0;while(ch<'0'||ch>'9'){if(ch=='-')w=-1;
    ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return w*x;}
    inline void wr(int x){if(x<0)putchar('-'),x=-x;if(x>9)wr(x/10);putchar(x%10+'0');}
    inline void wrln(int x){wr(x);putchar('\n');}
     
     
    struct T{
    	int k,s;
    	bool operator<(const T &x)const{
    		return s>x.s||s==x.s&&k<x.k;
    	}
    }f[5100];
    bool cmp(int x,int y){
    	return f[x].k<f[y].k;
    }
    int main(){
    	int n,m;
    	n=read();m=read();m=m*1.5;
    	for(int i=1;i<=n;i++)
    		f[i].k=read(),f[i].s=read();
    	sort(f+1,f+1+n);
    	while(f[m+1].s==f[m].s)m++;
    	sort(f+1,f+1+m);
    	wr(f[m].s);putchar(' ');wrln(m);
    	for(int i=1;i<=m;i++)wr(f[i].k),putchar(' '),wrln(f[i].s);
    	return 0;
    }
    
    

    Pascal :

    var
      num,sco:array[1..5010]of longint;
      n,m,i,j,st,ans:longint;
    
    procedure swap(var i,j:longint);
    var
      t:longint;
    begin
      t:=i;i:=j;j:=t;
    end;
    
    procedure qsort(l,r:longint);
    var
      i,j,m1,m2:longint;
    begin
      i:=l;
      j:=r;
      m1:=sco[(i+j) div 2];
      m2:=num[(i+j) div 2];
      repeat
        while (sco[i]>m1)or(sco[i]=m1)and(num[i]<m2) do inc(i);
        while (sco[j]<m1)or(sco[j]=m1)and(num[j]>m2) do dec(j);
        if i<=j then
        begin
          swap(sco[i],sco[j]);
          swap(num[i],num[j]);
          inc(i);
          dec(j);
        end;
      until i>j;
      if l<j then qsort(l,j);
      if i<r then qsort(i,r);
    end;
    
    begin
      //assign(input,'score.in');reset(input);
      //assign(output,'score.out');rewrite(output);
      readln(n,m);
      for i:=1 to n do
        readln(num[i],sco[i]);
      qsort(1,n);
      st:=sco[trunc(m*1.5)];
      for i:=1 to n do
        if sco[i]>=st then
          inc(ans);
      writeln(st,' ',ans);
      for i:=1 to ans do
        writeln(num[i],' ',sco[i]);
      //close(input);close(output);
    end.
    
    
    • 1

    信息

    ID
    269
    时间
    1000ms
    内存
    125MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者