题目:
http://acm.hdu.edu.cn/showproblem.php?pid=4310
#include<iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node{
int dps;
int hp;
friend booloperator<(constnode a,const node b){
return a.dps* b.hp - b.dps * a.hp > 0;
}
}hero[25];
int main(){
int n,i,j;
while(~scanf("%d",&n)){
for(i =0;i < n;i++)
scanf("%d%d",&hero[i].dps,&hero[i].hp);
sort(hero, hero+n);
int ans =0;
for(i =0;i <n;i++){
int sum = 0;
for(j = i;j <n;j++)
sum += hero[j].dps;
sum *=hero[i].hp;
ans+=sum;
}
printf("%d\n",ans);
}
return 0 ;
}
本文深入探讨了高效算法及数据结构的应用实例,包括排序、动态规划、哈希算法等核心概念,旨在提升编程效率与解决复杂问题的能力。
529

被折叠的 条评论
为什么被折叠?



