2 条题解
-
1
正解
#include<iostream> using namespace std; int main(){ int n,m,apple=0; int a[101],b[5]; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=m;i++){ cin>>b[i]; } for(int i=1;i<n;i++){ for(int j=1;j<n-1;j++){ if(a[i]>a[i+1]){ int t=a[i]; a[i]=a[i+1]; a[i+1]=t; } } } for(int i=1;i<m;i++){ for(int j=1;j<n-1;j++){ if(b[i]>b[i+1]){ int t=b[i]; b[i]=b[i+1]; b[i+1]=t; } } } int k=1; for(int i=1;i<=m;i++){ int time=0; for(int j=k;j<=n;j++){ if(a[j]<=b[i]){ apple++; time++; k++; } if(time==2){ break; } } } cout<<apple; }
-
1
C++ :
#include<bits/stdc++.h> using namespace std; int a[110],b[25]; bool cmp(int x,int y){ return x>y; } int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n,cmp); for(int i=1;i<=m;i++) cin>>b[i]; sort(b+1,b+1+n,cmp); int k=1; int sum=0,t=0; for(int i=1;i<=m;i++) for(int j=k;j<=n;j++){ if(b[i]>a[j]){ sum++; t++; } if(t==2){ t=0; k=j+1; break; } } cout<<sum<<endl; return 0; }
Pascal :
var n,m,k,t,j,tmp,sum,i:longint; pg,xpy:array[1..100] of longint; begin readln(n,m); for i:=1 to n do read(pg[i]); for i:=1 to m do read(xpy[i]); for i:=1 to n-1 do for j:=i+1 to n do if pg[i]<pg[j] then begin tmp:=pg[i];pg[i]:=pg[j];pg[j]:=tmp; end; for i:=1 to m-1 do for j:=i+1 to n do if xpy[i]<xpy[j] then begin tmp:=xpy[i];xpy[i]:=xpy[j];xpy[j]:=tmp; end; k:=1; for i:=1 to m do for j:=k to n do if xpy[i]>pg[j] then begin inc(sum); inc(t); if t=2 then begin t:=0; k:=j+1; break; end; end; write(sum); end.
- 1
信息
- ID
- 494
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 40
- 已通过
- 7
- 上传者