Codeforces Round #490 (Div. 3)-C. Alphabetic Removals(思維)
題目連結:http://codeforces.com/contest/999/problem/C
題意:給了n和k,然後輸入一個長度為n的字串,然後有k次操作,從字串中依次按abcd...的順序刪除字元,最後輸出k次操作後的字串。
思路:sort排序後的前k個字元就是我們要刪除的字元,用map標記要刪除的字元,直接輸出就好了。
#include<bits/stdc++.h> using namespace std; #define ll long long #define read(x) scanf("%d",&x) const int maxn = 1e6+7; map<char,int>mp; int main() { int n, k; read(n); read(k); string s, t; cin >> s; t = s; sort(t.begin(),t.end()); for(int i = 0; i < k; i++) mp[t[i]]++; for(int i = 0; i < n; i++) { if(!mp[s[i]]) cout << s[i]; else mp[s[i]]--; } }
相關推薦
Codeforces Round #490 (Div. 3)-C. Alphabetic Removals(思維)
題目連結:http://codeforces.com/contest/999/problem/C 題意:給了n和k,然後輸入一個長度為n的字串,然後有k次操作,從字串中依次按abcd...的順序刪除字元,最後輸出k次操作後的字串。 思路:sort排序後的前k個字元就是我們要刪除的字元,用
Codeforces Round #486 (Div. 3) C. Equal Sums (題解)
OutputIf it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "
Codeforces Round #423 Div. 2 C-String Reconstruction(思維)
images memset clu 技術 ret .cn har ges round 題目大意:告訴你n個字符串以及這些字符串在字符串s中出現的位置(x1,x2.....xn),要求在滿足上述條件的情況下,求出字典序最小的字符串s。 解題思路:主要問題是,如果直接模擬是會超
Codeforces Round #506 (Div. 3) C. Maximal Intersection (枚舉)
set return 最大 spa each pty c++ int names 【題目描述】 You are given $n$ segments on a number line; each endpoint of every segment has integer c
Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes(思維)
題目連結:http://codeforces.com/contest/1092/problem/C 題意:有一個長度為n的字串(並沒有給出),然後給出了2*n-2個這個字串的字首和字尾子串,也就是長度為1的有兩個,分別是字串的字首和字尾,長度為2的也有兩個,也是一個為字首一個為字尾,直到n-
Codeforces Round #224 (Div. 2): C. Arithmetic Progression(模擬)
題意: 給你n個數字,你需要再新增一個數字,使得最後所有數字排序之後任意相鄰兩個數之差全部相等,問可以新增多少種不同的數字 思路: 一看就是水題但是情況不少,沒了 例如所有數字全部相等,只有兩個數字,且它們的差是偶數/奇數等等 &nb
Codeforces Round #511 (Div. 2) C. Enlarge GCD (質因數)
題目 題意: 給你n個數a[1]...a[n],可以得到這n個數的最大公約數, 現在要求你在n個數中 儘量少刪除數,使得被刪之後的陣列a的最大公約數比原來的大。 如果要刪的數小於n,就輸出要刪的數的個數, 否則輸出 -1 。 思路: 設原來的最大
Codeforces Round #367 (Div. 2) C. Hard problem (dp)
Note In the second sample one has to reverse string 2 or string 3. To amount of energy required to reverse the string 3 is smaller. In the third sample
Codeforces Round #490 (Div. 3)-賽後補題
pair mem In style i++ tro http 如果 use D. Equalize the Remainders 思維太僵硬了,我從余數入手,嫩是記錄不了每個數要操作多少次。但是如果考慮每個數的貢獻,即操作多少次能使得滿足條件,就好寫了,實際上也是暴力。
Reachability from the Capital(Codeforces Round #490 (Div. 3)+tarjan有向圖縮點)
capi mage vector syn clas blank num 就是 pil 題目鏈接:http://codeforces.com/contest/999/problem/E 題目: 題意:給你n個城市,m條單向邊,問你需要加多少條邊才能使得從首
Codeforces Round #506 (Div. 3) C. Maximal Intersection
htm multiset rip namespace next msu == nec -i C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabyte
Codeforces Round #515 (Div. 3) C (模擬)
題意: 三種操作: L id ,將編號為id的書放在最左邊; R id,將編號為id的書放在最右邊; ?id,查詢編號為id的書左右兩邊哪一邊的數量最小,輸出最小值。 思路: 用l和r表示下一個左或右的位置,然後模擬就行了。 #include<bits/stdc++
CodeForces Round #521 (Div.3) C. Good Array
sum true copy sam pan have ++ cond math http://codeforces.com/contest/1077/problem/C Let‘s call an array good if there is an element i
CodeForces Round #521 (Div.3) C. Good Array
http://codeforces.com/contest/1077/problem/C Let's call an array good if there is an element in the array that equals to the sum of a
Codeforces Round #515 (Div. 3)C. Books Queries【模擬,思維】
C. Books Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You h
Codeforces Round #521 (Div. 3) C. Good Array
C. Good Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let's
Codeforces Round #486 (Div. 3) C. Equal Sums
OutputIf it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "
Codeforces Round #486 (Div. 3) C
傳送 題意:找出兩個序列,各刪除一個數後序列和相等,問刪除哪兩個序列的哪兩個數 題解:預處理出刪除每個數後的序列和,set存一下。 #include<bits/stdc++.h> using namespace std; int k,a,s
Codeforces Round #529 (Div. 3) C. Powers Of Two(數學????)
傳送門 題意: 給出一個整數 n ,問能否將 n 分解成 k 個數之和,且這 k 個數必須是2的冪。 如果可以,輸出"YES",並打印出任意一組解,反之輸出"NO"; 題解: 預備知識補充: 如何求出 num 最少需要多少個2的冪之和? 例如 : n
Codeforces Round #529 (Div. 3) C. Powers Of Two
http://codeforces.com/contest/1095/problem/C 題意:給n找出k個2的冪,加起來正好等於n。例如 9,4:9 = 1 + 2 + 2 + 4 思路:首先任何數都能表示成2的次冪的和,其次很容易發現,n和k都是二的次冪的情況是最基礎的,因為可以分成k個n/k,而n/