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可以建立在前一 ...
随机推荐
- C# datagridview设置标题为汉语
正常情况下,在给datagridview绑定数据源之后,显示的是SQL语句中的栏位,如下 我们想让标题显示汉语,可以有一下两种方法 1.在SQL中设置列别名 SELECT TITLE AS '报警标题 ...
- printf函数输出格式总结
printf函数格式 函数描述: printf("[格式化字符串]", [参数链表]); 函数声明: int printf(const char *format, ...) ; 输 ...
- [Usaco2008 Mar]牛跑步
题目描述 BESSIE准备用从牛棚跑到池塘的方法来锻炼. 但是因为她懒,她只准备沿着下坡的路跑到池塘, 然后走回牛棚. BESSIE也不想跑得太远,所以她想走最短的路经. 农场上一共有M (1 < ...
- 入门OJ:扫雪
扫雪1 题目描述 大雪履盖了整个城市,市政府要求冬季服务部门尽快将一些街道(列在一份清单中)的积雪清除掉以恢复交通,整个城市由许多交叉路口和街道构成,当然任意两个交叉路口都是直接或间接连通的,清单给出 ...
- java之 Request
0x01.Request 什么是request 在Servlet API中,定义了一个HttpServletRequest接口,它继承自ServletRequest接口,专门用来封装HTTP请求消息. ...
- JavaScript中的Object类型!
3.4.8 Object 类型 ECMAScript 中的对象其实就是一组数据和功能的集合.对象通过 new 操作符后跟对象类型的名称来创建.开发者可以通过创建 Object 类型的实例来创建自己的对 ...
- 前端面试之CSS权重问题!
前端面试之CSS权重问题! 下面的权重按照从小到大来排列! 1.通用选择器(*) 2.元素(类型)选择器 权重1 3.类选择器 权重10 4.属性选择器 5.伪类 6.ID 选择器 权重100 7.内 ...
- Python Data Structure and Algorithms Tutorial
Python - Algorithm Design - Tutorialspoint https://www.tutorialspoint.com/python_data_structure/pyth ...
- list里放map list 放list
Map<String,Integer> hashMap = new HashMap<String, Integer>(); Map<String,Integer> ...
- 关于MongoDB的简单理解(二)--Java篇
一.声明 本文依赖于 MongoDB JVM DRIVERS 4.1 版本编写. 本文案例依赖于 Maven 项目管理工具. 二.本文主要讲解哪些内容? 如何连接到MongoDB 通过TLS/SSL连 ...