原来set,priority_queue也可以映射。。涨姿势2333

比较麻烦的应该就是判断自身回文的串是选2个还是选一个吧。

  1. #include<bits/stdc++.h>
  2. #define INF 0x7fffffff
  3. #define LL long long
  4. #define N 100005
  5. #define pill pair<int ,int >
  6. using namespace std;
  7. inline int ra()
  8. {
  9. int x=,f=; char ch=getchar();
  10. while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
  11. while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
  12. return x*f;
  13. }
  14. struct Node{
  15. int val;
  16. string s;
  17. }node[N];
  18. map<string, multiset<int > > dic;
  19. LL ans;
  20. int n,k,m;
  21. bool cmp(Node a, Node b)
  22. {
  23. return a.val>b.val;
  24. }
  25. int main()
  26. {
  27. n=ra(); m=ra();
  28. for (int i=; i<n; i++)
  29. {
  30. cin>>node[i].s>>node[i].val;
  31. dic[node[i].s].insert(node[i].val);
  32. }
  33. int k=,x=,tmp=;
  34. for (int i=; i<n; i++)
  35. {
  36. string s1=node[i].s;
  37. if (dic[s1].size()==) continue;
  38. int val=(*dic[s1].rbegin());
  39. if (val<) continue;
  40. reverse(s1.begin(),s1.end());
  41. dic[node[i].s].erase(dic[node[i].s].find(val));
  42. if (dic[s1].size()!=)
  43. {
  44. tmp=(*dic[s1].rbegin());
  45. dic[s1].erase(dic[s1].find(tmp));
  46. if (val+tmp>=)
  47. {
  48. ans+=val+tmp;
  49. if (s1==node[i].s)
  50. x=max(-tmp,x);
  51. }
  52. else if (s1==node[i].s)
  53. x=max(x,val);
  54. }
  55. else if (s1==node[i].s) x=max(val,x);
  56. }
  57. cout<<ans+x;
  58. return ;
  59. }

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. Nginx反向代理实现负载均衡配置图解

    Nginx反向代理实现负载均衡配置图解 [导读] 负载均衡配置是超大型机器需要考虑的一些问题,同时也是数据安全的一种做法,下面我来介绍在nginx中反向代理 负载均衡配置图解,大家可参考本文章来操作. ...

  2. POI 2001 Goldmine 线段树 扫描线

    题目链接 http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1350 http://main.edu.pl/en/archive/oi/8/kop ...

  3. Echarts学习宝典

    1,可以使用百度图说中的图表代码复制到option中,还可在百度图说中以可视化的方式编辑数据,调整参数和编辑样式.(也可借助百度图说更改部分样式) 2,借助网站 https://echarts.bai ...

  4. Mapreduce实例——WordCount

    实验步骤 切换目录到/apps/hadoop/sbin下,启动hadoop. cd /apps/hadoop/sbin ./start-all.sh 2.在linux上,创建一个目录/data/map ...

  5. 【Winform】键 盘 事 件

    private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) { , (, (, (, ( }; //回车 Backsp ...

  6. 安装数据库Typical path for xclock: /usr/X11R6/bin/xclock 错误问题

    [oracle@localhost database]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp spa ...

  7. 时间戳,秒级,毫秒级转换DateTime格式

    解决了本地时间和格林尼治时间差问题 function DateTimeToTp(ConvDate: TDateTime): time_t;var zi: TTimeZoneInformation;be ...

  8. [题解] UVA11426 GCD - Extreme (II)

    题面 莫反是不可能莫反的,这辈子都不可能莫反了 题目要求的是 \[ \sum\limits_{i=1}^n \sum\limits_{j=i+1}^n \gcd(i,j) \] 稍微变个亚子 \[ \ ...

  9. 十八、React react-router4.x中:实现路由模块化、以及嵌套路由父子组件传值

    一.路由模块化(用字典定义路由,然后循环出来) 1.官方文档参考 [官方文档]https://reacttraining.com/react-router/web/guides/quick-start ...

  10. 吴裕雄--天生自然java开发常用类库学习笔记:排序及重复元素说明

    import java.util.Set ; import java.util.HashSet ; class Person{ private String name ; private int ag ...