LeeBlog

导航

2011年5月5日 #

HDU 1286 找新朋友 筛选法

摘要: 这题要用到筛选法的思想,否则直接TLE,这题我很郁闷,原以为这题用这种方法肯定要超时的,就一直不敢用,没想到水了.郁闷#include<stdio.h>#include<string.h>int n,num[40000];int main( ){ int t; scanf( "%d",&t ); num[0] = num[1] = 0; while( t-- ) { scanf( "%d",&n ); memset( num,0,sizeof( num ) ); for( int i = 2; i <= n 阅读全文

posted @ 2011-05-05 11:00 LeeBlog 阅读(372) 评论(0) 推荐(0) 编辑

HDU 3792 Twin Prime Conjecture 这题要用筛选法......

摘要: 开始我直接打表一直不能过,后来知道有删选法这一东西,水过62MS#include<stdio.h>#include<string.h>int num[100005],c[100005];void shuaixuan( )//筛选法{ memset( num,0,sizeof( num ) ); for( int i = 2; i < 100005; ++i ) for( int j = 2; i * j < 100005; ++j ) num[i*j] = 1;}void chart( )//预处理{ num[1] = 1; memset( c,0,size 阅读全文

posted @ 2011-05-05 10:13 LeeBlog 阅读(269) 评论(0) 推荐(0) 编辑

HDU 1215 七夕节 筛选法

摘要: 这题我开始暴力,结果TLE,后来想到这种题应该都有精简的方法,就去网上搜,没想到新学了一招,筛选法,估计最小公倍数也能这样做了,哈哈#include<stdio.h>#include<string.h>long long num[500005];void shaixuan( ){ for( int i = 1; i < 500005; ++i ) num[i] = 1; for( int i = 2; i < 500005; ++i ) for( int j = 2; j * i < 500005; ++j ) num[i*j] += i; }int 阅读全文

posted @ 2011-05-05 09:32 LeeBlog 阅读(258) 评论(0) 推荐(0) 编辑