正文
增加 22 行删除 119 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132```cpp// P10486 [入门赛 #25] sql#include <iostream>#include <algorithm>#include <vector>#include <unordered_map>template <typename K, typename V>using map = std::unordered_map<K, V>;// <name, <header, <string, index> > >map<std::string, map<std::string, map<std::string, std::vector<int>>>> hashs;map<std::string, std::vector<std::vector<std::string>>> tables;void CreateTable(std::string name, int row, int col) // It runs correctly. Don't touch it.{// Create Table Arraystd::vector<std::vector<std::string>> table(row + 1, std::vector<std::string>(col + 1));for (int i = 1; i <= row; i++)for (int j = 1; j <= col; j++)std::cin >> table[i][j];tables[name] = table;// Create Hash For Tablemap<std::string, std::vector<int>> temp;map<std::string, map<std::string, std::vector<int>>> temp2;for (int i = 1; i <= col; i++){std::string colName = table[1][i];for (int j = 2; j <= row; j++)temp[table[j][i]].push_back(j);temp2[colName] = temp;temp.clear();}hashs[name] = temp2;return;}void Query(std::string tableName, std::vector<std::string> headers, std::string query, std::string value){// Copymap<std::string, map<std::string, std::vector<int>>> hash = hashs[tableName];std::vector<std::vector<std::string>> table = tables[tableName];// Querystd::vector<int> idx = hash[query][value];for (int row : idx){for (std::string header : headers){for (int col = 1; col <= (int)table[row].size() - 1; col++){if (table[1][col] == header) // Find Every Tablehead{std::cout << table[row][col] << " ";break;}}}std::cout << '\n';}return;}std::string Get(const std::string &op, char endChar, int &startIdx){int i = startIdx;std::string res;while (op[i] != endChar && i < (int)op.length()){res += op[i];i++;}startIdx = i + 1;return res;}void Resolve(std::string op, std::string &table, std::vector<std::string> &headers, std::string &query, std::string &value) // It runs well.{// Such As : select sid,name from basic_info where grade=2// Also : select headers from table where query=valueint i = 0;i += 7; // Continue "select" and space to headersstd::string headersResolve = Get(op, ' ', i) + ','; // GetHeadersint j = 0;while (j < (int)headersResolve.length()){std::string header = Get(headersResolve, ',', j);if (!header.empty())headers.push_back(header);}i += 5; // Continue "from" and space to tabletable = Get(op, ' ', i); // Get tablei += 6; // Continue "where" and space to queryquery = Get(op, '=', i); // Get Queryvalue = op.substr(i); // Get Valuewhile (!value.empty() && (value.back() == ' ' || value.back() == '\n' || value.back() == '\r'))value.pop_back();}void Solve(){int n, q;// Create Tablesstd::cin >> n;while (n--){std::string str;int x, y;std::cin >> str >> x >> y;CreateTable(str, x, y);}// Querystd::cin >> q;while (q--){std::string str;std::getline(std::cin, str);if (str.empty()){q++;continue;}std::string table, query, value;std::vector<std::string> headers;Resolve(str, table, headers, query, value);Query(table, headers, query, value);}}int main(){Solve();return 0;}```1234567891011121314151617181920212223242526272829303132333435#include <iostream>#define ULL unsigned long longbool Solve(){ULL n, x;std::cin >> n >> x;if (x == 1)return (n & (n - 1)) == 0;ULL S = 0, tmp = n;while (tmp){S += tmp % x;tmp /= x;}ULL d = x - 1;for (ULL p = 1; p <= n; p <<= 1)if (p >= S && (p - S) % d == 0)return true;return false;}int main(){std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int T;std::cin >> T;while (T--)std::cout << (Solve() ? "Yes\n" : "No\n");return 0;}