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 ...
随机推荐
- MAC电脑如何播放.SWF文件
很简单,不需要专门的播放器,只需要将.swf文件直接拖拽到浏览器页面就可以播放了. 亲测safari , 谷歌chrome浏览器,火狐浏览器 ,都是可以的 下面是图示 step1 电脑上找到swf文件 ...
- Tornado -- 7 - 查询结果
查询结果 查询结果总结: 条件查询 多表查询
- PE文件中找导出表
导出表: typedef struct _IMAGE_EXPORT_DIRECTORY { DWORD Characteristics; // 未使用,总为0 DWORD TimeDateStamp; ...
- (转)CentOS/Debian/Ubuntu系统 TCP-BBR 一键安装脚本
本脚本适用环境 系统支持:CentOS 6+,Debian 7+,Ubuntu 12+ 虚拟技术:OpenVZ 以外的(KVM.Xen.VMware等) 内存要求:≥128M 日期 :2017 年 0 ...
- android侧滑效果(引用官方网站提供的API文件)
原文地址:http://www.cnblogs.com/android100/p/android-SlidingMenu.html 在新浪微博和唱吧里面都有看到android的侧滑效果,于是想要学习一 ...
- javascript判断数组是否包含了指定的元素
jQuery写法: var arr = [ "xml", "html", "css", "js" ]; $.inArra ...
- 剑指offer自学系列(五)
题目描述:请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读出 ...
- scanf与正则表达式的搭配及应用
scanf与正则表达式的搭配及应用 正则其实我也学的不咋地,只会一点皮毛,正则最大的作用就是当输入流是一个字符串,我们能在输入的时候就滤掉无用信息,省去后期提取数值的步骤. 正则的语法我怕误人子弟,嘿 ...
- a标签-伪类
a:link {color: #FF0000} /* 未访问的链接 */ a:visited {color: #00FF00} /* 已访问的链接 */ a:hover {color: #FF00FF ...
- Exchange Server备份与恢复
本文档描述了Exchange 2003.Exchange Server 2007/2010的备份与恢复操作,涉及的内容包括: 1.使用NTBackup 备份与恢复Exchange 2007/2003 ...