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的时候的确是最优的,即使代码什么都不改
相关文章
|
6月前
|
开发框架 .NET
poj 3468 A Simple Problem with Integers线段树区间修改
题目意思很简单,有N个数,Q个操作, Q l r 表示查询从l到r 的和,C l r v 表示将从l到r 的值加上v,明显的线段树,不知道线段树的人肯定暴力,肯定超时,哈哈!!
19 0
|
算法 Go C++
UPC Go Home(贪心 || 前缀和+二分)(STL二分函数的使用)
UPC Go Home(贪心 || 前缀和+二分)(STL二分函数的使用)
65 0
|
人工智能
[Codeforces 1286B] Numbers on Tree | 技巧构造
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer ai written on it. For each vertex i, Evlampiy calculated ci — the number of vertices j in the subtree of vertex i, such that a j < a i
95 0
[Codeforces 1286B] Numbers on Tree | 技巧构造
|
存储
题解报告:POJ 2386--Lake Counting(BFS+DFS)
给你一副图n行m列,其中’W’代表池塘,’.'代表土地,问现在这幅图中有多少个池塘,如果一个池塘的八个方向上如果有池塘,则只算一个,类似于连通块,求有多少个连通块。
103 0
|
算法 测试技术
【算法笔记题解】PAT A1075 PAT Judge
【算法笔记题解】PAT A1075 PAT Judge
【算法笔记题解】PAT A1075 PAT Judge
LeetCode解题之二:Add Two Numbers
LeetCode解题之二:Add Two Numbers