hdu3979 轮换不等式
轮换不等式性质: 1.可比性.2.传递性
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<algorithm> 6 using namespace std; 7 8 const int maxn = 10005; 9 struct emeny{ 10 int hp,apk; 11 double ave; 12 int time; 13 bool operator <(const emeny & r) const{ 14 return ave > r.ave; //降序排列; 15 } 16 }e[maxn]; 17 int test; 18 int n,m; 19 20 int main() 21 { 22 if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} 23 cin>>test; 24 for(int t=1;t<=test;t++){ 25 cin>>n>>m; 26 for(int i=0;i<n;i++){ 27 scanf("%d%d",&e[i].hp,&e[i].apk); 28 if(e[i].hp % m != 0) e[i].time = e[i].hp / m + 1; 29 else e[i].time = e[i].hp/m; 30 31 e[i].ave = 1.0*e[i].apk /(1.0*e[i].time); 32 } 33 34 sort(e,e+n); 35 int cnt = 0; 36 long long int ans = 0; 37 for(int i=0;i<n;i++){ 38 cnt += e[i].time; 39 ans += cnt * e[i].apk; 40 } 41 printf("Case #%d: %I64d\n",t,ans); 42 } 43 return 0; 44 }