自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(70)
  • 收藏
  • 关注

原创 由epoll实现的简易服务端实例

函数原型:#include <sys/epoll.h>int epoll_create(int size);int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);int epoll_wait(int epfd, struct epoll_event *events, int maxevents,...

2019-07-08 16:13:30 408

原创 由select实现的简单服务端实例

函数原型: #include <sys/time.h> #include <sys/types.h> #include <unistd.h> int select(int nfds, fd_set *readfds, fd_set *writefds, ...

2019-07-08 16:06:17 606

原创 欧拉计划--27

二次“素数生成”多项式欧拉发现了这个著名的二次多项式:n2+ n + 41对于连续的整数n从0到39,这个二次多项式生成了40个素数。然而,当n = 40时,402+ 40 + 41 = 40(40 + 1) + 41能够被41整除,同时显然当n = 41时,412+ 41 + 41也能被41整除。随后,另一个神奇的多项式n2− 79n + 1601被发现了,对于连续的整数...

2019-06-16 10:01:12 290

原创 0-1背包问题的个人理解

问题:给一个能承重V的背包,和n件不同物品(每个物品只有一件),我们用重量和价值的二元组来表示一个物品,第i件物品表示为(Vi,Wi),问:在背包不超重的情况下,得到物品的最大价值是多少?最近做了不少题,不像以前那样水博客了2333,总结一下,运用动态规划解决此类问题,首先确定递推状态 f ( i, j ) = k;其中 k 表示为i 件物品,剩余承重为 j 的情况下能装的最大价...

2019-04-10 14:22:51 424 1

原创 欧拉计划34

各位数字的阶乘145是个有趣的数,因为1! + 4! + 5! = 1 + 24 + 120 = 145。找出所有各位数字的阶乘和等于其本身的数,并求它们的和。注意:因为1! = 1和2! = 2不是和的形式,所以它们并不在讨论范围内。#include<iostream>using namespace std;int jc(int k){ int ans = ...

2019-04-05 11:49:16 240

原创 欧拉计划33

消去数字的分数49/98是一个有趣的分数,因为缺乏经验的数学家可能在约简时错误地认为,等式49/98 = 4/8之所以成立,是因为在分数线上下同时抹除了9的缘故。我们也会想到,存在诸如30/50 = 3/5这样的平凡解。这类有趣的分数恰好有四个非平凡的例子,它们的分数值小于1,且分子和分母都是两位数。将这四个分数的乘积写成最简分数,求此时分母的值。答案:100#inclu...

2019-04-05 11:24:19 136

原创 欧拉计划31

Coin sumsProblem 31In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).It is possi...

2019-04-05 10:37:01 180

原创 欧拉计划28

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:2122 23 242520 78 91019 6 12 1118 54 3121716 15 1413It can be ...

2019-04-05 10:34:40 105

原创 欧拉计划25

The Fibonacci sequence is defined by the recurrence relation:Fn= Fn−1+ Fn−2, where F1= 1 and F2= 1.Hence the first 12 terms will be:F1= 1F2= 1F3= 2F4= 3F5= 5F6= 8F7= 13F8= 21...

2019-04-05 10:32:17 172

转载 第七届蓝桥杯B组省赛第八题---四平方和

四平方和四平方和定理,又称为拉格朗日定理:每个正整数都可以表示为至多4个正整数的平方和。如果把0包括进去,就正好可以表示为4个数的平方和。比如:5 = 0^2 + 0^2 + 1^2 + 2^27 = 1^2 + 1^2 + 1^2 + 2^2(^符号表示乘方的意思)对于一个给定的正整数,可能存在多种平方和的表示法。要求你对4个数排序:0 <= a <= b ...

2019-03-22 09:05:16 490

原创 蓝桥杯第七届B组省赛第六题--方格填数

方格填数如下的10个格子(如果显示有问题,也可以参看【图1.jpg】)填入0~9的数字。要求:连续的两个数字不能相邻。(左右、上下、对角都算相邻)一共有多少种可能的填数方案?请填写表示方案数目的整数。注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。标号后位置: 1 2 34 5 6 78 9 10运用全排...

2019-03-21 10:49:10 185

原创 螺旋输出数组

#include<iostream>using namespace std; int main(){ int ma[100][100]; int pd[100][100]; int n,m; int temp = 0; scanf("%d%d",&n,&m); for(int i = 0; i < n; i++){ for(int j = ...

2019-03-21 10:42:40 331

转载 2018蓝桥杯b组国赛真题----格雷码

标题:格雷码格雷码是以n位的二进制来表示数。与普通的二进制表示不同的是,它要求相邻两个数字只能有1个数位不同。首尾两个数字也要求只有1位之差。有很多算法来生成格雷码。以下是较常见的一种:从编码全0开始生成。当产生第奇数个数时,只把当前数字最末位改变(0变1,1变0)当产生第偶数个数时,先找到最右边的一个1,把它左边的数字改变。用这个规则产生的4位格雷码序列如下:000000...

2019-03-17 15:25:29 632

原创 第九届蓝桥杯第二题--明码

标题:明码汉字的字形存在于字库中,即便在今天,16点阵的字库也仍然使用广泛。###16点阵的字库把每个汉字看成是16x16个像素信息。并把这些信息记录在字节中。###一个字节可以存储8位信息,用32个字节就可以存一个汉字的字形了。把每个字节转为2进制表示,1表示墨迹,0表示底色。每行2个字节,一共16行,布局是:第1字节,第2字节第3字节,第4字节....第31字节, 第...

2019-03-03 09:14:28 128

原创 杭电2055

#include&lt;iostream&gt;#include&lt;map&gt;using namespace std;int main(){ map&lt;char,int&gt; m; m['A'] = 1;m['a'] = -1; m['B'] = 2;m['b'] = -2; m['C'] = 3;m['c'] = -3; m['D'] = 4;m['d'] = ...

2019-02-24 13:53:32 226

转载 杭电2054

Problem DescriptionGive you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".Inputeach test case contains two numbers A and B.Outputfor each case, if A is equal...

2019-02-24 12:06:54 123

原创 杭电2053

Problem DescriptionThere are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multipl...

2019-02-23 23:06:13 199

转载 欧拉计划26--Reciprocal cycles

倒数的循环节单位分数指分子为1的分数。分母为2至10的单位分数的十进制表示如下所示:1/2= 0.51/3= 0.(3)1/4= 0.251/5= 0.21/6= 0.1(6)1/7= 0.(142857)1/8= 0.1251/9= 0.(1)1/10= 0.1这里0.1(6)表示0.166666…,括号内表示有一位循环节。可以看出,1/7有六位循环节。找出正整数...

2019-02-18 22:17:59 206

原创 欧拉计划24--Lexicographic permutations

字典序排列排列指的是将一组物体进行有顺序的放置。例如,3124是数字1、2、3、4的一个排列。如果把所有排列按照数字大小或字母先后进行排序,我们称之为字典序排列。0、1、2的字典序排列是:012   021   102   120   201   210数字0、1、2、3、4、5、6、7、8、9的字典序排列中第一百万位的排列是什么?结果:2783915460#include&...

2019-02-11 13:14:05 249

原创 欧拉计划23--Non-abundant sums

并非盈数之和完全数是指真因数之和等于自身的那些数。例如,28的真因数之和为1 + 2 + 4 + 7 + 14 = 28,因此28是一个完全数。一个数n被称为亏数,如果它的真因数之和小于n;反之则被称为盈数。由于12是最小的盈数,它的真因数之和为1 + 2 + 3 + 4 + 6 = 16,所以最小的能够表示成两个盈数之和的数是24。通过数学分析可以得出,所有大于28123的数都可以被...

2019-02-11 13:03:46 342

转载 欧拉计划22--Names score

姓名得分在这个46K的文本文件names.txt(右击并选择“目标另存为……”)中包含了五千多个姓名。首先将它们按照字母序排列,然后计算出每个姓名的字母值,乘以它在按字母顺序排列后的位置,以计算出姓名得分。例如,按照字母序排列后,位于第938位的姓名COLIN的字母值是3 + 15 + 12 + 9 + 14 = 53。因此,COLIN的姓名得分是938 × 53 = 49714。文件...

2019-02-11 12:16:08 13136

原创 欧拉计划21--Amicable numbers

记d(n)为n的所有真因数(小于n且整除n的正整数)之和。如果d(a) = b且d(b) = a,且a ≠ b,那么a和b构成一个亲和数对,a和b被称为亲和数。例如,220的真因数包括1、2、4、5、10、11、20、22、44、55和110,因此d(220) = 284。284的真因数包括1、2、4、71和142,因此d(284) = 220。说明284和220是亲和数。求所有小于10000的...

2019-02-11 11:20:11 282

原创 欧拉计划20--Factorial digit sum

阶乘数字和n! 的意思是 n × (n − 1) × … × 3 × 2 × 1例如,10! = 10 × 9 × … × 3 × 2 × 1 = 3628800,所以10!的各位数字和是 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27。求出100!的各位数字和。结果:648#include&lt;iostream&gt;#include&lt;string....

2019-02-08 13:00:18 222

原创 欧拉计划19--Counting Sundays

结果:171#include&lt;iostream&gt;using namespace std;int main(){ int a[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; int day=1,ans =0; for(int i=1900;i&lt;=2000;i++){ if((i%4==0&amp;&amp;i...

2019-02-08 12:25:38 178

原创 欧拉计划18--Maximum path sum I

#include&lt;iostream&gt;#include&lt;string.h&gt;#include&lt;math.h&gt;using namespace std;int main(){ int ans = 0; int a[50][50],sum[50][50]; memset(sum,0,sizeof(sum)); for(int i=1;i&lt;=15...

2019-02-08 11:01:05 184

原创 欧拉计划17--Number letter counts

#include&lt;iostream&gt;#include&lt;string.h&gt;using namespace std;int a[105],b[5];void Init(){ memset(a,0,sizeof(a)); a[1]=a[2]=a[6]=a[10] = 3; a[4]=a[5]=a[9] = 4; a[3]=a[7]=a[8]=a[40...

2019-01-29 20:03:32 239

原创 欧拉计划16--Power digit sum

用数组模拟运算的步骤,每一位存入数组内。#include&lt;iostream&gt;#include&lt;string.h&gt;using namespace std;int main(){ int a[1000]; int ans = 0; memset(a,0,sizeof(a)); a[0] = 1; for(int i=1;i&lt;=1000;i++){...

2019-01-24 19:54:59 156

原创 欧拉计划15--Lattice paths

动态解比较好,当前节点的路径数是其前一个节点和上面一个节点的可能性之和。状态转移方程:a[i][j] = a[i-1][j]+a[i][j-1];#include<iostream>using namespace std;int main(){ long long a[25][25]; for(int i = 0;i < 21;i++){ for(int...

2019-01-24 17:25:06 186

原创 欧拉计划水题14--Longest Collatz sequence

#include<iostream>using namespace std;int klz(long long n,int len){ if(n==1) return len; if(n%2==0){ klz(n/2,len+1); }else{ klz(3*n+1,len+1); }}int main(){ int max=0,ans,temp;...

2019-01-23 21:53:32 159

原创 欧拉计划13--Large sum

结果:5537376230390876637302048746832985971773659831892672取十位:5537376230#include<iostream>#include<string.h>using namespace std;int main(){ char c[55]; int a[55],b[105]; memset(b...

2019-01-23 21:32:00 217

原创 欧拉计划12--Highly divisible triangular number

Answer: 76576500 #include<iostream>#include<math.h>using namespace std;int value(int temp){ int num = 0; for(int i=1;i<=sqrt(temp);i++){ if(temp%i==0){ if(i=...

2019-01-23 19:39:00 170

原创 欧拉计划11--Largest product in a grid

#include&lt;iostream&gt;#include&lt;string.h&gt;using namespace std;int a[25][25];int heng(int i,int j){ return a[i][j]*a[i][j+1]*a[i][j+2]*a[i][j+3];}int shu(int i,int j){ return a[i][j]*a[...

2019-01-23 18:56:59 85

原创 欧拉计划10--Summation of primes

#include <iostream>#include <algorithm>#include <string.h>using namespace std;#define MAX_N 2000000typedef long long lint;int prime[MAX_N+5];int is_prime[MAX_N+5];int main(...

2019-01-23 17:29:14 120

原创 欧拉计划09

#include<iostream>using namespace std;int main(){ for(int i=1;i<=1000;i++){ for(int j=1;j<=1000;j++){ for(int k=1;k<=1000;k++){ if(i+j+k==1000&&i*i+j*j==k*k){ ...

2019-01-23 16:15:09 85

原创 欧拉计划008--Largest product in a series

更新一下,重新写一下,输入写到文件里,再重定向到输入就好:#include <iostream>#include <algorithm>#include <string.h>using namespace std;#define MAX_N 1000typedef long long lint;char num[MAX_N+5];int m...

2019-01-21 21:53:14 63

原创 欧拉计划007--10001st prime

筛法筛一下存到数组就可以,线性筛更好了。结果:104743#include<iostream>#include<string.h>#define maxin 200000using namespace std;int a[maxin];int b[maxin];int main(){ int ans = 0; memset(a,0,sizeo...

2019-01-21 21:50:41 118

原创 欧拉计划006--Sum square difference

#include<iostream>using namespace std;int main(){ int i,ans=0,t=0; for(i=1;i<=100;i++){ int temp = i*i; ans += temp; } for(i=1;i<=100;i++){ t+=i; } t = t*t; cout<&lt...

2019-01-21 21:47:40 120

原创 欧拉计划005--Smallest multiple

最小的能够被1到20整除的正数是多少?直接交答案的题硬跑就行。结果:232792560#include<iostream>using namespace std;int main(){ long long ans=21 ; int k = 1; while(k){ k = 0; for(int i=1;i<=20;i++){ if(ans...

2019-01-21 21:43:48 166 1

原创 欧拉计划004--Largest palindrome product

结果:906609,简单的暴力就可以解决,注意判断产生的回文数是否为最大即可。#include<iostream>using namespace std;int main(){ int i,j; int ans=0; for(i=999;i>=100;i--){ for(j=999;j>=100;j--){ long long temp = i*...

2019-01-21 21:39:17 98

原创 欧拉计划003--Largest prime factor

求600851475143最大的质因数是多少?举例24 = 4 X 6= 2 X 2 X 2 X 3,即2,3为质因数,3最大,可利用24不断除去小的质因数,最后剩下最大质因数,即( ( 24/2 )/2 )/2 = 3;结果:6857#include<iostream>using namespace std;int main(){ long long te...

2019-01-21 21:36:22 139

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除