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 ...
随机推荐
- Nginx反向代理实现负载均衡配置图解
Nginx反向代理实现负载均衡配置图解 [导读] 负载均衡配置是超大型机器需要考虑的一些问题,同时也是数据安全的一种做法,下面我来介绍在nginx中反向代理 负载均衡配置图解,大家可参考本文章来操作. ...
- POI 2001 Goldmine 线段树 扫描线
题目链接 http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1350 http://main.edu.pl/en/archive/oi/8/kop ...
- Echarts学习宝典
1,可以使用百度图说中的图表代码复制到option中,还可在百度图说中以可视化的方式编辑数据,调整参数和编辑样式.(也可借助百度图说更改部分样式) 2,借助网站 https://echarts.bai ...
- Mapreduce实例——WordCount
实验步骤 切换目录到/apps/hadoop/sbin下,启动hadoop. cd /apps/hadoop/sbin ./start-all.sh 2.在linux上,创建一个目录/data/map ...
- 【Winform】键 盘 事 件
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) { , (, (, (, ( }; //回车 Backsp ...
- 安装数据库Typical path for xclock: /usr/X11R6/bin/xclock 错误问题
[oracle@localhost database]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp spa ...
- 时间戳,秒级,毫秒级转换DateTime格式
解决了本地时间和格林尼治时间差问题 function DateTimeToTp(ConvDate: TDateTime): time_t;var zi: TTimeZoneInformation;be ...
- [题解] UVA11426 GCD - Extreme (II)
题面 莫反是不可能莫反的,这辈子都不可能莫反了 题目要求的是 \[ \sum\limits_{i=1}^n \sum\limits_{j=i+1}^n \gcd(i,j) \] 稍微变个亚子 \[ \ ...
- 十八、React react-router4.x中:实现路由模块化、以及嵌套路由父子组件传值
一.路由模块化(用字典定义路由,然后循环出来) 1.官方文档参考 [官方文档]https://reacttraining.com/react-router/web/guides/quick-start ...
- 吴裕雄--天生自然java开发常用类库学习笔记:排序及重复元素说明
import java.util.Set ; import java.util.HashSet ; class Person{ private String name ; private int ag ...