第一次做TCO
今天晚上第一次做TCO的资格赛,第一次做,没经验,不过总算明白怎么回事了。
贴上我的第一次做TCO的大菜鸟代码250分拿到题目,囧了……:
代码
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class JingleRingle {
public:
int profit(vector <int> buyOffers, vector <int> sellOffers, int tax);
};
bool cmp(int a, int b)
{
if(a > b) return true;
else return false;
}
int JingleRingle::profit(vector <int> buyOffers, vector <int> sellOffers, int tax) {
int i, res = 0, t, tt;
double temp = 0.0;
res = 0;
sort(buyOffers.begin(), buyOffers.end(), cmp);
sort(sellOffers.begin(), sellOffers.end());
for(i = 0; i != sellOffers.size();i++)
{
t = buyOffers[i] - sellOffers[i];
if(t < 0) break;
tt = t - int(floor( double((buyOffers[i]) * (tax)) /100.0 ));
if(tt >= 0) res += tt;
}
return res;
}
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class JingleRingle {
public:
int profit(vector <int> buyOffers, vector <int> sellOffers, int tax);
};
bool cmp(int a, int b)
{
if(a > b) return true;
else return false;
}
int JingleRingle::profit(vector <int> buyOffers, vector <int> sellOffers, int tax) {
int i, res = 0, t, tt;
double temp = 0.0;
res = 0;
sort(buyOffers.begin(), buyOffers.end(), cmp);
sort(sellOffers.begin(), sellOffers.end());
for(i = 0; i != sellOffers.size();i++)
{
t = buyOffers[i] - sellOffers[i];
if(t < 0) break;
tt = t - int(floor( double((buyOffers[i]) * (tax)) /100.0 ));
if(tt >= 0) res += tt;
}
return res;
}
posted on 2010-05-12 20:35 Ktyanny Home 阅读(485) 评论(0) 编辑 收藏 举报