跳到主要內容

TopCoder SRM 195 DIV2 optimalCoins

題意是說要構成1~value分別只需要一種方法去付錢

思考題,想出方法之後就可以直接秒過去了 有點類似權值

 

// BEGIN CUT HERE

// END CUT HERE
#line 5 "GCAcode.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#ifdef DEBUG
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...) printf("DEBUG: "),printf(__VA_ARGS__)
#else
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...)
#endif
typedef unsigned int uint;
typedef long long int Int;
typedef unsigned long long int UInt;
#define Set(a,s) memset(a,s,sizeof(a))
#define Pln() printf("\n")
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define M MAX_LIMITS
#define PB push_back
#define oo INT_MAX
#define FOR(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)
#define eps 1e-9
#define X first
#define Y second
inline bool xdy(double x,double y){return x>y+eps;}
inline bool xddy(double x,double y){return x>y-eps;}
inline bool xcy(double x,double y){return x<y-eps;}
inline bool xcdy(double x,double y){return x<y+eps;}
const Int mod=1000000007;


bool cmp(int x,int y){return x>y;}
class ChangePurse
{
public:

vector <int> optimalCoins(vector <int> coinTypes, int value){
vector<int> ans;
map<int,int> sid;
int n=coinTypes.size();
vector<int> sortcoin=coinTypes;
sort(sortcoin.begin(),sortcoin.end(),cmp);
int now=value;
for(int i=0;i<n;i++){
if(now%sortcoin[i]==sortcoin[i]-1){
sid[sortcoin[i]]=now/sortcoin[i];
now=sortcoin[i]-1;
}
}
for(int i=0;i<n;i++){
ans.PB(sid[coinTypes[i]]);
}
// printf("%d\n",n);
return ans;
}

// BEGIN CUT HERE
public:
void run_test(int Case) {
if ((Case == -1) || (Case == 0)) test_case_0();
if ((Case == -1) || (Case == 1)) test_case_1();
if ((Case == -1) || (Case == 2)) test_case_2();
if ((Case == -1) || (Case == 3)) test_case_3();
if ((Case == -1) || (Case == 4)) test_case_4();
if ((Case == -1) || (Case == 5)) test_case_5();
if ((Case == -1) || (Case == 6)) test_case_6();
if ((Case == -1) || (Case == 7)) test_case_7();
}
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const vector <int> &Expected, const vector <int> &Received) { cout << "Test Case #" << Case << "..."; if (Expected == Received) cout << "PASSED" << endl; else { cout << "FAILED" << endl; cout << "\tExpected: " << print_array(Expected) << endl; cout << "\tReceived: " << print_array(Received) << endl; } }
void test_case_0() {
int Arr0[] = {1,25,10};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 49;
int Arr2[] = { 24, 1, 0 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(0, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_1() {
int Arr0[] = {1,7};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 49;
int Arr2[] = { 49, 0 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(1, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_2() {
int Arr0[] = {11,5,10,1};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 109;
int Arr2[] = { 9, 0, 0, 10 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(2, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_3() {
int Arr0[] = {29210, 58420, 350520, 708072, 720035, 230, 42355,
1, 59006, 985, 236024, 163, 701040};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 929579039;
int Arr2[] = { 1, 5, 1, 0, 0, 126, 0, 229, 0, 0, 0, 0, 1325 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(3, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_4() {
int Arr0[] = {795, 5536, 26, 915, 18590, 60840, 49140, 2,
119700, 162235, 369000, 383936, 478800, 505995,
949, 95984, 455, 8, 420, 239400, 276800, 191968,
619305, 654810, 706420, 393120, 738000, 767872,
425880, 786240, 830400, 676, 4500, 851760, 957600,
648940, 1, 112, 180, 457};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 687245439;
int Arr2[] = { 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 13, 0, 0, 0, 1, 0, 0, 0, 0, 0, 894, 0, 0, 0, 0, 0, 0, 0, 0, 1, 856, 0, 0 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(4, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_5() {
int Arr0[] = {494208, 722376, 731798, 809064, 920448, 1, 988416, 9152, 158,
991014, 282720, 40132, 608, 143, 289755, 734, 579510, 828400,
330338, 816, 460224, 27456, 675783, 331, 436, 82368, 729, 306,
202266, 247104, 414200, 705};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 419088383;
int Arr2[] = { 1, 0, 0, 0, 0, 142, 423, 2, 0, 0, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(5, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_6() {
int Arr0[] = {1,25,10};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 49;
int Arr2[] = { 24, 1, 0 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(6, Arg2, optimalCoins(Arg0, Arg1)); }
void test_case_7() {
int Arr0[] = {1,25,10};
vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0])));
int Arg1 = 49;
int Arr2[] = { 24, 1, 0 };
vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0])));
verify_case(7, Arg2, optimalCoins(Arg0, Arg1)); }

// END CUT HERE

};

// BEGIN CUT HERE
int main()
{
ChangePurse ___test;
___test.run_test(-1);
return 0;
}
// END CUT HERE

留言