TLE求优化

P1808 单词分类

@[zhicheng](/user/393934) 你这个显然是常数大的n方 用string+map/set
by WanderingTrader @ 2021-02-21 22:28:54


谢谢
by zhicheng @ 2021-02-22 10:18:28


@[zhicheng](/user/393934) 我的代码,希望能够帮到你! ```cpp // ---------- P1808 ---------- #include <iostream> #include <string> #include <algorithm> #include <set> std::set<std::string> ss; std::string s; int n, i; int main(){ std::cin >> n; for (i = 0; i < n; i++){ std::cin >> s; sort(s.begin(), s.end()); ss.insert(s); } std::cout << ss.size() << std::endl; return 0; } ``` 解释:我的代码使用了STL模版set,利用的是set的特性(自动去重和排序)。
by L_G_T @ 2021-08-31 16:44:12


谢谢你!
by zhicheng @ 2021-08-31 21:55:38


|