题目:戳这里

题意:给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+构造】的更多相关文章

  1. Codeforces 159D Palindrome pairs

    http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...

  2. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  3. Codeforces 486C Palindrome Transformation(贪心)

    题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要 ...

  4. LeetCode 336. Palindrome Pairs

    原题链接在这里:https://leetcode.com/problems/palindrome-pairs/ 题目: Given a list of unique words, find all p ...

  5. 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 ...

  6. 【题解】Palindrome pairs [Codeforces159D]

    [题解]Palindrome pairs [Codeforces159D] 传送门:\(Palindrome\) \(pairs\) \([CF159D]\) [题目描述] 给定一个长度为 \(N\) ...

  7. [Codeforces 1246B] Power Products (STL+分解质因数)

    [Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...

  8. leetcode 132 Palindrome Pairs 2

    lc132 Palindrome Pairs 2 大致与lc131相同,这里要求的是最小分割方案 同样可以分割成子问题 dp[i][j]还是表示s(i~j)是否为palindrome res[i]则用 ...

  9. leetcode 131 Palindrome Pairs

    lc131 Palindrome Pairs 解法1: 递归 观察题目,要求,将原字符串拆成若干子串,且这些子串本身都为Palindrome 那么挑选cut的位置就很有意思,后一次cut可以建立在前一 ...

随机推荐

  1. 爬虫-使用lxml解析html数据

    使用lxml之前,我们首先要会使用XPath.利用XPath,就可以将html文档当做xml文档去进行处理解析了. 一.XPath的简单使用: XPath (XML Path Language) 是一 ...

  2. oracle常用hint添加

    1.视图添加索引 /* Formatted on 2020/1/6 下午 04:46:37 (QP5 v5.163.1008.3004) */ SELECT /*+index(VIEW_NAME.TA ...

  3. 使用memory_profiler异常

    在使用memory_profiler模块0.55.0版本执行命令诊断程序内存用量时,遇到下面错误: C:\Users\Chen\Desktop\python_doc\第四模块课件>python ...

  4. 24V转5V稳压芯片,高效率的同步降压DC-DC变换器3A输出电流

    PW2330开发了一种高效率的同步降压DC-DC变换器3A输出电流.PW2330在4.5V到30V的宽输入电压范围内工作集成主开关和同步开关,具有非常低的RDS(ON)以最小化传导损失.PW2330采 ...

  5. Python安装教程之anaconda篇

    [导读]我们知道,Python的功能非常强大.那么对于迫切想学习Python的新手同学来说,第一件事情可能需要了解python是什么?能用来做什么?语法结构是怎样的?这些我们几句话很难介绍清楚,后续会 ...

  6. 转 10 jmeter之动态关联

    10 jmeter之动态关联   jmeter中关联是通过之前请求的后置处理器实现的,具体有两种方式:XPath Extractor(一般xml的时候用的多)和正则表达式提取器. 以webtours登 ...

  7. jquery 数据查询

    jquery 数据查询 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  8. Intellij idea 报错:Error : java 不支持发行版本5

    保证下面几个地方编译版本一致: 分两步: 第一步,进入Project Structure中设置Project JDK 以及Project Level ,高于JDK5版本 第二步,进入设置中将项目的JD ...

  9. ETL优化(转载)

    1.引言 数据仓库建设中的ETL(Extract, Transform, Load)是数据抽取.转换和装载到模型的过程,整个过程基本是通过控制用SQL语句编写的存储过程和函数的方式来实现对数据的直接操 ...

  10. 小米开源监控系统Open-Falcon安装使用笔记

    小米开源监控系统Open-Falcon安装使用笔记-BB保你大-51CTO博客 https://blog.51cto.com/chenguomin/1865550