标签:周赛 string 46 cin int str include unordered Acwing
第2题:AcWing 4397. 卡牌
卡住的点:不用具体实现翻牌、记录编号的操作,只需求d[i]=b[i]-a[i],之后将d排序,当d[i]>0时,不选,反之则选。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 200010;
int n, m;
int a[N], b[N], d[N];
int main()
{
cin >> n >> m;
int sum = 0;
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]), sum += a[i];
for (int i = 1; i <= n; i ++ ) scanf("%d", &b[i]), d[i] = b[i] - a[i];
sort(d + 1, d + n + 1);
for(int i = 1; i <= n - m; i ++ ) //最多能翻n-m次
if(d[i] >= 0) break;
else sum += d[i];
printf("%d\n", sum);
return 0;
}
第3题:AcWing 4398. 查询字符串
哈希即可
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main()
{
unordered_map<string, int> cnt;
unordered_map<string, string> hash;
int n, m;
cin >> n;
while (n -- )
{
unordered_set<string> S;
string str;
cin >> str;
for(int i = 0; i < str.size(); i ++ )
{
string s;
for(int j = i; j < str.size(); j ++ )
{
s += str[j];
S.insert(s);
}
}
for(auto& word: S)
{
cnt[word] ++;
hash[word] = str;
}
}
cin >> m;
while (m -- )
{
string str;
cin >> str;
cout << cnt[str] << " ";
if(!cnt[str]) puts("-");
else cout << hash[str] << endl;
}
return 0;
}
标签:周赛,string,46,cin,int,str,include,unordered,Acwing 来源: https://www.cnblogs.com/esico/p/16127116.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。