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可以建立在前一 ...
随机推荐
- 词嵌入之FastText
什么是FastText FastText是Facebook于2016年开源的一个词向量计算和文本分类工具,它提出了子词嵌入的方法,试图在词嵌入向量中引入构词信息.一般情况下,使用fastText进行文 ...
- Android 8.0/9.0 wifi 自动连接评分机制
前言 Android N wifi auto connect流程分析 Android N selectQualifiedNetwork分析 Wifi自动连接时的评分机制 今天了解了一下Wifi自动连接 ...
- c++11之override关键字
明确是用来 覆盖 用来对虚函数的 从新实现 加上后编译器就会帮我们去检查这个语法 总结就是:c++11允许派生类显示的注明它将使用那个成员函数改写基类的虚函数 https://blog.csdn. ...
- Python爬虫学习笔记(三)
Cookies: 以抓取https://www.yaozh.com/为例 Test1(不使用cookies): 代码: import urllib.request # 1.添加URL url = &q ...
- java关键字static使用总结
java关键字static使用总结 1.static修饰的方法被称之为静态方法也叫做类方法,加static的方法,可以通过类名直接访问,不加static的方法只能通过对象名访问. 静态方法可以直接通过 ...
- ThinkPHP 漏洞利用
ThinkPHP thinkphp_5x_命令执行漏洞 受影响版本包括5.0和5.1版本 docker漏洞环境源码: https://github.com/vulnspy/thinkphp-5.1.2 ...
- 《aspose》 word表格循环导出图片
废话不多说,直接上代码,网上代码都不能用,迫不得已,最后查询了官网的源码.上菜! 模板文件可以自己去github去下载. package com.aspose.words.examples.mail_ ...
- dedecms万能SQL标签使用方法大全
注意:dede_archives这是系统默认的数据库表,如果你修改过表前缀dede_,请自行更改表名.在以下示例的标签中,有一部分只写出了SQL语句,具体的完整标签写法请参考:织梦SQL标签调用方法. ...
- springboot注解开发
可以毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我都说了具体用法,掌握搞懂,使用 SpringBoot 来开发项 ...
- sqoop使用以及常见问题
1.hdfs文件的权限问题 问题分析与解决: 根据报错信息是hdfs文件的权限问题,命令进入集群执行的用户为null,而hdfs文件所有者为hdfs. 要么以用户hdfs执行命令,要么调整hdfs文件 ...