Check-in [ecb4f1560e]
Not logged in
Overview
SHA1 Hash:ecb4f1560e1321c23f998e00212756b5e19be82d
Date: 2013-02-07 01:30:49
User: kinaba
Comment:(no comment)
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added SRM/568-U/1A.cpp version [17eca4992b85996a]

1 +#include <iostream> 2 +#include <sstream> 3 +#include <iomanip> 4 +#include <vector> 5 +#include <string> 6 +#include <map> 7 +#include <set> 8 +#include <algorithm> 9 +#include <numeric> 10 +#include <iterator> 11 +#include <functional> 12 +#include <complex> 13 +#include <queue> 14 +#include <stack> 15 +#include <cmath> 16 +#include <cassert> 17 +using namespace std; 18 +typedef long long LL; 19 +typedef long double LD; 20 +typedef complex<LD> CMP; 21 + 22 +class BallsSeparating { public: 23 + int minOperations(vector <int> red, vector <int> green, vector <int> blue) 24 + { 25 + int best = 1<<30; 26 + int N = red.size(); 27 + 28 + if(N<=2) 29 + return -1; 30 + for(int R=0; R<N; ++R) 31 + for(int G=0; G<N; ++G) if(G!=R) 32 + for(int B=0; B<N; ++B) if(B!=G && B!=R) 33 + { 34 + int c = 0; 35 + for(int i=0; i<N; ++i) 36 + { 37 + int gb = green[i] + blue[i]; 38 + int br = blue[i] + red[i]; 39 + int rg = red[i] + green[i]; 40 + if(i==R) c += gb; 41 + else if(i==B) c += rg; 42 + else if(i==G) c += br; 43 + else c += min(gb, min(rg,br)); 44 + } 45 + best = min(best, c); 46 + } 47 + return best; 48 + } 49 +}; 50 + 51 +// BEGIN CUT HERE 52 +#include <ctime> 53 +double start_time; string timer() 54 + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 55 +template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 56 + { os << "{ "; 57 + for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 58 + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 59 +void verify_case(const int& Expected, const int& Received) { 60 + bool ok = (Expected == Received); 61 + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 62 + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 63 +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 64 +#define END verify_case(_, BallsSeparating().minOperations(red, green, blue));} 65 +int main(){ 66 + 67 +CASE(0) 68 + int red_[] = {1, 1, 1}; 69 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 70 + int green_[] = {1, 1, 1}; 71 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 72 + int blue_[] = {1, 1, 1}; 73 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 74 + int _ = 6; 75 +END 76 +CASE(1) 77 + int red_[] = {5}; 78 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 79 + int green_[] = {6}; 80 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 81 + int blue_[] = {8}; 82 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 83 + int _ = -1; 84 +END 85 +CASE(2) 86 + int red_[] = {4, 6, 5, 7}; 87 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 88 + int green_[] = {7, 4, 6, 3}; 89 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 90 + int blue_[] = {6, 5, 3, 8}; 91 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 92 + int _ = 37; 93 +END 94 +CASE(3) 95 + int red_[] = {7, 12, 9, 9, 7}; 96 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 97 + int green_[] = {7, 10, 8, 8, 9}; 98 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 99 + int blue_[] = {8, 9, 5, 6, 13}; 100 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 101 + int _ = 77; 102 +END 103 +CASE(4) 104 + int red_[] = {842398, 491273, 958925, 849859, 771363, 67803, 184892, 391907, 256150, 75799}; 105 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 106 + int green_[] = {268944, 342402, 894352, 228640, 903885, 908656, 414271, 292588, 852057, 889141}; 107 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 108 + int blue_[] = {662939, 340220, 600081, 390298, 376707, 372199, 435097, 40266, 145590, 505103}; 109 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 110 + int _ = 7230607; 111 +END 112 + /* 113 +CASE(5) 114 + int red_[] = ; 115 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 116 + int green_[] = ; 117 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 118 + int blue_[] = ; 119 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 120 + int _ = ; 121 +END 122 +CASE(6) 123 + int red_[] = ; 124 + vector <int> red(red_, red_+sizeof(red_)/sizeof(*red_)); 125 + int green_[] = ; 126 + vector <int> green(green_, green_+sizeof(green_)/sizeof(*green_)); 127 + int blue_[] = ; 128 + vector <int> blue(blue_, blue_+sizeof(blue_)/sizeof(*blue_)); 129 + int _ = ; 130 +END 131 + */ 132 +} 133 +// END CUT HERE