26 条题解
- 
  1dusk LV 8 @ 2017-10-27 19:24:22 #include<stdio.h> 
 int ren[5005],fen[5005];
 int main()
 {
 freopen("score.in","r",stdin);
 freopen("score.out","w",stdout);
 int n,m,i,j,t;
 scanf("%d %d",&n,&m);
 for(i=1;i<=n;i++)
 scanf("%d %d",&ren[i],&fen[i]);
 for(i=1;i<=n-1;i++) //冒泡排序
 for(j=1;j<=n-i;j++)
 if(fen[j]<fen[j+1]||
 fen[j]==fen[j+1]&&ren[j]>ren[j+1])
 { // 分数和报名号一起交换
 t=fen[j];fen[j]=fen[j+1];fen[j+1]=t;
 t=ren[j];ren[j]=ren[j+1];ren[j+1]=t;
 }
 m=m+m/2; //计算人数
 while(fen[m]==fen[m+1]) m++;//找出分数一样
 printf("%d %d\n",fen[m],m);
 for(i=1;i<=m;i++)
 printf("%d %d\n",ren[i],fen[i]);
 return 0;
 }
- 
  1@ 2017-10-20 21:59:22#include<iostream> 
 #include<algorithm>
 #include<cmath>
 using namespace std;
 struct ss{
 int k,s;
 }s1[5001];
 int cmp1(ss x,ss y)
 {
 if(x.s==y.s) return x.k<y.k;
 else return x.s>y.s;
 }
 int main()
 {
 int n,m,a,f,sum=0;
 cin>>n>>m;
 for(int i=1;i<=n;i++)
 {
 cin>>s1[i].k>>s1[i].s;
 }
 a=floor(m*1.5);
 sort(s1+1,s1+1+n,cmp1);
 sort(s1+1,s1+n+1,cmp1);
 s1[a].s;
 cout<<s1[a].s<<" ";
 for(int i=1;i<=n;i++)
 {
 if(s1[i].s>=s1[a].s)
 sum++;
 }
 cout<<sum<<endl;
 for(int i=1;i<=sum;i++)
 {
 cout<<s1[i].k<<" "<<s1[i].s<<endl;
 }
 return 0;
 }
- 
  0@ 2018-02-06 10:13:45#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; int n, m, ans; struct A { int num; int s; }arr[10010]; bool cmp(A a,A b){ if(a.s==b.s) return a.num < b.num; else return a.s > b.s; } int main(){ scanf("%d%d",&n,&m); int num,sum; for(int i=0; i<n; i++) { scanf("%d%d",&num,&sum); arr[i].num=num; arr[i].s=sum; } sort(arr,arr+n,cmp); int r = ((double) m * 1.5); int brr=arr[r-1].s; for(int i=0; i<n; i++) { if(arr[i].s >= brr) ans++; } printf("%d %d\n",brr,ans); for(int i=0; i<ans; i++) printf("%d %d\n",arr[i].num,arr[i].s); return 0; }
- 
  0@ 2017-04-15 12:42:28#include<bits/stdc++.h> 
 using namespace std;
 struct xs
 {
 int id,score;
 }a[5005];
 bool cmp(xs a,xs b)
 {
 if(a.score==b.score) return a.id<b.id;
 else return a.score>b.score;
 }
 int main()
 {
 int n,m,i;
 cin>>n>>m;
 m=1.5*m;
 for(i=1;i<=n;++i)
 cin>>a[i].id>>a[i].score;
 sort(a+1,a+n+1,cmp);
 while(a[m].score==a[m+1].score) ++m;
 cout<<a[m].score<<" "<<m<<endl;
 for(i=1;i<=m;++i) cout<<a[i].id<<" "<<a[i].score<<endl;
 return 0**;
- 
  0@ 2016-09-06 12:14:11评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 596 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 596 KiB, score = 10 测试数据 #2: Accepted, time = 15 ms, mem = 596 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 596 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 596 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 596 KiB, score = 10 测试数据 #6: Accepted, time = 0 ms, mem = 596 KiB, score = 10 测试数据 #7: Accepted, time = 15 ms, mem = 596 KiB, score = 10 测试数据 #8: Accepted, time = 0 ms, mem = 600 KiB, score = 10 测试数据 #9: Accepted, time = 0 ms, mem = 596 KiB, score = 10 Accepted, time = 30 ms, mem = 600 KiB, score = 100 代码 #include <algorithm> #include <iostream> #include <cstdio> using namespace std; struct Score { int num,score; }peole[5001]; inline bool cmp(Score x,Score y) { if (x.score != y.score) return x.score > y.score; return x.num < y.num; } int main() { ios :: sync_with_stdio(false); //ifstream cin("score.in",ios :: in); //ofstream cout("score.out",ios :: out); int n,m; cin >> n >> m; m = (int)(m*1.5); for (int i = 1;i <= n;i++) cin >> peole[i].num >> peole[i].score; sort(peole+1,peole+n+1,cmp); int cnt = m; while (peole[cnt].score == peole[m].score) cnt++; cout << peole[m].score << ' ' << --cnt << '\n'; for (int i = 1;i <= cnt;i++) cout << peole[i].num << ' ' << peole[i].score << '\n'; return 0; }
- 
  0@ 2016-05-21 19:11:29这个很好理解的,只是基础的模拟+排序。 
 var
 n,m,num,i,j,t:longint;
 a,b:array[1..100000] of longint;
 begin
 readln(n,m);
 for i:=1 to n do begin
 readln(a[i],b[i]);
 end;
 for i:=1 to n-1 do
 for j:=i+1 to n do begin
 if b[i]<b[j] then begin
 t:=b[i]; b[i]:=b[j]; b[j]:=t;
 t:=a[i]; a[i]:=a[j]; a[j]:=t;
 end;
 end;
 m:=trunc(m*1.5);
 num:=0;
 for i:=m to n do begin
 if b[m]=b[i] then inc(num);
 end;
 m:=m+num-1;
 writeln(b[m],' ',m);
 for i:=1 to m-1 do
 for j:=i+1 to m do begin
 if b[i]=b[j] then begin
 if a[i]>a[j] then begin
 t:=a[i]; a[i]:=a[j]; a[j]:=t;
 end;
 end;
 end;
 for i:=1 to m do begin
 writeln(a[i],' ',b[i]);
 end;
 end.
- 
  0@ 2015-08-26 13:50:19var a,b,c,d,n,m:longint; 
 e:array[1..5000,1..2] of integer;procedure f(var a,b:integer); 
 var c:integer;
 begin
 c:=a;
 a:=b;
 b:=c;
 end;begin 
 read(n,m);
 for a:=1 to n do read(e[a,1],e[a,2]);for a:=1 to n do 
 for b:=1 to n-1 do
 begin
 if (e[b,2]<e[b+1,2])or((e[b,2]=e[b+1,2])and(e[b,1]>e[b+1,1])) then
 begin
 f(e[b,1],e[b+1,1]);
 f(e[b,2],e[b+1,2]);
 end;
 end;
 m:=trunc(m*1.5);
 for a:=m+1 to n do
 if e[m,2]=e[a,2] then inc(m) else break;writeln(e[m,2],' ',m); 
 for a:=1 to m do
 writeln(e[a,1],' ',e[a,2]);
 end.
- 
  0@ 2015-04-08 18:12:21没必要快排。主要就是5000^2的时间复杂度。冒泡简单又方便。大不了可以标记优化下就行了。 首先是按2个条件排序,1是分数 2是号次(分数相同的考虑) 然后算出M,但是这个M不一定就是M*1.5,我们需要看看有没有同分。你需要看跟M名分数一样的有几个,M就+多少,这个很简单,自己去想怎么做吧。 然后输出第M名的分数和M。再从1到M依次出成绩即可。嗯,水题。快排反而可能会搞乱。 ###block code 
 program P18132;
 var m,n,i,j:longint;
 data:array[1..5000,1..2] of longint;
 procedure change(var a,b:longint);
 var t:longint;
 begin
 t:=a; a:=b; b:=t;
 end;begin //main 
 read(n); read(m);
 for i:=1 to n do begin read(data[i,1]); read(data[i,2]); end; //读入for i:=1 to n do //冒泡不谢 
 for j:=1 to n-1 do
 begin
 if data[j,2]<data[j+1,2] then
 begin
 change(data[j,1],data[j+1,1]); change(data[j,2],data[j+1,2]);
 end;if (data[j,1]>data[j+1,1]) and (data[j,2]=data[j+1,2]) then 
 begin
 change(data[j,1],data[j+1,1]); change(data[j,2],data[j+1,2]);
 end;
 end;m:=trunc(m*1.5); //算M for i:=m+1 to n do //修正M 
 if data[m,2]=data[i,2] then
 inc(m)
 else
 break;writeln(data[m,2],' ',m); //以下输出 for i:=1 to m do 
 writeln(data[i,1],' ',data[i,2]);end. 
- 
  0@ 2014-09-04 13:08:35#include <stdio.h> 
 #include <iostream>
 #include <algorithm>
 using namespace std;
 struct arr {
 int x, y;
 } a[5005];
 bool cmp (arr x, arr y) {
 if (x.y == y.y) return x.x < y.x;
 return x.y > y.y;
 }
 int main()
 {
 int m,n,ans=0,num=0;
 scanf("%d%d",&n,&m);
 for (int i=1;i<=n;i++)
 cin>>a[i].x>>a[i].y;
 sort (a+1, a + n + 1, cmp);
 ans=int(1.5*m);
 cout<<a[ans].y<<" ";
 for(int i=1;i<=n;i++){
 if(a[i].y>=a[ans].y)
 num ++;
 }
 cout<<num<<endl;
 for(int i=1;i<=num;i++)
 //if(a[i].y>= a[ans].y)
 cout<<a[i].x<<" "<<a[i].y<<endl;
 return 0;
 }
- 
  0@ 2013-12-08 14:07:20评测结果 
 编译成功测试数据 #0: Accepted, time = 0 ms, mem = 824 KiB, score = 10 
 测试数据 #1: Accepted, time = 0 ms, mem = 824 KiB, score = 10
 测试数据 #2: Accepted, time = 0 ms, mem = 824 KiB, score = 10
 测试数据 #3: Accepted, time = 0 ms, mem = 824 KiB, score = 10
 测试数据 #4: Accepted, time = 0 ms, mem = 824 KiB, score = 10
 测试数据 #5: Accepted, time = 0 ms, mem = 824 KiB, score = 10
 测试数据 #6: Accepted, time = 15 ms, mem = 820 KiB, score = 10
 测试数据 #7: Accepted, time = 62 ms, mem = 820 KiB, score = 10
 测试数据 #8: Accepted, time = 140 ms, mem = 824 KiB, score = 10
 测试数据 #9: Accepted, time = 0 ms, mem = 820 KiB, score = 10
 Accepted, time = 217 ms, mem = 824 KiB, score = 100代码var 
 id,score:array[1..10000]of longint;
 n,m,i,j,upscore,temp:longint;
 begin
 readln(n,m);
 for i:=1 to n do
 readln(id[i],score[i]);
 for i:=1 to n do
 for j:=i to n do
 if (score[i]<score[j])or((score[i]=score[j])and(id[i]>id[j])) then
 begin
 temp:=score[i]; score[i]:=score[j]; score[j]:=temp;
 temp:=id[i]; id[i]:=id[j]; id[j]:=temp;
 end;
 m:=m+m div 2;
 upscore:=score[m];
 while score[m]>=upscore do inc(m);
 writeln(upscore,' ',m-1);
 for i:=1 to n do
 if score[i]>=upscore then
 writeln(id[i],' ',score[i]);
 end.
- 
  0@ 2013-11-28 15:03:58测试数据 #0: Accepted, time = 0 ms, mem = 480 KiB, score = 10 
 测试数据 #1: Accepted, time = 0 ms, mem = 480 KiB, score = 10
 测试数据 #2: Accepted, time = 0 ms, mem = 476 KiB, score = 10
 测试数据 #3: Accepted, time = 0 ms, mem = 484 KiB, score = 10
 测试数据 #4: Accepted, time = 0 ms, mem = 476 KiB, score = 10
 测试数据 #5: Accepted, time = 0 ms, mem = 476 KiB, score = 10
 测试数据 #6: Accepted, time = 0 ms, mem = 484 KiB, score = 10
 测试数据 #7: Accepted, time = 0 ms, mem = 484 KiB, score = 10
 测试数据 #8: Accepted, time = 15 ms, mem = 480 KiB, score = 10
 测试数据 #9: Accepted, time = 0 ms, mem = 476 KiB, score = 10
 Accepted, time = 15 ms, mem = 484 KiB, score = 100#include<cstdio> 
 #include<cmath>
 #include<stdlib.h>
 struct aa{
 int hao,fen;
 }ren[5000];
 int cmp(const void *a ,const void b)
 {
 if(((aa*)a).fen>((aa)b).fen) return -1;
 if(((aa)a).fen<((aa)b).fen) return 1;
 if(((aa)a).hao<((aa)b).hao) return -1;
 }
 int main()
 {
 int i,n,m,num,line;
 scanf("%d%d",&n,&m);
 num=1.5*m;
 for(i=0;i<n;i++) scanf("%d%d",&ren[i].hao,&ren[i].fen);
 qsort(ren,n,sizeof(ren[0]),cmp);
 line=ren[num-1].fen;
 for(i=num;i<n;i++)
 {
 if(ren[i].fen>=line)
 num++;
 else
 break;
 }
 printf("%d %d\n",line,num);
 for(i=0;i<num;i++)
 printf("%d %d\n",ren[i].hao,ren[i].fen);
 return 0;
 }用快排很快就出来了,快排的比较函数得重新写一下,很水的题 
- 
  0@ 2013-11-09 11:57:36根据分数和序号求出每个数据的优先度再排序即可。AC代码如下 
 type
 sbsb=record
 hao:integer;
 fen:byte;
 root:longint;
 end;
 var
 a:array[1..5000]of sbsb;
 c:sbsb;
 d,i,j,n,m:integer;begin 
 readln(n,m);
 for i:=1 to n do readln(a[i].hao,a[i].fen);
 for i:=1 to n do a[i].root:=a[i].fen*10000+(10000-a[i].hao);
 for i:=1 to n-1 do
 for j:=i+1 to n do
 if a[i].root<a[j].root then begin
 c:=a[i];a[i]:=a[j];a[j]:=c;
 end;
 d:=trunc(m*1.5);
 while a[d+1].fen=a[d].fen do inc(d);
 writeln(a[d].fen,' ',d);
 for i:=1 to d do writeln(a[i].hao,' ',a[i].fen);
 end.
- 
  0@ 2013-11-04 20:57:03额...交错程序了 
- 
  0@ 2013-10-28 01:26:38不用快排。。。累死我也。。。 #include<stdio.h> 
 #include<windows.h>
 int main()
 {
 int n,m,k,s,tot,total,nowp,tempk,temps,totally,left,right;
 long i,temp;
 short r[1010000]={0};
 long rr[5001];scanf("%d%d",&n,&m); for (i=1;i<=n;i++) 
 { scanf("%d%d",&k,&s);r[k+s*10000]=1;}tot=0; 
 nowp=0;
 total=0;
 totally=0;
 for (i=1009999;i>=11000;i--)
 if (r[i]==1)
 { tempk=i%10000;temps=i/10000;
 if (nowp==0)
 {
 if (tot+1<m*3/2)
 {tot++;
 total++;
 rr[total]=i;
 }
 else
 {
 nowp=temps;
 tot++;
 total++;
 rr[total]=i;
 }
 }else
 if (nowp==temps)
 {
 total++;
 rr[total]=i;
 }
 else break;
 }left=1;right=1; 
 while (right+1<=total)
 if (rr[left]/10000==rr[right+1]/10000)
 right++; else
 {
 for (i=1;i<=(right-left+1)/2;i++)
 {temp=rr[left+i-1];
 rr[left+i-1]=rr[right-i+1];
 rr[right-i+1]=temp;
 }
 left=right=right+1;
 }
 for (i=1;i<=(right-left+1)/2;i++)
 {temp=rr[left+i-1];
 rr[left+i-1]=rr[right-i+1];
 rr[right-i+1]=temp;
 }
 left=right=right+1;
 printf("%d %d\n",rr[total]/10000,total);
 for (i=1;i<=total;i++) printf("%d %d\n",rr[i]%10000,rr[i]/10000);
 system("pause");
 return 0;
 }
- 
  0@ 2013-09-06 18:54:26var n,m,m2,i,j,t1,ans,t2:longint; 
 m1:real;
 fs:array[1..5000,1..2] of longint;
 begin
 ans:=0;
 readln(n,m);
 for i:=1 to n do readln(fs[i,1],fs[i,2]);
 for i:=1 to n do
 for j:=i+1 to n do
 begin
 if fs[i,2]<fs[j,2] then begin t1:=fs[i,1]; t2:=fs[i,2]; fs[i,1]:=fs[j,1]; fs[i,2]:=fs[j,2]; fs[j,1]:=t1; fs[j,2]:=t2; end;
 if (fs[i,2]=fs[j,2]) and (fs[i,1]>fs[j,1]) then begin t1:=fs[i,1]; t2:=fs[i,2]; fs[i,1]:=fs[j,1]; fs[i,2]:=fs[j,2]; fs[j,1]:=t1; fs[j,2]:=t2; end;
 end;
 m:=trunc(m*1.5);
 for i:=1 to n do if fs[i,2]>=fs[m,2] then inc(ans);
 writeln(fs[m,2],' ',ans);
 for i:=1 to ans do writeln(fs[i,1],' ',fs[i,2]);
 end.
- 
  0@ 2013-08-28 12:07:53var 
 a,b,c:array[1..5000]of integer;
 i,j,k,m,n,l:integer;procedure qsort(l,r: integer); 
 var i,j,x: longint; y:integer;
 begin
 i:=l;j:=r;
 x:=a[(l+r) div 2];
 repeat
 while a[i]<x do inc(i);
 while x<a[j] do dec(j);
 if i<=j then
 begin
 y:=a[i]; a[i]:=a[j]; a[j]:=y;
 y:=b[i]; b[i]:=b[j]; b[j]:=y;
 inc(i);
 dec(j);
 end;
 until i>j;
 if l<j then qsort(l,j);
 if i<r then qsort(i,r);
 end;procedure qsort2(l,r: integer); 
 var i,j,x: longint; y:integer;
 begin
 i:=l;j:=r;
 x:=b[(l+r) div 2];
 repeat
 while b[i]<x do inc(i);
 while x<b[j] do dec(j);
 if i<=j then
 begin
 y:=b[i]; b[i]:=b[j]; b[j]:=y;
 inc(i);
 dec(j);
 end;
 until i>j;
 if l<j then qsort2(l,j);
 if i<r then qsort2(i,r);
 end;begin 
 readln(n,m);
 m:=trunc(m*1.5);
 l:=m;
 //writeln(m);
 for i:=1 to n do readln(b[i],a[i]);
 qsort(1,n);
 for i:=1 to n do c[n-i+1]:=a[i];
 for i:=1 to n do a[i]:=c[i];
 for i:=1 to n do c[n-i+1]:=b[i];
 for i:=1 to n do b[i]:=c[i];
 write(a[m],' ');
 for i:=m+1 to n do
 if (a[i]=a[m]) then inc(l);
 writeln(l);
 //for i:=1 to n do writeln(a[i],' ',b[i]);
 for i:=1 to l do
 begin
 j:=i;
 while a[i]=a[j+1] do inc(j);
 qsort2(i,j);
 end;
 for i:=1 to l do
 writeln(b[i],' ',a[i]);
 end.
- 
  0@ 2013-08-28 12:07:47我竟然是第一个发表题解的 
- 
  -1@ 2021-07-09 14:49:40#include<bits/stdc++.h> using namespace std; int N,M,n,m; struct Node{ int k,s; }P[10001]; bool Compare(Node a,Node b){ if(a.s==b.s)return a.k<b.k; return a.s>b.s; } int main(){ scanf("%d %d",&N,&M); for(int i=1;i<=N;i++){ scanf("%d %d",&P[i].k,&P[i].s); } sort(P+1,P+N+1,Compare); m=floor(M*1.5); for(int i=1;;i++){ if(P[i].s>=P[m].s)++n; else break; } printf("%d %d\n",P[m].s,n); for(int i=1;;i++){ if(P[i].s>=P[m].s)printf("%d %d\n",P[i].k,P[i].s); else break; } return 0; }
- 
  -1@ 2017-10-20 21:21:00不想说些什么了...... 
 #include<iostream>
 #include<algorithm>
 #include<cmath>
 using namespace std;
 struct p{
 int k,s;
 }a[5005];
 bool cmp(p a,p b){
 if(a.s==b.s) return a.k<b.k;
 else return a.s>b.s;
 }
 int main()
 {
 int n,m,x,num=0;
 cin>>n>>m;
 x=floor(m*1.5);
 for(int i=1;i<=n;i++)
 cin>>a[i].k>>a[i].s;
 sort(a+1,a+1+n,cmp);
 for(int i=1;i<=n;i++)
 {
 if(a[i].s==a[x].s||a[i].s>a[x].s) num++;
 }
 cout<<a[num].s<<" "<<num<<endl;
 for(int i=1;i<=num;i++)
 cout<<a[i].k<<" "<<a[i].s<<endl;
 return 0;
 }
- 
  -1@ 2017-08-22 02:52:11so water #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> using namespace std; int main() { int n,i,j,a[5500],m,c[5500],h,a2,x,y,z; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) { scanf("%d %d",&c[i],&a[i]); } for(i=1;i<=n-1;i++) { for(j=1;j<=n-i;j++) { if(a[j]<a[j+1]) { a2=a[j]; a[j]=a[j+1]; a[j+1]=a2; a2=c[j]; c[j]=c[j+1]; c[j+1]=a2; } else if(a[j]==a[j+1]) { if(c[j]>c[j+1]) { a2=c[j]; c[j]=c[j+1]; c[j+1]=a2; } } } } h=m*1.5; for(i=h;a[i]==a[i+1];i++) { h++; } printf("%d %d\n",a[h],h); for(i=1;i<=h;i++) { printf("%d %d\n",c[i],a[i]); } return 0; }
信息
- ID
- 1813
- 难度
- 4
- 分类
- (无)
- 标签
- 递交数
- 1564
- 已通过
- 694
- 通过率
- 44%
- 被复制
- 17
- 上传者