【AOJ 2198】Moonlight Farm
問題
Moonlight Farm | Aizu Online Judge
方針
- 入力が色々あるので1度図に起こして考えてみると非常に簡単
- 収入効率の分母は, 分子はとなるのでこれをクラスにいれてソートをするだけ.
- 効率が同じ場合は名前を辞書順で表示する.
ソース
#include <iostream> #include <vector> #include <algorithm> using namespace std; class Log{ public: string name; double efficiency; Log(string name, double numerator, double denominator){ this->name = name; efficiency = numerator/denominator; } bool operator < (const Log& another) const{ if(efficiency == another.efficiency){ return name < another.name; } return (efficiency > another.efficiency); } }; signed main(){ int n; while(cin >> n, n){ vector<Log> v; for(int i = 0 ; i < n ; i++){ double p, a, b, c, d, e, f, s, m; string l; cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m; v.push_back(Log(l, s*f*m-p, a+b+c+(d + e)*m)); } sort(v.begin(), v.end()); for(int i = 0 ; i < n ; i++){ cout << v[i].name << endl; } cout << "#" << endl; } }