随笔分类 - 筛选
摘要:先生成蛇型矩阵,然后再筛选出素数进行标记,最后bfs。这里要注意题目要求的1-10000的之间的数路径,但是并不代表我们只要打印到这个范围的素数,因为很可能边沿的点需要走到外面的图形来完成对短路,外围的也不要打印太多,毕竟素数的个数越到外面是越稀疏的,所以打印到40000足矣。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>#include <map>#define MAXN 40000using namespace std;i
阅读全文
摘要:问你一个数在一个连续区间,这个区间全为和数的长度。代码如下:#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#define MAXN 1300000using namespace std;int p[MAXN+5], rec[100005], N;void pre(){ int k; for (int i = 4; i <= MAXN; i += 2) { p[i] = 1; } for (int i = 3; i <= 1141; i
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2710给定N个数,求出其中含有最大素因子的数。两个代码:自己的恶心代码#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int p[20010], max[20005];inline int cal( int x ){ for( int i = x / 2; i >= 1; --i ) { if( !p[x] ) return x
阅读全文
摘要:这里主要预习了素数筛选以及输入外挂的编写。涛神的筛选法一直记着,给力。 #include <cstdio>#include <cstring>#include <cstdlib>using namespace std;char hash[16005] = {0};bool getint( int &t ){ char c; int f = 1; while( c = getchar(), c != '-' && ( c < '0' || c > '9' ) ) { if( c
阅读全文
摘要:由于该题是求一个数是不是“自身数”,而定义一个数是不是“自身数”的根据就是是否有祖先,又因为一个数的祖先一定比这个数要小,所以这就和筛选法很像了。 代码如下: 1 #include <cstring> 2 #include <cstdlib> 3 #include <cstdio> 4 using namespace std; 5 6 char hash[1000005]; 7 8 void deal( int x ) 9 {10 int rec = x;11 while( x > 0 )12 {13 int c = x % 10;14 ...
阅读全文
摘要:1105: Prime PathTime Limit: 1 SecMemory Limit: 128 MBSubmit: 2Solved: 2[Submit][Status][Web Board]DescriptionThe ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a ma..
阅读全文
摘要:找新朋友Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2518Accepted Submission(s): 1183Problem Description新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。Input第一行是测试数据的组数CN(Case
阅读全文
摘要:七夕节Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12718Accepted Submission(s): 3505Problem Description七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!"人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2
阅读全文