cf 478D.Santa Claus and a Palindrome
原来set,priority_queue也可以映射。。涨姿势2333
比较麻烦的应该就是判断自身回文的串是选2个还是选一个吧。
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define LL long long
#define N 100005
#define pill pair<int ,int >
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
struct Node{
int val;
string s;
}node[N];
map<string, multiset<int > > dic;
LL ans;
int n,k,m;
bool cmp(Node a, Node b)
{
return a.val>b.val;
}
int main()
{
n=ra(); m=ra();
for (int i=; i<n; i++)
{
cin>>node[i].s>>node[i].val;
dic[node[i].s].insert(node[i].val);
}
int k=,x=,tmp=;
for (int i=; i<n; i++)
{
string s1=node[i].s;
if (dic[s1].size()==) continue;
int val=(*dic[s1].rbegin());
if (val<) continue;
reverse(s1.begin(),s1.end());
dic[node[i].s].erase(dic[node[i].s].find(val));
if (dic[s1].size()!=)
{
tmp=(*dic[s1].rbegin());
dic[s1].erase(dic[s1].find(tmp));
if (val+tmp>=)
{
ans+=val+tmp;
if (s1==node[i].s)
x=max(-tmp,x);
}
else if (s1==node[i].s)
x=max(x,val);
}
else if (s1==node[i].s) x=max(val,x);
}
cout<<ans+x;
return ;
}
cf 478D.Santa Claus and a Palindrome的更多相关文章
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Santa Claus and a Palindrome
Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...
- 【Codeforces752D】Santa Claus and a Palindrome [STL]
Santa Claus and a Palindrome Time Limit: 20 Sec Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个a ...
- Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CF 752C. Santa Claus and Robot
C. Santa Claus and Robot time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- [CF752D]Santa Claus and a Palindrome(优先队列,贪心乱搞)
题目链接:http://codeforces.com/contest/752/problem/D 题意:给长度为k的n个字符串,每一个字符串有权值,求构造一个大回文串.使得权值最大. 因为字符串长度都 ...
- Codeforces 748D Santa Claus and a Palindrome
雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在 ...
- CodeForces - 748D Santa Claus and a Palindrome (贪心+构造)
题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的 ...
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- 获取JSHANDLE句柄
A string can also be passed in instead of a function: const aHandle = await page.evaluateHandle('doc ...
- eot文件
*.eot文件 是一种压缩字库,目的是解决在网页中嵌入特殊字体的难题2.在网页中嵌入的字体只能是 OpenType 类型,其他类型的字体只有转换成 OpenType 类型(eot格式)的字体才能在网页 ...
- 2.13 阶段实战 使用layui重构选课系统
一.说在前面 昨天 学习表单校验插件validate,并使用ajax 自定义校验规则 今天 使用layui重构选课系统 二.题目要求 1.项目需求: 本项目所开发的学生选课系统完成学校对学生 ...
- ubuntu18.04窗口截图和选区截图快捷键
解决方法: 1.点击左下角的系统设置. 2.点击设备. 3.点击键盘,可查看各种截图操作的快捷键. PS:双击图中的快捷键可以设置新的快捷键.
- k8s 各种网络方案【转】
网络模型有了,如何实现呢? 为了保证网络方案的标准化.扩展性和灵活性,Kubernetes 采用了 Container Networking Interface(CNI)规范. CNI 是由 Core ...
- SQLyog连接报错 Error No.2058 Plugin caching_sha2_password could not be loaded
参考链接:https://blog.csdn.net/qq_22766431/article/details/80628583 win10系统更新安装Mysql8.0,连接SQLyog的时候出现下面错 ...
- vue - 子组件向父组件 传递方法和参数
1,子组件 TodoItem.vue : <template> <div class="todo-item" :class="{'is-compl ...
- tomcat-性能?
http://www.cnblogs.com/zhuawang/p/5213788.html http://www.cnblogs.com/zhuawang/p/5213192.html http:/ ...
- 配置gem5-gpu docker版
1 安装docker:wget -qO- https://get.docker.com/ | sh,启动服务:sudo service docker start 2 把非root用户添加到docker ...
- delphi http请求用到的编码方式
uses HttpEncode: HttpEncode(AnsiToUtf8('***'))