排序+链表 CF——752D
来源:互联网 发布:游戏配乐知乎 编辑:程序博客网 时间:2024/05/21 07:02
725D
刚拿到题目一脸懵逼
10万个数字长度十万??????
哦……字符总数小于十万
妈的吓死了,还以为输入要超时了
构造一个回文串,显然的是,我们可以把两个相反的字符串加到一个回文串的两侧,构成新的回文串。
就这个思路,直接开map离散字符串,然后找一下,如果大于0就加上去,以及:可以在中间放一个本身是回文串的字符串
然后,对于多个相同的字符串的处理方法,显然越大越好
所以我们先对所有输入排序,然后挂链表
嗯……数组模拟链表
然后就可以做了,不知道为什么联想到当前弧优化(逃
以及一个有趣的问题:如果有两个是回文串的字符串,我们是加到两侧还是加一个到中间?
听起来要很多特判的样子。。。
其实不用
我们开一个变量ans1存中间那个字符串的贡献
例如xyz -1,xyz 2这样,我们可以直接把他们放在两侧,然后ans1=max(ans1,-(-1))
为什么?这样相当于把一个去掉,然后把另外一个放到中间去
可以保证中间只有一个
然后。。我WA了两次
至今不知道发生了什么= =???理论上没区别啊
???
算了。。。OI的世界是玄学的
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<queue>#include<string>#include<map>#include<cstring>#include<ctime>#include<vector>#define inf 1e9#define ll long long#define For(i,j,k) for(int i=j;i<=k;i++)#define Dow(i,j,k) for(int i=k;i>=j;i--)using namespace std;struct node{string s;int v;}t[100001];map<string,int> mp;inline bool cmp(node x,node y){return x.v<y.v;}int f[300001],nxt[300001],poi[300001],ans,ans1,n,k,tot,cnt;int main(){ios::sync_with_stdio(false);cin>>n>>k;For(i,1,n)cin>>t[i].s>>t[i].v;sort(t+1,t+n+1,cmp);For(i,1,n){if(!mp[t[i].s]){mp[t[i].s]=++tot;poi[++cnt]=t[i].v;nxt[cnt]=0;f[tot]=cnt;}else {int tmp=mp[t[i].s];poi[++cnt]=t[i].v;nxt[cnt]=f[tmp];f[tmp]=cnt;}}Dow(i,1,n){string ts;Dow(j,0,k-1)ts+=t[i].s[j];if(ts==t[i].s){int tmp=mp[ts];if(tmp&&f[tmp]&&nxt[f[tmp]]){int v=poi[f[tmp]]+poi[nxt[f[tmp]]];if(v>0)ans+=v,ans1=max(ans1,-poi[nxt[f[tmp]]]),f[tmp]=nxt[nxt[f[tmp]]];else ans1=max(ans1,poi[f[tmp]]);}else if(tmp&&f[tmp]){ans1=max(ans1,poi[f[tmp]]);}}else {int tmp=mp[ts],tmp1=mp[t[i].s];if(tmp&&f[tmp]&&f[tmp1]){int v=poi[f[tmp1]]+poi[f[tmp]];if(v>0)ans+=v,f[tmp]=nxt[f[tmp]],f[tmp1]=nxt[f[tmp1]];}}}printf("%d",ans1+ans);}
阅读全文
0 0
- 排序+链表 CF——752D
- 数学——cf 735 D
- 图论——cf 699 D
- CF-12D - Ball(排序+MAP)
- CF 274D Lovely Matrix(拓扑排序)
- cf 274D Lovely Matrix 拓扑排序
- CF 632D(Longest Subsequence-计数排序)
- CF 274D Lovely Matrix(拓扑排序)
- CF 369 div 2 —D 搜索+组合数
- CF 417D Cunning Gena [状压dp+排序]
- CF 412 D Giving Awards(拓扑排序)
- CF——289D(推不出来就找规律吧)
- 【打CF,学算法——一星级】CodeForces 617D Polyline(水题)
- 【打CF,学算法——三星级】CodeForces 567D One-Dimensional Battle Ships (二分)
- 【打CF,学算法——三星级】CodeForces 550D Regular Bridge (构造)
- 【打CF,学算法——五星级】CodeForces 478D (dp计数)
- CF——Codeforces Round #428 (Div. 2)D. Winter is here
- CF D. Buses
- JavaBean,EL表达式和JSTL的介绍
- Redis数据库--快速入门手册
- 守护进程理解与创建
- 怎么查看电脑主板是否支持UEFI+GPT启动模式
- Win10上的git、github部署及基本使用方法
- 排序+链表 CF——752D
- qcom smgr的attr概述
- 30.根据程序当前界面找出对应活动-活动实践
- 为Cubieboard2构建自己的的Debian Linux的步骤(2)(分色排版)下载cb2的内核==
- CTF安卓逆向练习第三弹
- Spring mvc interceptor配置拦截器
- SYD8801 ADC使用说明【校准】
- centos6.7下ngnix1.8+tomcat8+memcached1.4.25 集群实现session共享
- SIM800A模块进行HTTP的GET和POST操作