int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// int n; cin >> n; vector<int> res(7); int cur = (1 + 13 - 1) % 7, next = cur; for (int i = 0; i < n; ++i) { int leap = leap_year(1900 + i); for (int j = 0; j < 12; ++j) { cur = next; ++res[cur]; next = (cur + month[leap][j]) % 7; } } for (int i = 0; i < 7; ++i) { if (i) cout << " "; cout << res[(6 + i) % 7]; } cout << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// int n; cin >> n; vector< pair<int, int> > v(n); for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second; sort((v).begin(), (v).end()); int start = v[0].first, end = v[0].second; int continuous_time = 0, idle_time = 0; for (int i = 0; i < n; ++i) { if (v[i].first <= end) { end = max(end, v[i].second); continuous_time = max(continuous_time, end - start); } else { idle_time = max(idle_time, v[i].first - end); start = v[i].first; end = v[i].second; continuous_time = max(continuous_time, end - start); } } cout << continuous_time << " " << idle_time << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ///////////////////////////////////////////////////////////////////////// int n; cin >> n; vector< pair<int, int> > v(n); for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; } sort((v).begin(), (v).end()); int start = v[0].first, end = v[0].second; int x = end - start, y = 0; for (int i = 1; i < n; ++i) { if (v[i].first > end) { y = max(y, v[i].first - end); start = v[i].first; end = v[i].second; } else if (v[i].second > end) { end = v[i].second; } x = max(x, end - start); } cout << x << " " << y << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// int min_area = INT_MAX; set< pair<int, int> > res; vector< pair<int, int> > v(4); for (int i = 0; i < 4; ++i) cin >> v[i].first >> v[i].second; for (int p = 0; p < (1 << 4); ++p) { vector< pair<int, int> > v2 = v; for (int q = 0; q < 4; ++q) { if (p & (1 << q)) swap(v2[q].first, v2[q].second); } int a[4] = {0, 1, 2, 3}; do { vector< pair<int, int> > aux(4); for (int i = 0; i < 4; ++i) aux[i] = v2[a[i]]; func(aux, min_area, res); } while (next_permutation(a, a + 4)); } cout << min_area << endl; for (__typeof((res).begin()) i = (res).begin(); i != (res).end(); ++i) cout << i->first << " " << i->second << endl; }
int main(int argn, char const* argv[]) { cin.exceptions(ios_base::badbit | ios_base::failbit); cout.setf( ios::fixed, ios::floatfield ); cout.precision(1); if (argn > 1) { static ifstream ifs{argv[1]}; cin.rdbuf(ifs.rdbuf()); } std::vector<int> samples; { int n = 0; cin >> n; samples.reserve(n); while(n-- > 0) { int i = 0; cin >> i; samples.push_back(i); } } auto result = solution(samples); cout << result << "\n"; return 0; }
XML_File(string s){ inFile.open(s, fstream::in); ostringstream ss; ss << inFile.rdbuf(); content = ss.str(); inFile.close(); }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// int a[3], b[3]; int p[3][3]; for (int i=0; i<3; ++i) cin>>a[i]; for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) cin>>p[i][j]; int m=INT_MAX, r1=0, r2=0, r3=0, c; for (int k1=0; k1<100; ++k1) for (int k2=0; k2<100; ++k2) for (int k3=0; k3<100; ++k3) { b[0]=k1*p[0][0]+k2*p[1][0]+k3*p[2][0]; b[1]=k1*p[0][1]+k2*p[1][1]+k3*p[2][1]; b[2]=k1*p[0][2]+k2*p[1][2]+k3*p[2][2]; // cout<<k1<<" "<<k2<<" "<<k3<<" "; // print(a, 3); print(b, 3); int tmp; if ((tmp=check(a, b, 3))!=0) { int aux=k1+k2+k3; if (aux<m) { m=aux, r1=k1, r2=k2, r3=k3; c=tmp; } } } if (m==INT_MAX) cout<<"NONE"<<endl; else cout<<r1<<" "<<r2<<" "<<r3<<" "<<c<<endl; }
int CounterErrorTester::testErrorCounter(ifstream& aInStream, CounterError& bProcessor, const char* cFilename) { aInStream.open(cFilename); //открываем файл cin.rdbuf(aInStream.rdbuf()); //получаем буфер int result = bProcessor.CountErorrs(); //вызываем счетчик ошибок aInStream.close(); //закрываем файл return result; //отправляем результат }
void redirect(){ #ifdef DEBUG std::streambuf *cinbuf = std::cin.rdbuf(); std::cin.rdbuf(fin.rdbuf()); std::streambuf *coutbuf = std::cout.rdbuf(); std::cout.rdbuf(fout.rdbuf()); #endif }
bool STIL::determineEOL(ifstream &stilFile) { CERR_STIL_DEBUG << "detEOL() called" << endl; if (stilFile.fail()) { CERR_STIL_DEBUG << "detEOL() open failed" << endl; return false; } stilFile.seekg(0); STIL_EOL = '\0'; STIL_EOL2 = '\0'; // Determine what the EOL character is // (it can be different from OS to OS). istream::sentry se(stilFile, true); if (se) { streambuf *sb = stilFile.rdbuf(); const int eof = char_traits<char>::eof(); while (sb->sgetc() != eof) { const int c = sb->sbumpc(); if ((c == '\n') || (c == '\r')) { STIL_EOL = c; if (c == '\r') { if (sb->sgetc() == '\n') STIL_EOL2 = '\n'; } break; } } } if (STIL_EOL == '\0') { // Something is wrong - no EOL-like char was found. CERR_STIL_DEBUG << "detEOL() no EOL found" << endl; return false; } CERR_STIL_DEBUG << "detEOL() EOL1=0x" << hex << static_cast<int>(STIL_EOL) << " EOL2=0x" << hex << static_cast<int>(STIL_EOL2) << dec << endl; return true; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ///////////////////////////////////////////////////////////////////////// int a, b; cin >> a >> b; cout << a + b << endl; }
//the parser for reading from file string Morse::decode_morse(ifstream& fin) { if (!fin.good()){ return "ERROR: The file cannot be opened"; } stringstream buffer; buffer << fin.rdbuf(); string code_to_decipher, decoded = ""; while (buffer >> code_to_decipher){ decoded += " " + decoding(root, code_to_decipher); } return decoded; }
int main() { #ifdef DEBUG cin.rdbuf(fin.rdbuf()); #endif int n; cin>>n; vector<int> v(n); for (int i=0; i<n; ++i) cin>>v[i]; sort((v).begin(), (v).end()); long long sum=0, res=0; for (long long i=0; i<n; ++i) res+=v[i]*i-sum, sum+=v[i]; cout<<res*2<<endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// string in, pre, res; cin>>in>>pre; res=func(in, pre); cout<<res<<endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// int n; cin >> n; dfs(n, 1, 2); dfs(n, 0, 0); }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif //////////////////////////////////////////////////////////////////////////// int n; cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> y[i]; vector<string> g(n); for (int i = 0; i < n; ++i) cin >> g[i]; vector<vector<double> > dist(n, vector<double>(n, MAX)); for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (g[i][j] == '1') dist[i][j] = dist[j][i] = euclidean_distance(i, j); for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); double aux = 0; vector<double> diameter(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) if (i != j && dist[i][j] < MAX) diameter[i] = max(diameter[i], dist[i][j]); aux = max(aux, diameter[i]); } double res = MAX; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (i != j && dist[i][j] == MAX) res = max(min(res, euclidean_distance(i, j) + diameter[i] + diameter[j]), aux); cout << setiosflags(ios::fixed) << setprecision(6); cout << res << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// vector<int> a; for (int i=1; i<=8; ++i) a.push_back(i); vector<int> b(8); for (int i=0; i<8; ++i) cin>>b[i]; queue<vector<int> > q; q.push(a); map<vector<int>, pair<vector<int>, char> > back; back[a]=make_pair(vector<int>(), 0); string res; bool ok=false; while (!q.empty()) { vector<int> x=q.front(); q.pop(); if (x==b) { ok=true; while (x!=a) res+=back[x].second, x=back[x].first; reverse((res).begin(), (res).end()); break; } vector<int> next=turn1(x); if (!((back).find(next)!=(back).end())) back[next]=make_pair(x, 'A'), q.push(next); next=turn2(x); if (!((back).find(next)!=(back).end())) back[next]=make_pair(x, 'B'), q.push(next); next=turn3(x); if (!((back).find(next)!=(back).end())) back[next]=make_pair(x, 'C'), q.push(next); } if (ok) { cout<<(int)(res).size()<<endl; for (int i=0; i<(int)(res).size(); ++i) { if (i && i%60==0) cout<<endl; cout<<res[i]; } cout<<endl; } }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ///////////////////////////////////////////////////////////////////////// cin >> sum >> left_top; create_prime(); g[0][0] = row_sum[0][0] = column_sum[0][0] = left_top; found = false; dfs(0, 1); if (!found) cout << "NONE" << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif //////////////////////////////////////////////////////////////////////////// int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; --v[i]; } vector<int> cnt(3); for (int i = 0; i < n; ++i) ++cnt[v[i]]; vector< vector<int> > place(3, vector<int>(3)); for (int i = 0; i < n; ++i) if (i < cnt[0]) ++place[0][v[i]]; else if (i < cnt[0] + cnt[1]) ++place[1][v[i]]; else ++place[2][v[i]]; int res = 0; int aux = min(place[0][1], place[1][0]); res += aux; place[0][1] -= aux; aux = min(place[0][2], place[2][0]); res += aux; place[0][2] -= aux; aux = min(place[1][2], place[2][1]); res += aux; aux = max(place[0][1], place[0][2]); res += 2 * aux; cout << res << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// string a, b; cin >> a >> b; int x = 1, y = 1; for (int i = 0; i < (int)(a).size(); ++i) x = x * (a[i] - 'A' + 1) % 47; for (int i = 0; i < (int)(b).size(); ++i) y = y * (b[i] - 'A' + 1) % 47; cout << (x == y ? "GO" : "STAY") << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif //////////////////////////////////////////////////////////////////////////// int sum = 0; res = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> board[i]; sum += board[i]; } cin >> m; for (int i = 0; i < m; ++i) cin >> rails[i]; sort(board, board + n); sort(rails, rails + m); for (int i = 0; i < m; ++i) { total[i] = i == 0 ? rails[i] : total[i - 1] + rails[i]; if (total[i] > sum) { m = i; break; } } ok = false; for (int deep = m - 1; deep >= 0; --deep) { dfsid(deep, 0, sum - total[deep], 0); if (ok) { res = deep + 1; break; } } cout << res << endl; }
bool FirehoseLibraryClient::sendMessage(const ifstream& data, int repetitions/* = 0*/) { if(!m_initialized) { cout << "Not Initialized." << endl; return false; } PutRecordRequest request; //set stream name; Aws::String __streamName("TMP"); request.SetDeliveryStreamName(m_streamName.c_str()); Record record; Aws::StringStream dataStream; dataStream << data.rdbuf(); #ifdef DEBUG_INFO cout << "Buff Size to transfer: [" << dataStream.str().length() << "]" << endl; #endif Aws::Utils::ByteBuffer buff((unsigned char*)dataStream.str().c_str(), dataStream.str().length()); //apply stream data to record buffer Data record.SetData(buff); //set record to request request.SetRecord(record); //for loop is for testing purposes only for(int i = 0; i <= repetitions; i++) { //send request to cloud Model::PutRecordOutcome outcome = m_firehoseClient->PutRecord(request); if(!outcome.IsSuccess()) { cout << "Error sending message " << i + 1 << "." << endl; i = repetitions; return false; } } return true; }
int main() { #ifdef DEBUG cin.rdbuf(fin.rdbuf()); #endif int n; while (cin>>n && n) { int x; int m=-1; int sum=0; memset(a, 0, sizeof(a)); // memset(b, 0, sizeof(a)); for (int i=0; i<n; ++i) cin>>x, a[x]++, m=max(m, x), sum+=x; int res=0; for (int i=m; i<=sum; ++i) if (sum%i==0 && check(i, sum)) { res=i; break; } cout<<res<<endl; } }
vector<equal_functions> parse_file(const ifstream& file, const vector<affine_change>& vec) { vector<equal_functions> eq; int function, change, n; char c; stringstream ss; ss << file.rdbuf(); ss>>n>>c; while(ss) { ss>>function>>c>>change>>c; eq.push_back(equal_functions(polynom(int_to_vec(function,pow(2,n)),0))); while (c != ';') { ss>>function>>c>>change>>c; eq.back().add_function(function, change); } } if (!eq.empty()) eq.pop_back(); return eq; }
int main() { #ifdef DEBUG cin.rdbuf(fin.rdbuf()); #endif int n; cin>>n; vector<vector<int> > g(n, vector<int>(n)); for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) cin>>g[i][j]; int res=0; for (int k=0; k<(1<<(n-1)); ++k) { int aux=0; for (int i=0; i<n; ++i) for (int j=i+1; j<n; ++j) if (!(k&(1<<i))!=!(k&(1<<j))) aux+=g[i][j]; res=max(res, aux); } cout<<res<<endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif //////////////////////////////////////////////////////////////////////////// int k, n; cin >> k >> n; vector<int> prime(k); for (int i = 0; i < k; ++i) cin >> prime[i]; sort((prime).begin(), (prime).end()), (prime).erase(unique((prime).begin(), (prime).end()), (prime).end()); vector<int> res; res.push_back(1); while (n) { int x = res.back(); int next = INT_MAX; for (int i = 0; i < (int)(res).size(); ++i) { int start = lower_bound((prime).begin(), (prime).end(), x / res[i]) - prime.begin(); for (int j = start; j < k; ++j) { int aux = res[i] * prime[j]; if (aux > next) break; if (aux > x && aux < next) next = aux; } } res.push_back(next); --n; } #ifdef DEBUG print(res); #endif cout << res.back() << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif //////////////////////////////////////////////////////////////////////////// int F; cin >> F; vector<int> v(501); vector< vector<int> > g(501, vector<int>(501)); for (int i = 0; i < F; ++i) { int a, b; cin >> a >> b; ++v[a]; ++v[b]; ++g[a][b]; ++g[b][a]; } int start = 1; for (int i = 1; i < (int)(v).size(); ++i) if (v[i] % 2 == 1) { start = i; break; } vector<int> path; find_path(start, g, path); #ifdef DEBUG print(path); #endif reverse((path).begin(), (path).end()); for (int i = 0; i < (int)(path).size(); ++i) cout << path[i] << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif //////////////////////////////////////////////////////////////////////////// int n; cin >> n; int sum = n * (n + 1) / 2; if (sum % 2) { cout << 0 << endl; return 0; } dp[0] = 1; for (int i = 1; i <= n; ++i) for (int j = sum; j >= i; --j) dp[j] += dp[j - i]; cout << dp[sum / 2] / 2 << endl; }
int main() { cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); #ifdef DEBUG cin.rdbuf(cin_buf); cout.rdbuf(cout_buf); #endif ////////////////////////////////////////////////////////////////////////////// int s; cin>>s; for (int i=0; i<s; ++i) { int n; cin>>n; vector<pair<int, int> > v; for (int j=0; j<n; ++j) { int c, k; cin>>c>>k; v.push_back(make_pair(c, k)); } int p; cin>>p; special_price.push_back(make_pair(v, p)); } int b; cin>>b; for (int i=0; i<b; ++i) { int c, k, p; cin>>c>>k>>p; a[c]+=k; price[c]=p; } res=INT_MAX; dfs(0); cout<<res<<endl; }
int main() { #ifdef DEBUG cin.rdbuf(fin.rdbuf()); #endif int n; scanf("%d", &n); for (int i=0; i<n; ++i) { int t=0; scanf("%s", s); for (unsigned j=0; j<strlen(s); ++j) if (isdigit(s[j])) t=t*10+(s[j]-'0'); else if (isupper(s[j])) t=t*10+num[s[j]-'A']; v[t]++; } bool ok=false; for (int i=0; i<10000000; ++i) if (v[i]>1) { ok=true; printf("%d%d%d-%d%d%d%d %d\n", i/1000000%10, i/100000%10, i/10000%10, i/1000%10, i/100%10, i/10%10, i%10, v[i]); } if (!ok) cout<<"No duplicates."<<endl; }