日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

贪心 BestCoder Round #39 1001 Delete

發布時間:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 贪心 BestCoder Round #39 1001 Delete 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

題目傳送門

1 /* 2 貪心水題:找出出現次數>1的次數和res,如果要減去的比res小,那么總的不同的數字tot不會少; 3 否則再在tot里減去多余的即為答案 4 用set容器也可以做,思路一樣 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <algorithm> 11 using namespace std; 12 13 const int MAXN = 1e4 + 10; 14 const int INF = 0x3f3f3f3f; 15 int cnt[110]; 16 17 int main(void) //BestCoder Round #39 1001 Delete 18 { 19 //freopen ("1001.in", "r", stdin); 20 21 int n; 22 while (scanf ("%d", &n) == 1) 23 { 24 int k; 25 memset (cnt, 0, sizeof (cnt)); 26 27 int tot = 0, res = 0, x; 28 for (int i=1; i<=n; ++i) 29 { 30 scanf ("%d", &x); 31 if (cnt[x] == 0) tot++; 32 else if (cnt[x] >= 1) res++; 33 cnt[x]++; 34 } 35 36 scanf ("%d", &k); 37 if (res >= k) printf ("%d\n", tot); 38 else printf ("%d\n", tot - (k - res)); 39 } 40 41 return 0; 42 } 1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <set> 7 using namespace std; 8 9 int main(void) //BestCoder Round #39 1001 Delete 10 { 11 //freopen ("1001.in", "r", stdin); 12 13 set<int> S; 14 int n, k; 15 16 while (cin >> n) 17 { 18 S.clear (); 19 int x; 20 for (int i=1; i<=n; ++i) 21 { 22 cin >> x; S.insert (x); 23 } 24 25 cin >> k; 26 cout << ((n-S.size () <= k) ? n - k : S.size ()) << endl; 27 } 28 29 return 0; 30 } 使用set容器

?

轉載于:https://www.cnblogs.com/Running-Time/p/4459855.html

總結

以上是生活随笔為你收集整理的贪心 BestCoder Round #39 1001 Delete的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。