#include<stdio.h>
#include?<string.h>
int?main(){
?int?n,m;?//n?is?number?of?heads.m?is?number?of??knights.?
?while(scanf("%d?%d",&n,&m)==2&&!(n==0&&m==0)){
???if(n>=1&&n<=20000&&m>=1&&n<=20000&&n<=m){???
???int?headSize[n];???
???int?knightAbility[m];???
???int?i,j;???
???for(i=0;i<n;i++){????
???scanf("%d\n",&headSize[i]);???
???}??????
???for(i=0;i<m;i++){????
???scanf("%d\n",&knightAbility[i]);???
???}??????
???int?sum=0;???
???for(i=0;i<n;i++){????
???int?min=999999;????
???for(j=0;j<m;j++){?????
???if(knightAbility[j]>=headSize[i]&&knightAbility[j]<min){??????
???min=knightAbility[j];?????
???}?????
???sum+=min;
???}???
???}???
???printf("%d\n",sum);?
???}??
???else???
???printf("loowater?is?doomed.");
}???//printf("end?of?pro");
}這道題我沒(méi)有事先排序,結(jié)果不對(duì)。
1 回答

艾爾森
TA貢獻(xiàn)33條經(jīng)驗(yàn) 獲得超27個(gè)贊
你也知道沒(méi)有排序?yàn)槭裁床慌拧?主要就是一個(gè)貪心 不排序還怎么貪 還有算法問(wèn)題還是不要在這里問(wèn)了… 這個(gè)網(wǎng)站本身就不是算法的學(xué)習(xí)網(wǎng)站 (還有你這個(gè)縮進(jìn)看的我無(wú)從下手…)
- 1 回答
- 2 關(guān)注
- 2295 瀏覽
添加回答
舉報(bào)
0/150
提交
取消