
OJ题目
Red818
别人的幸福与你无关
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
最大公约数GCD
OJ地址 /*Enter 2 positive integers A, B, and output the largest common divisor of A and B*/#include <stdio.h>//recursionint gcd1(int a,int b){ if (b==0) return a; else return gcd1...原创 2018-03-19 11:09:11 · 269 阅读 · 0 评论 -
最小公倍数LCM
OJ地址/*Enter 2 positive integers A, B, and output the least common multiple of A and B.*/#include <stdio.h>long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}int main...原创 2018-03-19 14:07:38 · 346 阅读 · 0 评论 -
素数判定
OJ地址/* 给定一个数n,要求判断其是否为素数(0,1,负数都是非素数) */#include <stdio.h>#include <math.h>bool Judge(int n){ if (n<=1) return false; else{ int bound = (int)sqrt(n); f...原创 2018-03-19 14:33:10 · 263 阅读 · 0 评论 -
判断素数个数
OJ测试地址/* 输入一个整数n(2<=n<=10000),要求输出所有从1到这个整数之间(不包括1和这个整数)个位为1的素数,如果没有则输出-1。 */ #include <stdio.h> int prime[1000]; int primesize; bool mark[10001]; void Count(int n...原创 2018-03-19 15:38:25 · 967 阅读 · 0 评论 -
还原二叉树
OJ传送门/* 两个字符串,其长度n均小于等于26。 第一行为前序遍历,第二行为中序遍历。 求出其后序遍历 */#include <stdio.h>#include <string.h>static struct Node{ Node *lchild; Node *rchild; char c;}Tree[110];stati...原创 2018-03-20 20:15:02 · 526 阅读 · 0 评论 -
二叉排序树遍历
OJ传送门/* 输入一系列整数,建立二叉排序数,并进行前序,中序,后序遍历 */#include <stdio.h>#include <iostream>using namespace std;struct Node{ Node *lchild; Node *rchild; int c;}Tree[110];int loc;...原创 2018-03-20 20:19:24 · 760 阅读 · 0 评论 -
并查集
OJ传送门/* 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。 省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。 问最少还需要建设多少条道路? */#include <stdio.h>using namespace std;#define N 1000stat...原创 2018-03-21 20:06:57 · 233 阅读 · 2 评论