intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; int n = s.size(); vector<int> ans; int i = 1, st; while (i < n) { st = i; while (i < n && s[i] != '|') i++; ans.push_back(i - st); i++; } for (auto &x : ans) cout << x << ' '; return0; }
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; string s; cin >> s; vector<pair<int, int>> blocks; for (int i = 0, st; i < n; i++) { if (s[i] == '1') { st = i; while (i < n && s[i] == '1') i++; blocks.push_back({st, i - 1}); } } int r_prev = blocks[k - 2].second; int l = blocks[k - 1].first, r = blocks[k - 1].second; string ans = ""; ans += s.substr(0, r_prev + 1); ans += s.substr(l, r + 1 - l); ans += s.substr(r_prev + 1, l - r_prev - 1); ans += s.substr(r + 1); cout << ans << endl; return0; }
首先,觀察每次操作的規則:將目前的字串 S 中的大寫字母變成小寫,小寫字母變成大寫後,附加到原字串的末尾。這意味著每進行一次操作,字串的長度會翻倍。因此,在 m 次操作後,字串的長度將達到 n×2m。而我們可以利用這個性質來確定查詢位置 Ki 所在的字串是位於第 m 次操作後的原始部分 S 或翻轉部分 T 。
S = input() Q = int(input()) queries = list(map(int, input().split()))
n = len(S) ln = [n] MAX_LN = 1e18 while ln[-1] <= MAX_LN: ln.append(ln[-1] * 2) m = len(ln)
ans = [] for k in queries: cnt = 0 for i inrange(m - 1, 0, -1): if k > ln[i - 1]: k = k - ln[i - 1] cnt += 1 ch = S[k - 1] if cnt & 1: ch = ch.upper() if ch.islower() else ch.lower() ans.append(ch) print(*ans)
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m, l; cin >> n >> m >> l; vector<int> cards(n + m + l); for (int i = 0; i < n + m + l; i++) cin >> cards[i]; int mask = (1 << (n + m + l)) - 1; int a = 0, b = 0; for (int i = 0; i < n; i++) a |= (1 << i); for (int i = n; i < n + m; i++) b |= (1 << i);
unordered_map<int, int> memo; // Memoization auto f = [&](auto &&f, int a, int b, bool flag) -> bool { int key = a << (n + m + l + 1) | b << 1 | flag; if (memo.count(key)) return memo[key];
int cur = flag ? a : b; // 當前輪到某玩家出牌 if (cur == 0) returnfalse; // 當前玩家沒有牌可打就輸了 int table = ~(a | b) & mask; // 桌面上的牌是兩個玩家手牌以外的牌 int n_a, n_b, n_table; for (int i = 0; i < n + m + l; i++) { // 枚舉要打出的牌 if (!((cur >> i) & 1)) continue; // 如果當前玩家沒有這張牌則跳過
if (flag) { n_a = a & ~(1 << i); n_b = b; } else { n_a = a; n_b = b & ~(1 << i); }
n_table = table | (1 << i); // 桌面上的牌加上剛剛打出的牌 if (!f(f, n_a, n_b, flag ^ 1)) return memo[key] = true; // 不回收牌 for (int j = 0; j < n + m + l; j++) { if (((n_table >> j) & 1) && (cards[j] < cards[i])) { // 這張牌在桌面上,且比剛剛打出的牌小,可以回收 if (flag) { if (!f(f, n_a | (1 << j), n_b, flag ^ 1)) return memo[key] = true; } else { if (!f(f, n_a, n_b | (1 << j), flag ^ 1)) return memo[key] = true; } } } } return memo[key] = false; }; cout << (f(f, a, b, 1) ? "Takahashi" : "Aoki") << endl;
return0; }
寫在最後
PROMPT
Kamisato Ayaka, a serene and dreamy image of Kamisato Ayaka, an anime girl with long flowing white hair, gracefully reclines on a bed adorned with crisp white sheets. She wears a stylish school uniform featuring a fitted white shirt, a deep blue sailor collar, and a pleated blue skirt, accented by a vibrant blue bow around her neck and a striking red bow in her hair. Her large blue eyes gaze softly at the viewer, sparkling with warmth, while a gentle blush graces her cheeks, enhancing her youthful charm.
The room is awash in soft blue and white tones, but with increased contrast to highlight the details, as sunlight streams through a nearby window on the right, casting a warm, inviting glow across the scene. Plush blue pillows are arranged behind her, providing comfort, and a book with scattered petals lies open beside her, suggesting a moment of leisure.
Ayaka’s posture is relaxed yet natural, with one arm resting comfortably behind her head while the other gently cradles a small, delicate flower. Her serene expression is complemented by a peaceful atmosphere, heightened by the presence of a smartphone and a stylish school bag nearby. The scene is completed with a touch of elegance from her intricate hair ornament and choker, creating a harmonious and vibrant blend of elements that draws the viewer into her tranquil world.