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 ...
随机推荐
- 车林通购车之家--购车计算器模块js实现
//jsq-nav.twig <ul class="switch-nav db-tags bgfff clearfix"> <li id="qk&quo ...
- zabbix4.4安装 centos7+mysql+Nginx
1.安装数据源 # rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch. ...
- FTP 服务器在WIN10上的搭建及服务端下载文件实例
1.搭建 (1)控制面板--->程序----->将FTP服务器打勾 (2)输入iis,或者右键桌面-->管理-->服务和应用程序--->internet informat ...
- springboot官网->pom.xml文件
springboot 2.1.6 pom.xml
- sizeof strlen 求char*字符串的长度
sizeof只是求变量所占的字节数,sizeof(char *) = 4字节: strlen(char*) 可以得到整个字符串的长度. 如果是数组vec,那么使用sizeof就可以得到整个数组的所占的 ...
- Linux动静态库
gcc编译过程 预处理,gcc -E,.c->.i 展开宏和头文件,替换条件编译,删除注释.空白和空行 编译, gcc -S,.i -> .s 检查语法规范 [消耗时间和系统资源最多] 汇 ...
- uboot源码分析1-启动第一阶段
1.不简单的头文件包含 #include <config.h>:这个文件的内容其实是包含了一个头文件:#include <configs/x210_sd.h>". # ...
- Centos7忘记mysql的root用户密码
1.先停止mysql服务 [root@CentOS ~]# ps -ef | grep mysql root : pts/ :: /bin/sh /usr/local/mysql/bin/mysql ...
- POJ 2785:4 Values whose Sum is 0 二分
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 18221 Accep ...
- HihoCoder第九周 状态压缩 二 与POJ2411总结
在此我向各位博友求助,特别想知道除了HihoCoder上面的结果要对1e9+7取余之外,这两道题还有什么其他的问题,都是骨牌覆盖问题,都是状态压缩+dp,为什么我能过poj2411的程序过不了Hiho ...