TOJ---1502---map真强大
2014-06-22 17:30
190 查看
这题 看上去 很无聊 但还是几乎花了一部 小电影 的时间=-=
touch me
题意 没什么好讲的.... 就是找 平方数
一开始 用了2个数字 分别标记与存储数据 但发现 inf = 2147483648 数据太大了
如果直接存储 平方数 也是很麻烦的 开始就把时间花这了 。。。
然后用map --- 不得不说 红黑树 这厉害 log(n)的时间 不是假的
我还是喜欢自己手写 pow 函数 而不是调用 cmath中的pow
这边 好像 其实 mp.find(X) == mp.end() 与 mp.count(x) 其实 在 时间运行上 是差不多的
好了 直接上code
View Code
美国往事 似乎 蛮好看 =-= 看过的 说下..
touch me
题意 没什么好讲的.... 就是找 平方数
一开始 用了2个数字 分别标记与存储数据 但发现 inf = 2147483648 数据太大了
如果直接存储 平方数 也是很麻烦的 开始就把时间花这了 。。。
然后用map --- 不得不说 红黑树 这厉害 log(n)的时间 不是假的
我还是喜欢自己手写 pow 函数 而不是调用 cmath中的pow
这边 好像 其实 mp.find(X) == mp.end() 与 mp.count(x) 其实 在 时间运行上 是差不多的
好了 直接上code
#include <iostream> #include <map> using namespace std; #define LL long long const long long inf = 2147483648; map<LL,LL>mp; LL pow( LL x , LL n ) { LL y = x; while( --n ) { x*=y; } return x; } void init() { LL temp; for( LL i = 2 ; i*i<=inf ; i++ ) { for( LL j = 2 ; j<=30 ; j++ ) { temp = pow( i , j ); if( temp>=inf ) { break; } else { if( mp.find(temp) == mp.end() ) mp[temp] = 1; } } } } void print() { map<LL,LL>::iterator it; for( it = mp.begin() ; it!=mp.end() ; it++ ) { printf( "%I64d\n",it->first ); } } int main() { init(); print(); getchar(); return 0; }
View Code
美国往事 似乎 蛮好看 =-= 看过的 说下..
相关文章推荐
- QVariant类学习(非常强大的类型,甚至能处理QMap<QString ,QVariant>)
- map, string 强大的STL
- map, string 强大的STL
- hdu 4022 Bombing (强大的map一对多的映射)
- 关于在toj上使用hash_map(回复黄冶)
- LogUtils:一个强大的Android日志管理器,支持对象、List、Map、数组等输出
- Map与List结合而成的强大的数据结构
- jquery的强大取值方法map()
- java遍历map最强大的一种方式
- Lisp em SCU - 4490 (强大的map用法)
- TOJ--2119--最小生成树和map
- 关于 Map 的整理 HashMap确实很强大啊
- MapGuide Enterprise 2007组件介绍
- python的几个内建函数:apply(),filter(),map(),reduce(
- SC命令,Xp下功能强大的服务控制管理命令
- TOJ 3504 Repeatless Numbers / 深搜
- __gnu_cxx::hash_map死循环分析
- java并发容器(Map、List、BlockingQueue)
- 【cocos3.x+tilemap】制作rpg小游戏(二)遮挡与碰撞
- 原生javascript 的MAP使用