51Nod-1280-前缀后缀集合
来源:互联网 发布:python进入命令行模式 编辑:程序博客网 时间:2024/06/07 05:28
ACM模版
描述
题解
两个数组,一个正序一个倒序,数据结构是map,不断查找匹配就行了,没啥难度,虽然用的两重循环,但是经过剪枝,其实复杂度并不高。
代码
#include <stdio.h>#include <map>using namespace std;const int MAXN = 5e4 + 10;const int OK = 999;int A[MAXN]; // 正序int B[MAXN]; // 逆序int main(int argc, const char * argv[]){ int N; scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", A + i); B[N - 1 - i] = A[i]; } long long ans = 0; int res = 0; int tag = 0; map<int, int> AM; map<int, int> BM; for (int i = 0; i < N; i++) { map<int, int>::iterator it = AM.find(A[i]); if (it != AM.end()) { ans += res; continue; } AM[A[i]] = OK; bool flag = false; res = 0; for (int j = tag; j < N; j++) { map<int, int>::iterator it = AM.find(B[j]); if (it == AM.end()) { break; } if (flag) { res++; continue; } BM[B[j]] = OK; if (BM.size() == AM.size()) { res++; tag = j; flag = true; } } ans += res; } printf("%lld\n", ans); return 0;}
参考
《ACM/ICPC竞赛之STL–map》
0 0
- 51Nod-1280-前缀后缀集合
- 51nod 1280 前缀后缀集合
- 51nod-1280 前缀后缀集合
- 51nod 1280 前缀后缀集合(set)
- 51nod 1280 前缀后缀集合
- 51Nod- 1280-前缀后缀集合(map)
- 1280 前缀后缀集合
- 51NOD1280 前缀后缀集合
- 前缀后缀集合
- 51Nod-1422-沙拉酱前缀
- 51Nod-1352-集合计数
- 51nod 1344 【前缀和】
- ACM水题--字符串的前缀和后缀
- 51nod 1422:沙拉酱前缀
- 51nod 1422 沙拉酱前缀
- 51nod-1422 沙拉酱前缀
- 51nod-1422:沙拉酱前缀
- 51nod 1572 宝岛地图(前缀和)
- 【Codeforces Round #369 (Div. 2)】Codeforces 711A Bus to Udayland
- 微信支付官方SDK调通
- NSIS学习笔记三-中文测试
- SPA单页面应用
- SOCKET基础讲解
- 51Nod-1280-前缀后缀集合
- 711D
- 实现memove
- FreeWAF开源的WEB应用防火墙免邀请码下载
- 苹果app上传AppStore因为IPv6被拒绝,本地搭建IPv6测试环境
- 用__attribute__((deprecated))管理过时的代码
- 20160830MYSQL的密码更改基本操作
- post和get传值
- 手机充电器原理