codeforces 1045I Palindrome Pairs 【stl+构造】
题目:戳这里
题意:给1e5个字符串,问有多少对字符串组合,满足最多只有一种字符有奇数个。
解题思路:每种情况用map存一下就行了。感觉这题自己的代码思路比较清晰,所以写个题解记录一下
附ac代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 const int maxn = 2e5 + 10;
5 const ll mod = 998244353;
6 int arr[33];
7 int nu[maxn];
8 int now;
9 string st;
10 map<int, int> mp;
11 int main() {
12 ios::sync_with_stdio(false);
13 int n;
14 cin>>n;
15 for(int i = 1; i <= n; ++i) {
16 memset(arr,0,sizeof(arr));
17 cin>>st;
18 now=0;
19 for(int j = 0; j < st.size(); ++j) {
20 arr[st[j]-'a']++;
21 }
22 for(int j = 0; j < 26; ++j) {
23 if(arr[j]&1) now += 1<<j;
24 }
25 ++mp[now];
26 nu[i] = now;
27 }
28
29 int od = 0;
30 ll ans = 0;
31
32 for(int i = 1; i <= n; ++i) {
33 od = 0;
34 for(int j = 0; j < 26; ++j) {
35 if(nu[i]&(1<<j)) ++od;
36 }
37 if(od == 0) {
38 ans += mp[nu[i]] - 1;
39 for(int j = 0; j < 26; ++j) {
40 ans += mp[1<<j];
41 }
42 }
43 else {
44 ans += mp[nu[i]] - 1;
45 for(int j = 0; j < 26; ++j) {
46 ans += mp[nu[i]^(1<<j)];
47 }
48 }
49 }
50 printf("%lld\n", ans / 2ll);
51 return 0;
52 }
codeforces 1045I Palindrome Pairs 【stl+构造】的更多相关文章
- Codeforces 159D Palindrome pairs
http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...
- DP VK Cup 2012 Qualification Round D. Palindrome pairs
题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...
- Codeforces 486C Palindrome Transformation(贪心)
题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...
- LeetCode 336. Palindrome Pairs
原题链接在这里:https://leetcode.com/problems/palindrome-pairs/ 题目: Given a list of unique words, find all p ...
- 336. Palindrome Pairs(can't understand)
Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that t ...
- 【题解】Palindrome pairs [Codeforces159D]
[题解]Palindrome pairs [Codeforces159D] 传送门:\(Palindrome\) \(pairs\) \([CF159D]\) [题目描述] 给定一个长度为 \(N\) ...
- [Codeforces 1246B] Power Products (STL+分解质因数)
[Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...
- leetcode 132 Palindrome Pairs 2
lc132 Palindrome Pairs 2 大致与lc131相同,这里要求的是最小分割方案 同样可以分割成子问题 dp[i][j]还是表示s(i~j)是否为palindrome res[i]则用 ...
- leetcode 131 Palindrome Pairs
lc131 Palindrome Pairs 解法1: 递归 观察题目,要求,将原字符串拆成若干子串,且这些子串本身都为Palindrome 那么挑选cut的位置就很有意思,后一次cut可以建立在前一 ...
随机推荐
- 利用iptables防火墙保护web服务器
实例:利用iptables防火墙保护web服务器 防火墙--->路由器-->交换机-->pc机 配置之前,清空下已有的规则,放在规则冲突不生效 工作中,先放行端口写完规则,再DROP ...
- Table controls and tabstrip controls
本文转载自http://www.cnblogs.com/clsoho/archive/2010/01/21/1653268.html ONTROLS Syntax Forms Declaration ...
- Springmvc中参数的绑定
.处理器适配器在执行Handler之前需要把http请求的key/value数据绑定到Handler方法形参数上. 1.默认支持的参数类型: HttpServletRequest,HttpServle ...
- Markdown特殊字符、数学公式汇总
引自:https://blog.csdn.net/weixin_39653948/article/details/104621249
- CSS3+JS完美实现放大镜模式
最近看到一篇讲放大镜的文章,实践后感觉效果非常好,这里分享给大家. 效果如下: 其实现核心: CSS函数,如:calc() -- 动态计算:var() -- 使用自定义变量 CSS伪元素:::befo ...
- 【Azure 应用服务】App Service中,为Java应用配置自定义错误页面,禁用DELETE, PUT方法
问题定义 使用Azure应用服务(App Service),部署Java应用,使用Tomcat容器,如何自定义错误页面呢?同时禁用DELETE, PUT方法 解决办法 如何自定义错误页面呢?需要在 J ...
- Apache环境下强制http跳转至https的配置总结
一. 简单实例介绍一般来说,apache配置好http和https后,如果想要做http强转到https,需要设置url重定向规则,大致需要下面几个步骤即可完成配置: 1)在httpd.conf文件里 ...
- 为什么Go自带的日志默认输出到os.Stderr?
为什么Go自带的日志默认输出到os.Stderr? - 知乎 https://www.zhihu.com/question/67629357 Note that the Go runtime writ ...
- Page (computer memory) Memory segmentation Page table 虚拟地址到物理地址的转换
A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described ...
- proc/net/tcp中各项内容的含义