- 博客(25)
- 资源 (5)
- 收藏
- 关注
原创 欧几里得求最大公因数
#include <cstdio>using namespace std;int gcd( int a, int b ){return !b ? a : gcd(b, a%b);}int main(){int a, b;scanf("%d%d", &a, &b );printf("%d\n", gcd(a,b) );return 0;}...
2018-04-29 20:12:36 314
原创 筛选法求素数
1 2 3 4 5 6 7 8 9101112131415161718192021#include <cstdio>#include <cmath>using namespace std;int a[1000000+5] = {1,1};int main(){ for( int i=2; i<= sqrt(1...
2018-04-29 20:10:59 93
原创 康拓展开
#include <cstdio>#include <cstring>using namespace std;int factor( int x ){ int pro = 1; for( int i=1; i <=x; i++ ) { pro = pro * i; } return pro;}int...
2018-04-29 10:24:03 119
原创 A的B次方取余
#include <cstdio>using namespace std;int main(){ const int c = 1000; int a, b; int i; int outcom; /*乘积的取余等于取余的乘积*/ while(true){ scanf("%d%d", &a, &b ...
2018-04-14 23:20:08 3201
原创 E - 最小周长
#include <cstdio>#include <cmath>using namespace std;int main(){ int s; int a, b; int i, minum; scanf("%d", &s ); /*输入面积*/ minum = s+1; /*初始记录的是最大的周长的一半*/ for( i=1;...
2018-04-14 16:45:32 234
原创 快速幂模板(求末尾数字)
#include <stdio.h>int powmod( int x, int c );int main(){ int number; /*做幂运算的数*/ int c; /*要用来取余的数*/ scanf("%d%d", &number, &c ); printf("%d\n", powmod( nu...
2018-04-14 15:52:12 263
原创 K - 数组中和等于K的数对
给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数,找出数组A中所有和等于K的数对。例如K = 8,数组A:{-1,6,5,3,4,2,9,0,8},所有和等于8的数对包括(-1,9),(0,8),(2,6),(3,5)。Input第1行:用空格隔开的2个数,K N,N为A数组的长度。(2 <= N <= 50000,-10^9 <= K <= ...
2018-04-13 11:54:30 904
原创 独木舟 (最优问题) (vector)
魔法学院放暑假了,WC和他的一帮魔友一起去弗尔夫斯基山脉玩。莫伊拉同学突然想划船到对岸找被削的Mercy玩,这里的每一艘船都是同一型号,能承受的重量都是一样的,并且每艘船都可以坐一个或者两个人。WC他们共有n个人,现在我们知道他们每个人的质量,而且每个人体重也不超过船的承重。可惜经费有限,他们必须租尽可能少的船,请问他们最少要租几艘船? Input第一行包含两个正整数n 和m ,n<=1...
2018-04-13 10:19:42 668
原创 H - 出勤记录I
小Hi的算法课老师每次上课都会统计小Hi的出勤记录。迟到会被记录一个L,缺席会被记录一个A,按时上课会被记录一个O。一学期结束,小Hi的出勤记录可以看成是一个只包含LAO的字符串,例如"OOOOLOOOLALLO……"。如果小Hi整学期缺席不超过1次,并且没有连续3次迟到,小Hi的出勤记录就算合格。 现在给出小Hi的出勤记录,你能判断他是否合格么?Input输入第一行包含一个...
2018-04-12 16:52:07 729
原创 风格不统一如何写程序
小Hi写程序时习惯用蛇形命名法(snake case)为变量起名字,即用下划线将单词连接起来,例如:file_name、 line_number。 小Ho写程序时习惯用驼峰命名法(camel case)为变量起名字,即第一个单词首字母小写,后面单词首字母大写,例如:fileName、lineNumber。 为了风格统一,他们决定邀请公正的第三方来编写一个转换程序,可以把一种命名法的变量...
2018-04-12 16:11:02 291
原创 大鱼吃小鱼 ( 栈操作 )
有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右。游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼。从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右)。问足够长的时间之后,能剩下多少条鱼?Input第1行:1个数N,表示鱼的数量(1 <= N <= 100000)。 第2 - N + 1行:每行两个数Aii, Bii,中间用空格分隔,分别表示鱼的大小及游...
2018-04-12 12:31:09 870
原创 分解素因子
假设x是一个正整数,它的值不超过65535(即1<x<=65535),请编写一个程序,将x分解为若干个素数的乘积。Input输入的第一行含一个正整数k (1<=k<=10),表示测试例的个数,后面紧接着k行,每行对应一个测试例,包含一个正整数x。Output每个测试例对应一行输出,输出x的素数乘积表示式,式中的素数从小到大排列,两个素数之间用“*”表示乘法。...
2018-04-12 10:50:46 1317
原创 歌德巴赫猜想 (速筛)
哥德巴赫猜想认为“每一个大于2的偶数,都能表示成两个质数之和”。给定一个大于2的偶数N,你能找到两个质数P和Q满足P<=Q并且P+Q=N吗?Input一个偶数N(4 <= N <= 1000000)Output输出P和Q。如果有多组解,输出P最小的一组。Sample Input10Sample Output3 7#include &l...
2018-04-12 09:13:53 569
原创 小Ho的补提交卡
小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序。100天过去了,小Ho查看自己的提交记录发现有N天因为贪玩忘记提交了。于是小Ho软磨硬泡、强忍着小Hi鄙视的眼神从小Hi那里要来M张"补提交卡"。每张"补提交卡"都可以补回一天的提交,将原本没有提交程序的一天变成有提交程序的一天。小Ho想知道通过利用这M张补提交卡,可以使自己的"最长连续提交天数"最多变成多少天...
2018-04-11 23:45:09 241
原创 分拆素数和
把一个偶数拆成两个不同素数的和,有几种拆法呢?Input : 输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。Output : 对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。Sample Input30260 1 2 3 4 5 6 7 8 910111213141516171819202122232...
2018-04-10 21:54:40 246
原创 STL set的基本用法
1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132333435363738394041424344#include <iostream> #include <set>using namespace std;...
2018-04-09 22:38:46 162
原创 STL map用法及其常用函数介绍
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667...
2018-04-09 21:56:07 519
原创 素数及其个数(速筛 打表)
#include <stdio.h>#define MAXNUM 1e6 /*上限*/ int prime[1000000+5] = { 1,1 }; /*已知 0和 1不是素数*/ int count[1000000+5] = { 0 }; /*打表*/ int main(){ /*速筛, 原理 一个判断一个素数,只需要判断能否被比他小的素数整除 因此,已知素数的倍...
2018-04-08 17:56:00 339
原创 6倍法快速判断素数
/*对于大于等于5的数字,我们可以用6的倍数来表示它,即,6x-1, 6x, 6x+1, 6x+2, 6x+3, 6x+4的轮回;6x+2 = 2(3x+1), 6x+3 = 3(2x+1), 6x+4 = 2(3x+2), 6x显然这些并不是素数;那么,我们可以总结为,对4以上的数字来说,只有6的倍数的左右两位才有可能是素数;作者:金七木链接:https://www.jiansh...
2018-04-08 17:09:29 3710 5
原创 数组中的二分查找
#include <cstdio>#include <vector>#include <algorithm>using namespace std;void b_search( vector<int> a, int x, int size ); //二分查找函数int main(){ int i, x; /*定义循环变量和查找元...
2018-04-07 22:01:51 391
原创 单向链表( 创建 插入 删除 遍历 )
#include <cstdio> #include <cstdlib>#include <cstring>using namespace std;struct list* create(); /*新建链表*/ struct list* insert( struct list *head, struct list *temp ); /*插入*/ s...
2018-04-07 21:59:32 388
原创 堆栈stack的基本操作
/*栈的模板可以用数组,单链表,以及stack堆栈来实现 *//*建议电脑查看*/ #include <cstdio> #include <stack> /*堆栈*/using namespace std;void print( stack<int> a, int n );void clear( stack<int> b ); /*清空...
2018-04-07 21:56:24 2341
原创 队列的基本操作
#include <cstdio>#include <queue> /*队列queue头文件*/ #include <algorithm>using namespace std;void print( queue<int> a, int n ); //自定义遍历输出函数 void is_empty( queue<int> d ...
2018-04-07 21:54:28 308
原创 一维vector简单操作
#include <cstdio>#include <vector>#include <algorithm>using namespace std;void print( vector<int> a, int n );int main(){ vector<int> num; //定义一个一维数组 int number;...
2018-04-07 21:52:57 529
原创 二维vector简单操作
#include <cstdio> #include <vector>#include <algorithm>using namespace std;int main(){ vector< vector<int> > arry; //写成arry(5) 可理解为设定大小5行 vector<int> d; /...
2018-04-07 21:49:12 2942
mysql-connector-java-8.0.16.jar驱动和注意事项.zip
2020-02-01
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人