当前位置: 首页 > news >正文

5.3刷题

P3370 【模板】字符串哈希

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
int n;
ull myhash(string s){ull code = 0, x = 131, y = 140814840257324663;for(int i = 0; i < s.size(); i++){code = (code * x + (ull)s[i]) % y;}return code;
}
void solve(){ull a[10010], ans, n;string s;cin >> n;for(int i = 0; i < n; i++){cin >> s;a[i] = myhash(s);}sort(a, a + n);ans = unique(a, a + n) - a;cout << ans << endl;
}
void solve1(){ull a = 0xffffffffffffffff;a = a / 131 - 131;cout << a << endl;while(1){int f = 0;for(ull i = 2; i <= a / i; i++){if(a % i == 0){f = 1;break;}}if(!f){cout << a << endl;return;}a--;}
}
signed main(){ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);solve();return 0;
}

P3405 [USACO16DEC] Cities and States S

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
map<pair<int, int>, int>mp;
int myhash(string s){int code = 0;for(int i = 0; i < 2; i++){code = code * 26 + (s[i] - 'A');}return code;
}void solve(){int ans = 0, x, y;string s, c;cin >> n;for(int i = 0; i < n; i++){cin >> c >> s;x = myhash(c);y = myhash(s);if(x == y)continue; mp[{x, y}]++;ans += mp[{y, x}];}cout << ans << endl;
}signed main(){ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);solve(); return 0;
}

http://www.dtcms.com/a/170256.html

相关文章:

  • 多元随机变量协方差矩阵
  • HTTP基础介绍+OSI七层参考模型+HTTP协议介绍
  • linux的时间轮
  • STM32部分:2-1、STM32CubeMX介绍
  • Spring Cache使用
  • Python表达式全解析:从基础到高级
  • Java多语言DApp质押挖矿盗U源码(前端UniApp纯源码+后端Java)
  • 算法每日一题 | 入门-顺序结构-数字反转
  • c++回调函数
  • Python 线程安全机制:Lock、RLock、Semaphore 的使用场景与最佳实践
  • PyTorch_创建01张量
  • Java虚拟线程基础介绍
  • 突破认知边界:神经符号AI的未来与元认知挑战
  • JAVA刷题记录: 递归,搜索与回溯
  • 纯Java实现STDIO通信的MCP Server与客户端验证
  • 普通 html 项目引入 tailwindcss
  • Go小技巧易错点100例(二十八)
  • 应用层自定义协议序列与反序列化
  • 数据赋能(209)——质量管理——时效性原则
  • 模型测试报错:有2张显卡但cuda.device_count()显示GPU卡数量只有一张
  • 昇腾的CANN是什么?跟英伟达CUDA的有什么联系和区别?【浅谈版】
  • 智能决策支持系统的系统结构:四库架构与融合范式
  • P1537 数字反转(升级版)详解
  • 【unity游戏开发入门到精通——UGUI】整体控制一个UGUI面板的淡入淡出——CanvasGroup画布组组件的使用
  • 深入探索 AAC 编码原理与 ADTS 格式:音频世界的智慧结晶
  • MCP多智能体消息传递机制(Message Passing Between Agents)
  • 注入内部Bean
  • 数据结构---
  • Scrapy框架之【settings.py文件】详解
  • Xilinx FPGA | 管脚约束 / 时序约束 / 问题解析