原来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的更多相关文章

  1. 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 ...

  2. Santa Claus and a Palindrome

    Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...

  3. 【Codeforces752D】Santa Claus and a Palindrome [STL]

    Santa Claus and a Palindrome Time Limit: 20 Sec  Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个a ...

  4. 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 ...

  5. 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 ...

  6. [CF752D]Santa Claus and a Palindrome(优先队列,贪心乱搞)

    题目链接:http://codeforces.com/contest/752/problem/D 题意:给长度为k的n个字符串,每一个字符串有权值,求构造一个大回文串.使得权值最大. 因为字符串长度都 ...

  7. Codeforces 748D Santa Claus and a Palindrome

    雅礼集训期间我好像考完试就开始划水了啊 给出k个长度相同的字符串,每个串有一个权值,选出一些串连成一个回文串.使得选中的串的总权值最大. 如果选一个串,必须同时选一个对称的串.还有一个特殊情况是可以在 ...

  8. CodeForces - 748D Santa Claus and a Palindrome (贪心+构造)

    题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的 ...

  9. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. DotNetSpeech----文本转wave语音文件

    wav操作引入dll(DotNetSpeech.dll),引入以后需要选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型”设置为False.不然会提示无法嵌入互操作类型"Spee ...

  2. 【Luogu4448】 [AHOI2018初中组]球球的排列

    题意 有 \(n\) 个球球,每个球球有一个属性值 .一个合法的排列满足不存在相邻两个球球的属性值乘积是完全平方数.求合法的排列数量对 \(10^9+7\) 取膜. \(n\le 300\) (本题数 ...

  3. 【转】WdatePicker日历控件使用方法

    转                自:   https://www.cnblogs.com/yuhanzhong/archive/2011/08/10/2133276.html WdatePicke官 ...

  4. 用 Heapster 监控集群【转】

    Heapster 是 Kubernetes 原生的集群监控方案.Heapster 以 Pod 的形式运行,它会自动发现集群节点.从节点上的 Kubelet 获取监控数据.Kubelet 则是从节点上的 ...

  5. C++面试常见问题——12虚函数

    虚函数 虚函数的工作原理 虚函数的实现要求对象携带额外的信息,这些信息用于确定运行时调用哪一个虚函数,这一信息具有一种被称为虚函数表指针(vptr)的指针形式.vptr指向一个被称为虚函数表(vtbl ...

  6. windows系统下使用mycat实现mysql数据库的主从复制,从而实现负载均衡

    在之前有记录过在一台系统中安装多台数据库,同时实现主从复制,但是那个主从复制只是一个基于dosc命令的,再实际的开发中我们不会去直接连接数据库,一般情况下我们也是通过间接的采用一些中间件去连接,本来是 ...

  7. 在html中创建自定义标签

    创建并使用自定义标签 Web Components 标准非常重要的一个特性是,它使开发者能够将HTML页面的功能封装为 custom elements(自定义标签),本篇介绍使用 CustomElem ...

  8. PHP截取指定字符前的字符串

    $str = 'A|B||C|D'; echo substr($str,0,strpos($str, '||')); 输出:A|B

  9. other#nginx配置

    #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice; #error ...

  10. tools.sublime.ConvertToUTF8

    sublime乱码,GBK乱码,安装插件ConvertToUTF8 下载ConvertToUTF8,解压,文件夹命名为ConvertToUTF8 sublime->Preferences-> ...