158 条题解
-
-1芙兰朵露•斯卡雷特 LV 8 @ 2016-07-14 17:00:38
# include <cstdio> # include <cmath> # include <cstdlib> # include <cctype> # include <ctime> # include <iostream> # include <cstring> # include <string> # include <algorithm> # include <sstream> //# define MAX 30001 using namespace std; struct student{ int Math,Chinese,English; int num; int score; }; inline bool comparator(const student&s1,const student&s2){ if(s1.score!=s2.score)return s1.score>s2.score; else if(s1.Chinese!=s2.Chinese) return s1.Chinese>s2.Chinese; return s1.num<s2.num; } int main() { //freopen("in.in","r",stdin); //freopen("in.out","w",stdout); int num; cin>>num; int Math,English,Chinese; student*s=new student[num]; for(int i=0;i<num;i++){ cin>>Chinese>>Math>>English; s[i].Chinese=Chinese; s[i].Math=Math; s[i].English=English; s[i].score=Chinese+Math+English; s[i].num=i+1; } sort(s,s+num,comparator); for(int i=0;i<5;i++) cout<<s[i].num<<" "<<s[i].score<<"\n"; delete[]s; return 0; }
-
-12016-06-24 13:06:10@
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 516 KiB, score = 10 测试数据 #6: Accepted, time = 0 ms, mem = 520 KiB, score = 10 测试数据 #7: Accepted, time = 0 ms, mem = 516 KiB, score = 10 测试数据 #8: Accepted, time = 0 ms, mem = 516 KiB, score = 10 测试数据 #9: Accepted, time = 0 ms, mem = 516 KiB, score = 10 Accepted, time = 0 ms, mem = 520 KiB, score = 100 代码 #include <cstdio> #include <algorithm> using std :: sort; struct Stu { int c,m,e; int sum,num; }pupil[301]; bool cmp(Stu x,Stu y) { if (x.sum != y.sum) return x.sum > y.sum; if (x.c != y.c) return x.c > y.c; return x.num < y.num; } int n; int main() { scanf("%d",&n); for (int i = 1;i <= n;i++) { scanf("%d%d%d",&pupil[i].c,&pupil[i].m,&pupil[i].e); pupil[i].sum = pupil[i].c+pupil[i].m+pupil[i].e; pupil[i].num = i; } sort(pupil + 1,pupil + n + 1,cmp); for (int i = 1;i <= 5;i++) printf("%d %d\n",pupil[i].num,pupil[i].sum); return 0; }
-
-12016-06-04 09:09:00@
var
a:array[1..1000] of longint;
i,n,x,num:longint;
begin
fillchar(a,sizeof(a),0);
readln(n);
for i:=1 to n do
begin
read(x);
a[x]:=1;
end;
for i:=1 to 1000 do
if a[i]=1 then num:=num+1;
writeln(num);
for i:=1 to 100 do
if a[i]=1 then write(i,' ');
end. -
-12016-05-21 15:42:44@
type
student=record
num:integer;
ch:0..100;
ma:0..100;
en:0..100;
total:integer;
end;
var a:array[1..300]of student;
i,j,n:integer; empty:student;
begin
readln(n);
for i:=1 to n do
begin
a[i].num:=i;
read(a[i].ch,a[i].ma,a[i].en);
a[i].total:=(a[i].ch+a[i].ma+a[i].en);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if a[i].total<a[j].total then
begin
empty:=a[i];
a[i]:=a[j];
a[j]:=empty;
end;
if (a[i].total=a[j].total)and(a[i].ch<a[j].ch) then
begin
empty:=a[i];
a[i]:=a[j];
a[j]:=empty;
end;
if (a[i].total=a[j].total)and(a[i].ch=a[j].ch)and(a[i].num<a[j].num) then
begin
empty:=a[i];
a[i]:=a[j];
a[j]:=empty;
end;
end;
for i:=1 to 5 do
writeln(a[i].num,' ',a[i].total);
end. -
-12016-05-21 15:18:37@
program money;
type pro=record
ch:0..100;
ma:0..100;
en:0..100;
tot:0..300;
st:0..300;
end;
var
i,j,n:integer;
t:pro;
a:array[0..300] of pro;
b:array[0..300] of integer;
begin
readln(n);
for i:= 1 to n do
begin
with a[i] do
begin
read(ch,ma,en);
tot:=ch+ma+en;
st:=i;
end;
end;
for i:= 1 to n-1 do
for j:= i+1 to n do
begin
if a[i].tot<a[j].tot
then begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
if a[i].tot=a[j].tot
then
begin
if a[i].ch<a[j].ch
then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
end;
end;
for i:= 1 to 5 do
begin
with a[i] do
begin
writeln(st,tot:4);
end;
end;
readln;
end. -
-12016-03-02 15:11:28@
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>using namespace std;
struct qwq{
int sum,chi,num;
}a[305];
int n;int cmp(qwq x,qwq y){
if(x.sum == y.sum && x.chi == y.chi) return x.num < y.num;
if(x.sum == y.sum) return x.chi > y.chi;
return x.sum > y.sum;
}void init(){
scanf("%d",&n);
int tmp2,tmp3;
for(int i = 1;i <= n;i ++){
scanf("%d%d%d",&a[i].chi,&tmp2,&tmp3);
a[i].num = i;
a[i].sum = tmp2 + tmp3 + a[i].chi;
}
}void solve(){
sort(a + 1,a + 1 + n,cmp);
for(int i = 1;i <= 5;i ++){
printf("%d %d\n",a[i].num,a[i].sum);
}
}int main(){
init();
solve();
return 0;
} -
-12016-01-30 16:34:01@
#include<iostream>
using namespace std;
int main()
{
int n,hu,a,b,c,y[301],h[301],z[301];
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a>>b>>c;
y[i]=a;
h[i]=i;
z[i]=a+b+c;
}
for (int i=1;i<=n-1;i++)
for (int j=i+1;j<=n;j++)
if (z[j]>z[i]||(z[j]==z[i]&&y[j]>y[i])||(z[j]==z[i]&&y[j]==y[i]&&h[j]<h[i]))
{
hu=z[i];
z[i]=z[j];
z[j]=hu;
hu=y[i];
y[i]=y[j];
y[j]=hu;
hu=h[i];
h[i]=h[j];
h[j]=hu;
}
for (int i=1;i<=5;i++)
cout<<h[i]<<" "<<z[i]<<endl;
}
水题哈哈哈 -
-12015-10-13 20:29:34@
记录信息
评测状态 Accepted
题目 P1398 奖学金
递交时间 2015-10-13 20:29:19
代码语言 C++
评测机 VijosEx
消耗时间 35 ms
消耗内存 536 KiB
评测时间 2015-10-13 20:29:22
评测结果
编译成功测试数据 #0: Accepted, time = 15 ms, mem = 532 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 532 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 528 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 532 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 536 KiB, score = 10
测试数据 #9: Accepted, time = 5 ms, mem = 532 KiB, score = 10
Accepted, time = 35 ms, mem = 536 KiB, score = 100
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct point {
int a,b,c,pos,sum;
}per[310];
bool cmp(point x,point y)
{
if(x.sum!=y.sum)
return x.sum>y.sum;
if(x.a!=y.a)
return x.a>y.a;
return x.pos<y.pos;
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&per[i].a,&per[i].b,&per[i].c);
per[i].pos=i;
per[i].sum=per[i].a+per[i].b+per[i].c;
}
sort(per+1,per+n+1,cmp);
for(int i=1;i<=5;i++)printf("%d %d\n",per[i].pos,per[i].sum);
return 0;
} -
-12015-09-11 19:16:36@
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = 300 + 10;int sum[MAXN];
struct Stu{
int a, b, c, num;
}s[MAXN];bool cmp(Stu x, Stu y){
if(sum[x.num] != sum[y.num])
return sum[x.num] > sum[y.num];
else if(x.a != y.a)
return x.a > y.a;
else
return x.num < y.num;
}int main()
{
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%d%d%d", &s[i].a, &s[i].b, &s[i].c);
sum[i] = s[i].a + s[i].b + s[i].c;
s[i].num = i;
}
sort(&s[1], &s[1]+n, cmp);
for(int i=1; i<=5; i++)
printf("%d %d\n", s[i].num, sum[s[i].num]);
return 0;
}
注意是学号小的在前。。。。被坑了 -
-12015-08-17 17:31:04@
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct student{
int Chinese;
int math;
int English;
int sum;
int number;
}a[30000];
int comp(const student&a,const student&b)
{
if(a.sum>b.sum)return 1;
if(a.sum<b.sum)return 0;
if(a.Chinese>b.Chinese)return 1;
if(a.Chinese<b.Chinese)return 0;
if(a.number<b.number)return 1;
if(a.number>b.number)return 0;
return 0;
}
int main()
{
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d%d%d",&a[i].Chinese,&a[i].math,&a[i].English);
a[i].sum=a[i].Chinese+a[i].math+a[i].English;
a[i].number=i;
}
sort(a+1,a+n+1,comp);
if(n>5){
n=5;
}
for(i=1;i<=n;i++){
printf("%d",a[i].number);
printf(" ");
printf("%d\n",a[i].sum);
}return 0;
} -
-12015-08-10 16:09:52@
program exam;
var i,j,m,n,k,l:longint;
a,b,c,d,y:array[0..10000] of longint;
procedure qt(l,r:longint);
var i,j,m,p,m1,m2,m3:longint;
begin
i:=l; j:=r;
m:=a[(l+r) div 2];
m2:=y[(l+r) div 2];
m3:=d[(l+r) div 2];
repeat
while (a[i]>m) or ((a[i]=m) and (y[i]>m2)) or ((a[i]=m) and (y[i]=m2) and (d[i]<m3)) do inc(i);
while (a[j]<m) or ((a[j]=m) and (y[j]<m2)) or ((a[j]=m) and (y[j]=m2) and (d[j]>m3)) do dec(j);
if i<=j then
begin
p:=a[i]; a[i]:=a[j]; a[j]:=p;
p:=d[i]; d[i]:=d[j]; d[j]:=p;
p:=y[i]; y[i]:=y[j]; y[j]:=p;
inc(i); dec(j);
end;
until i>j;
if i<r then qt(i,r);
if l<j then qt(l,j);
end;begin
readln(n);
for i:=1 to n do
begin
readln(y[i],b[i],c[i]);
a[i]:=y[i]+b[i]+c[i];
d[i]:=i;
end;
qt(1,n);
for i:=1 to 5 do
writeln(d[i],' ',a[i]);
end. -
-12015-08-04 14:33:20@
无聊排序
-
-12015-05-02 14:53:40@
小练一下排序算法
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define sz 310
#define LL long long
#define for1(v,a,b) for (int v=a;v<=b;v++)
#define for2(v,a,b) for (int v=a;v>=b;v--)
using namespace std;
struct Type{
int ch,sum,pos;
}a[sz];
int n;
int my_comp(const Type &x,const Type &y){
if (x.sum>y.sum) return 1;
if (x.sum<y.sum) return 0;
if (x.ch>y.ch) return 1;
if (x.ch<y.ch) return 0;
if (x.pos<y.pos) return 1;
if (x.pos>y.pos) return 0;
}
int main(){
//freopen("p1.in","r",stdin);
int ma,en;
scanf("%d",&n);
for1(i,1,n){
scanf("%d%d%d",&a[i].ch,&ma,&en);
a[i].sum=a[i].ch+ma+en;
a[i].pos=i;
}
sort(a+1,a+n+1,my_comp);
for1(i,1,5)
printf("%d %d\n",a[i].pos,a[i].sum);
return 0;
} -
-12014-11-02 20:14:07@
var i,j,k,l,m,n,yw,sx,yy:longint; xs:array[1..10000,1..3]of longint;procedure qs(q,h:longint);var i,j,mid1,mid2,mid3:longint; t:array[1..3]of longint;begin i:=q; j:=h; mid1:=xs[(q+h) div 2,1]; mid2:=xs[(q+h)div 2,2]; mid3:=xs[(q+h)div 2,3]; repeat while (xs[i,1]>mid1)or((xs[i,1]=mid1)and(xs[i,2]>mid2)) or((xs[i,1]=mid1)and(xs[i,2]=mid2)and(xs[i,3]<mid3)) do inc(i); while (xs[j,1]<mid1)or((xs[j,1]=mid1)and(xs[j,2]<mid2)) or((xs[j,1]=mid1)and(xs[j,2]=mid2)and(xs[j,3]>mid3)) do dec(j); if i<=j then begin t:=xs[i]; xs[i]:=xs[j]; xs[j]:=t; inc(i);dec(j); end; until i>j; if q<j then qs(q,j); if h>i then qs(i,h);end;begin readln(n); for i:=1 to n do begin read(yw,sx,yy); xs[i,1]:=yw+sx+yy; xs[i,2]:=yw; xs[i,3]:=i; end; qs(1,n); for i:=1 to 5 do writeln(xs[i,3],' ',xs[i,1]); end.
多关键字排序 -
-12014-10-26 11:49:15@
var
yu,shu,wai,yu1,shu1,wai1:array[1..300] of integer; i,j,k,t,s,n:longint; zong,kong,ans:array[1..300] of longint; begin
readln(n);
for i:=1 to n do
begin
read(yu[i],shu[i],wai[i]); yu1[i]:=yu[i]; shu1[i]:=shu[i]; wai1[i]:=wai[i]; readln; end;
for i:=1 to n do
begin
kong[i]:=yu[i]+shu[i]+wai[i]; zong[i]:=kong[i]; end;
for i:=1 to n-1 do
for j:=i+1 to n do begin
if (zong[i]<zong[j]) then begin t:=zong[i];zong[i]:=zong[j];zong[j]:=t; t:=yu1[i];yu1[i]:=yu1[j];yu1[j]:=t; t:=shu1[i];shu1[i]:=shu1[j];shu1[j]:=t; t:=wai1[i];wai1[i]:=wai1[j];wai1[j]:=t; end; end;
for i:=1 to n do
for j:=1 to n do begin if (zong[i]=kong[j]) and (yu1[i]=yu[j]) and (shu1[i]=shu[j]) and (wai1[i]=wai[j]) then ans[i]:=j; end; for i:=1 to 10 do
begin
if (zong[i]=zong[i+1]) and ((yu1[i]<yu1[i+1]) or (ans[i]>ans[i+1])) then begin
t:=zong[i];zong[i]:=zong[i+1];zong[i+1]:=t; t:=yu1[i];yu1[i]:=yu1[i+1];yu1[i+1]:=t; t:=ans[i];ans[i]:=ans[i+1];ans[i+1]:=t; end; end;
for i:=1 to 5 do
begin
writeln(ans[i],' ',zong[i]); end;
end. -
-12014-08-28 23:17:44@
绝妙的算法,在结构体里设一个变量,是总分数*1000000+语文*1000+总人数-学号,然后对它排序,保证了排序的唯一性
#include<iostream>
using namespace std;
struct student
{
int c;
int m;
int e;
long long int sum;
int k;
int num;
}a[305];
int n,t;
int main()
{
student a[305];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].k=a[i].c+a[i].m+a[i].e;
a[i].num=i+1;
a[i].sum=a[i].k*1000000+a[i].c*1000+n-i;
}
for(int i=0;i<n;i++)
for(int j=0;j<n-i-1;j++)
if(a[j].sum<a[j+1].sum)
{
t=a[j].sum;a[j].sum=a[j+1].sum;a[j+1].sum=t;
t=a[j].num;a[j].num=a[j+1].num;a[j+1].num=t;
t=a[j].k;a[j].k=a[j+1].k;a[j+1].k=t;
}
for(int i=0;i<5;i++)
cout<<a[i].num<<" "<<a[i].k<<"\n";
cout<<endl;
//system("pause");
return 0;
} -
-12014-08-08 18:40:02@
var
yu,shu,wai,yu1,shu1,wai1:array[1..300] of integer;
i,j,k,t,s,n:longint;
zong,kong,ans:array[1..300] of longint;
begin
readln(n);
for i:=1 to n do
begin
read(yu[i],shu[i],wai[i]);
yu1[i]:=yu[i];
shu1[i]:=shu[i];
wai1[i]:=wai[i];
readln;
end;
for i:=1 to n do
begin
kong[i]:=yu[i]+shu[i]+wai[i];
zong[i]:=kong[i];
end;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if (zong[i]<zong[j]) then begin
t:=zong[i];zong[i]:=zong[j];zong[j]:=t;
t:=yu1[i];yu1[i]:=yu1[j];yu1[j]:=t;
t:=shu1[i];shu1[i]:=shu1[j];shu1[j]:=t;
t:=wai1[i];wai1[i]:=wai1[j];wai1[j]:=t;
end;
end;
for i:=1 to n do
for j:=1 to n do
begin
if (zong[i]=kong[j]) and (yu1[i]=yu[j]) and (shu1[i]=shu[j]) and (wai1[i]=wai[j]) then ans[i]:=j;
end;
for i:=1 to 10 do
begin
if (zong[i]=zong[i+1]) and ((yu1[i]<yu1[i+1]) or (ans[i]>ans[i+1])) then begin
t:=zong[i];zong[i]:=zong[i+1];zong[i+1]:=t;
t:=yu1[i];yu1[i]:=yu1[i+1];yu1[i+1]:=t;
t:=ans[i];ans[i]:=ans[i+1];ans[i+1]:=t;
end;
end;
for i:=1 to 5 do
begin
writeln(ans[i],' ',zong[i]);
end;
end. -
-12014-08-07 09:11:25@
#include<iostream>
#include<cstdio>
using namespace std;
struct st
{
int xh;
int yw;
int sx;
int yy;
int zf;
};
void jh(int&a,int&b)
{
int t=a;
a=b;
b=t;
}
void aa(st&a,st&b)
{
jh(a.zf,b.zf);
jh(a.yw,b.yw);
jh(a.xh,b.xh);
}
main()
{
int i,j,n;
st a[301];
cin>>n;
for(i=1;i<=n;i++)
{
a[i].xh=i;
cin>>a[i].yw>>a[i].sx>>a[i].yy;
a[i].zf=a[i].yw+a[i].sx+a[i].yy;
}
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
{
if(a[i].zf<a[j].zf)
aa(a[i],a[j]);
else
if(a[i].zf==a[j].zf&&a[i].yw<a[j].yw)
aa(a[i],a[j]);
else
if(a[i].zf==a[j].zf&&a[i].yw==a[j].yw&&a[i].xh>a[j].xh)
aa(a[i],a[j]);
}
for(i=1;i<=5;i++)
cout<<a[i].xh<<" "<<a[i].zf<<endl;
}