TC SRM 564 div2 B 题
题意:
给出红,绿,蓝球的数量分别用r,g,b表示,每次执行如下操作,如果存在红球就拿出一个红球,如果存在绿球就拿出一个绿球,如果存在一个蓝球就拿出一个蓝球。当球为空时不再拿。问在第k步取出的是什么颜色的球;
思路:
好不容易做一次能把B题写完,感觉没错的TC结果还是因为没有考虑全面,被系统数据给击败了。哎,只能感叹自己思路还是没有那么的灵活。自己当时的处理确实也很麻烦。最后看了人家的处理感叹思路想好了代码速度其实差不多远。思路,思路.....
我们只要每次取出三个数中最小的来,然后检查同时减去这些的数量与 k的关系,如果小于的话,肯定都能减去,否则就是减去k个了。这里记录第几个是什么颜色处理的很是巧妙自己没有思考到。
#line 5 "AlternateColors.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; #define CL(a,num) memset((a),(num),sizeof(a)) #define iabs(x) ((x) > 0 ? (x) : -(x)) #define MOD 1073741824 #define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define PB push_back #define MP make_pair #define REP(i,n) for(i=0;i<(n);++i) #define FOR(i,l,h) for(i=(l);i<=(h);++i) #define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI; typedef vector<string> VS; typedef vector<double> VD; typedef long long LL; typedef pair<int,int> PII; const LL inf = 500000000000000LL; class AlternateColors { public: string getColor(long long r, long long g, long long b, long long k) { string s[5]; while (k > 0) { int num = 0; LL MIN = inf; MIN = min(min(r,g),min(MIN,b)); if (r != inf) s[++num] = "RED"; if (g != inf) s[++num] = "GREEN"; if (b != inf) s[++num] = "BLUE"; if (MIN*num >= k) { k = k%num; if (k == 0) return s[num]; else return s[k]; } else { if (r != inf) r -= MIN; if (g != inf) g -= MIN; if (b != inf) b -= MIN; if (r <= 0) r = inf; if (g <= 0) g = inf; if (b <= 0) b = inf; k -= MIN*num; } } } };