当前位置:网站首页>E. 2-Letter Strings
E. 2-Letter Strings
2022-04-22 15:13:00 【Bzdhxs_nt】
思路
对于一个字符串分别用 a [ ] , b [ ] a[],b[] a[],b[]来记录每个字符的个数,以及字符串的个数
对答案的贡献就是 在这个字符串前面的 第 一 个 字 符 的 个 数 + 第 二 个 字 符 的 个 数 − 2 ∗ 字 符 串 个 数 第一个字符的个数+第二个字符的个数-2*字符串个数 第一个字符的个数+第二个字符的个数−2∗字符串个数
因为字符串本身也会贡献两个字符的个数,所以减去 2 2 2 个
int n;
ll a[N],b[N],c[N][N];
void so1ve(){
cin>>n;
ll ans = 0;
mem(a,0);mem(b,0);mem(c,0);
forr(i,1,n){
string s;
cin>>s;
int x = s[0] - 'a';
int y = s[1] - 'a';
ans += (a[x]+b[y]-c[x][y]*2LL);
a[x]++;b[y]++;c[x][y]++;
}
cout << ans << endl;
}
版权声明
本文为[Bzdhxs_nt]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51687628/article/details/124346382
边栏推荐
- 【深入理解TcaplusDB技术】更替列表指定位置数据接口说明——[List表]
- About STS access control of Alibaba cloud OSS resources
- 824. Goat Latin
- 分布式任務調度平臺XXL-JOB安裝及使用
- [World Earth Day] Huawei cloud market | witness the beautiful changes of nature with science and technology
- UART minimalist routine for raspberry PI B
- Analysis on the characteristics of the official game economic model launched by platoffarm
- 云呐|最新酒店行业固定资产管理办法,酒店实物资产管理系统
- Web自动化测试
- Watch out for spies! Safeguard national security, you and I guard together
猜你喜欢
![【深入理解TcaplusDB技术】批量读取数据示例代码——[Generic表]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
【深入理解TcaplusDB技术】批量读取数据示例代码——[Generic表]

【网络】传输层-UDP协议
![【深入理解TcaplusDB技术】更替列表指定位置数据接口说明——[List表]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
【深入理解TcaplusDB技术】更替列表指定位置数据接口说明——[List表]

TcaplusDB君 · 行业新闻汇编(五)
![【深入理解TcaplusDB技术】读取列表所有数据示例代码——[List表]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
【深入理解TcaplusDB技术】读取列表所有数据示例代码——[List表]

2022 chemical automation control instrument examination question bank and online simulation examination

职场PUA,管理者的五宗罪

About STS access control of Alibaba cloud OSS resources

Tcallusdb Jun · industry news compilation (III)
![[deeply understand tcallusdb technology] delete all data interface descriptions in the list - [list table]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[deeply understand tcallusdb technology] delete all data interface descriptions in the list - [list table]
随机推荐
基于 Traefik 的激进 TLS 安全配置实践
【深入理解TcaplusDB技术】读取数据示例代码——[Generic表]
Development trend of C in 2022
vscode处理代码合并冲突
Installation and use of distributed task scheduling platform xxl-job
【深入理解TcaplusDB技术】根据部分Key字段值读取数据示例代码——[Generic表]
There are Chinese characters in the input parameter, and an error of 500 is reported. There is an internal error in the server
[deeply understand tcallusdb technology] insert data into the specified location of the list interface description - [list table]
The GNU build system experience tutorial: Hello world example with Autoconf and automake
View your own system activation type
【模型】状态空间平均法建模-降压
[C language] learn file operation in 10 minutes
UART minimalist routine for raspberry PI B
【深入理解TcaplusDB技术】异步扫描数据示例代码——[Generic表]
【深入理解TcaplusDB技术】示例代码——异步调用接口
ROS通信机制三---参数服务器
琢磨琢磨方法引用以及lambda--白话Lambda和方法引用
[*CTF2022]oh_my_lotto_revenge
Bootsrap 模态框文字超出处理
数学史有没有必要读?关于数学教育,我们忽视了太多