poj 2591 Set Definition【OJ实验】
这道题本身比我之前A的题目要简单,我自己另外在OJ上用这道题做了几个有趣一点的实验
poj2591只是定义集合的方式不同了而已。。。
ans[a2]*2+1,ans[a3]*3+1,还有注意一点就是我改的时候用%I64d不能输入int型的数,OJ会爆Runtime error
先贴AC的代码:
#include <iostream> #include <stdio.h> using namespace std; int ans[10000010]={0,1}; int getMin(int a,int b){return a<b?a:b;} int main() { int a2,a3,i,tmp,n; a2=a3=1; for(i=2;i<=10000000;i++) { tmp=getMin(ans[a2]*2+1,ans[a3]*3+1); ans[i]=tmp; if(tmp==ans[a2]*2+1) ++a2; if(tmp==ans[a3]*3+1) ++a3; } while(scanf("%d",&n)!=EOF) printf("%d\n",ans[n]); return 0; }
实验内容:
1.在OJ上,inline可以写
2.可以没有<stdio.h>,只有<iostream>用标准输入输出scanf和printf
3.可以没有using namespace std;这段代码一样正确,而且运行时间大减!!
4.用<stdio.h>比<iostream>运行时间长很多。。。
第一行的是只用<stdio.h>,Time: 188MS
第二行只用<iostream>,Time: 63MS
第三行用了<iostream>+using namespace std; Time: 391MS
第四行用了<iostream>+using namespace std;+<stdio.h>+inline Time: 172MS
第五行用了<iostream>+using namespace std;+<stdio.h> time:266MS
这样看来用iostream,并不用std的时候的确是最优的,即使代码什么都不改
最后更新:2017-04-03 14:53:58
上一篇:
GetWindowRect、GetClientRect、ScreenToClient与ClientToScreen
下一篇:
再看Core Data中PSC陷入死锁的问题
SQL语句的基本操作
ECMAScript基础
Java序列化和反序列化
Hello World感知机,懂你我心才安息 (深度学习入门系列之五)
Flink 1.1 – ResourceManager
在 Docker 中运行 MySQL:多主机网络下 Docker Swarm 模式的容器管理
2013蓝桥杯【模拟赛】1的个数
编程思维训练(一)
Java 25天基础-DAY 06-面向对象-ststic关键字
解决The type or namespace name \'XXXX\' does not exist in the namespace \'XXXXXXXXX\' 的错误