题目:戳这里

题意:给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. 定制个性化的GUI

    你现在还在使用SAP GUI710或者是GUI720,又或者更早的640等吗?那么古董先生,推荐您使用GUI730吧,您可能会730好在哪?那我建议您去百度或者Google问吧.对于新的GUI730, ...

  2. Building a Robust Live Reloader with WebSockets and Go — Brandur Leach https://brandur.org/live-reload

    Building a Robust Live Reloader with WebSockets and Go - Brandur Leach https://brandur.org/live-relo ...

  3. 等待 Redis 应答 Redis pipeline It's not just a matter of RTT

    小结: 1.When pipelining is used, many commands are usually read with a single read() system call, and ...

  4. C++学习之STL(二)String

    1.assign assign方法可以理解为先将原字符串清空,然后赋予新的值作替换. 返回类型为 string类型的引用.其常用的重载也有下列几种: a. string& assign ( c ...

  5. cookie,session,token傻傻分不清

    什么是认证(Authentication) • 通俗地讲就是验证当前用户的身份,证明"你是你自己"(比如:你每天上下班打卡,都需要通过指纹打卡,当你的指纹和系统里录入的指纹相匹配时 ...

  6. codevs 1344 模拟退火

    1344 线型网络  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamo   题目描述 Description 有 N ( <=20 ) 台 PC 放在机房内 ...

  7. POSTGIS

    https://blog.csdn.net/qq_35732147/article/details/85256640 官方文档:http://www.postgis.net/docs/ST_Buffe ...

  8. ThreadLocal全面解析,一篇带你入门

    ===================== 大厂面试题: 1.Java中的引用类型有哪几种? 2.每种引用类型的特点是什么? 3.每种引用类型的应用场景是什么? 4.ThreadLocal你了解吗 5 ...

  9. Redis 实战 —— 14. Redis 的 Lua 脚本编程

    简介 Redis 从 2.6 版本开始引入使用 Lua 编程语言进行的服务器端脚本编程功能,这个功能可以让用户直接在 Redis 内部执行各种操作,从而达到简化代码并提高性能的作用. P248 在不编 ...

  10. python格式转换的记录

    Python的格式转换太难了. 与其说是难,具体来说应该是"每次都会忘记该怎么处理".所以于此记录,总的来说是编码+格式转换的记录. 本文记录环境:python3.6 经常见到的格 ...