随笔分类 -  2012-1000系列

上一页 1 2 3 4 5 6 7 ··· 13 下一页

 
HDU 2151 Worm
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2151水View Code #include <stdio.h>#include <string.h>int n,p,m,t ;int dp[110][110] ;int main(){ while(~scanf("%d%d%d%d",&n,&p,&m,&t)) { memset(dp,0,sizeof(dp)) ; dp[0][p]=1 ; for(int i=0;i<=m;i++) for(int j=1;j<=n;j 阅读全文
posted @ 2012-06-10 19:35 LegendaryAC 阅读(139) 评论(0) 推荐(0)
HDU 2973 YAPTCHA
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2973威尔逊定理,详情参见数论四大定理。从这道题应用的层面讲,我们只需要知道若p为素数,则p可整除(p-1)!+1。有上面的结论这道题就解决了,3k+7为素数则答案加1,为非素数则不变。(代数式简单变化一下很容易看出来,此处不赘述)为了防止超时,提前把答案打表打出来就好。输入输出挂,果断刷到第一。View Code #include <iostream>using namespace std ;bool prime[3000008] ;int ans[1000001] ;inline bool s 阅读全文
posted @ 2012-06-10 02:59 LegendaryAC 阅读(406) 评论(0) 推荐(0)
HDU 1395 2^x mod n = 1
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1395枚举x复杂度可以处理成O(n),由于我是个sb,所以给弄成O(nlogn)了。这里用的方法基于欧拉定理。欧拉定理表明,若n,a为正整数,且n,a互质,(a,n) = 1,则a^φ(n) ≡ 1 (mod n)。我们处理的当然是(2,n)=1的情况,枚举欧拉函数的因子即可View Code #include <stdio.h>__int64 qpow(int a,__int64 b,int r){ __int64 ans=1,buff=a; while(b) { if(b&... 阅读全文
posted @ 2012-06-10 00:55 LegendaryAC 阅读(242) 评论(0) 推荐(0)
HDU 1905 Pseudoprime numbers
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1905水题,套个米勒拉宾的模板就秒了View Code #include <stdio.h>__int64 qpow(int a,int b,int r)//快速幂 { __int64 ans=1,buff=a; while(b) { if(b&1)ans=(ans*buff)%r; buff=(buff*buff)%r; b>>=1; } return ans;}bool Miller_Rabbin(int n,int a)//米勒拉宾... 阅读全文
posted @ 2012-06-09 16:54 LegendaryAC 阅读(201) 评论(0) 推荐(0)
HDU 1140 War on Weather
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1140根据球的切点做简单的判断,一开始找到答案没有跳出循环,各种错。。。View Code #include <iostream>#include <cmath>using namespace std ;const double PI=acos(-1.0) ;//π的表示方法 struct point { double x,y,z ;} ;double dis(point p1,point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p 阅读全文
posted @ 2012-06-09 05:49 LegendaryAC 阅读(199) 评论(0) 推荐(0)
HDU 1086 You can Solve a Geometry Problem too
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1086判断两线段是否相交,用向量搞了View Code #include <iostream>using namespace std ;struct point{ double x,y ;} ;typedef struct L{ point p1,p2 ;}L ;L kk[110] ;double direction(point p1,point p2,point p){ return (p.x-p1.x)*(p1.y-p2.y)-(p1.x-p2.x)*(p.y-p1.y) ;}bool ... 阅读全文
posted @ 2012-06-09 03:41 LegendaryAC 阅读(186) 评论(0) 推荐(0)
HDU 1240 Asteroids!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1240给这道题跪了,z是x,x是y,y是z,囧View Code #include <iostream>using namespace std ;char map[15][15][15] ;int dp[15][15][15] ;int q[15*15*15][3] ;int n ;int sx,sy,sz ;int ex,ey,ez ;void bfs(){ int x,y,z,xx,yy,zz ; int front=0,rear=1 ; int tab[][3]={1,0,0,-1,0... 阅读全文
posted @ 2012-06-08 01:10 LegendaryAC 阅读(269) 评论(0) 推荐(0)
HDU 2625 Say love to you once again
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2625随便写出一个dfs然后猥琐随机化法剪枝,第一次AC的战绩是1/18,还跑了700+ms,随机50w次成功率还这么低。。。最近rp真是太烂了有木有。。。View Code #include <iostream>#include <cstdlib>#include <ctime>using namespace std ;int map[30][30] ;int n ;int ans ;int vis[30] ;void dfs(int d){ if(d==n) { int 阅读全文
posted @ 2012-06-07 10:12 LegendaryAC 阅读(296) 评论(0) 推荐(0)
HDU 1865 1sting
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1865大数的斐波那契数列,又用java猥琐过了。。。View Code import java.io.* ;import java.math.* ;import java.util.* ;import java.text.* ;public class Main{ public static void main(String[]args) { Scanner cin=new Scanner(new BufferedInputStream(System.in)) ; Bi... 阅读全文
posted @ 2012-06-06 22:53 LegendaryAC 阅读(180) 评论(0) 推荐(0)
HDU 2209 翻纸牌游戏
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2209艰难的一题,对回溯法的理解又深刻了View Code #include <iostream>using namespace std ;int q[25] ;int cnt[25] ;int len ;int ans ;bool gao(){ for(int i=0;i<len;i++) if(q[i]) return false ; return true ;}void dfs(int idx){ if(gao()) { int ... 阅读全文
posted @ 2012-06-06 20:27 LegendaryAC 阅读(457) 评论(2) 推荐(0)
HDU 1495 非常可乐
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1495bfs,个人感觉很经典的题目,分六种情况搜索View Code #include <iostream>using namespace std ;int s,n,m ;int q[101*101*101][3] ;int dp[101][101][101] ;int bfs(){ if(s&1) return 0 ; if(n<(s>>1)) return 0 ; dp[s][0][0]=0 ; int front=0,rear=1 ; q[fro... 阅读全文
posted @ 2012-06-06 11:07 LegendaryAC 阅读(696) 评论(0) 推荐(0)
HDU 1010 Tempter of the Bone
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1010奇偶剪枝,说好的里程碑来了。。。跳出dfs的时候一定要注意确保跳出。。。我开始写的时候没有跳出dfs只是跳出了一层递归,导致长时间tle,orz涂涂能看出这种问题。View Code #include <iostream>#include <queue>using namespace std ;int n,m,t ;int flag ;int e ;char map[10][10] ;void dfs(int x,int y,int time){ int tab[][2]={1, 阅读全文
posted @ 2012-06-05 17:18 LegendaryAC 阅读(179) 评论(0) 推荐(0)
HDU 1035 Robot Motion
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1035搜搜搜View Code #include <iostream>using namespace std ;char map[11][11] ;int dp[11][11] ;int n,m ;int ans,loop ;int flag ;void dfs(int x,int y,int cnt){ if(x<0 || x>=n || y<0 || y>=m) { flag=0 ; ans=cnt ; return ; } if(dp[x... 阅读全文
posted @ 2012-06-04 23:30 LegendaryAC 阅读(191) 评论(0) 推荐(0)
HDU 1312 Red and Black
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1312从这老题开始吧View Code #include <iostream>#include <queue>using namespace std ;char map[25][25];int ans,n,m;typedef struct L{ int x,y;}L;void bfs(int x,int y){ queue <L> q ; int tab[][2]={1,0,-1,0,0,1,0,-1}; L point,go,front; point.x=x; point 阅读全文
posted @ 2012-06-04 18:29 LegendaryAC 阅读(167) 评论(0) 推荐(0)
HDU 1039 Easier Done Than Said?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1039做一道水题收拾收拾睡了。今天hut校赛被虐成狗哇哈哈哈,被人虐好爽,各种高潮。暑假前要复习期末考试,还有字符串,搜索,计算几何,线段树这么一大堆东西要弄,真是令人充满干劲啊,burning!View Code #include <stdio.h>#include <string.h>int main (){ char str[101]; char tab[5]={'a','e','i','o','u' 阅读全文
posted @ 2012-06-03 22:45 LegendaryAC 阅读(162) 评论(0) 推荐(0)
HDU 1403 Longest Common Substring
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1403学后缀树组罗大牛的《后缀树组——处理字符串的有力工具》应该谁都会看。。不过下面推荐的这个讲解也很不错http://wenku.baidu.com/view/3fd0138884868762caaed5ac.h... 阅读全文
posted @ 2012-06-03 01:46 LegendaryAC 阅读(684) 评论(0) 推荐(0)
HDU 1194 Beat the Spread!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1194跟着狗畅找了道水题做,他真无聊啊。。。View Code #include <iostream>using namespace std ;int main(){ int n,i; int s,d; scanf("%d",&n); while(n--) { scanf("%d%d",&s,&d); for(i=s;i>0;i--) if(abs(i*2-s)==d) { pr... 阅读全文
posted @ 2012-06-02 17:55 LegendaryAC 阅读(253) 评论(0) 推荐(0)
HDU 2161 Primes
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2161素数判断,这题数据范围小的可怜,普通的筛法肯定没问题,不过为了练习我还是拿米勒拉宾测试写的。ps:为2b的自己流了一地泪View Code #include <iostream>using namespace std ;__int64 qpow(int a,int b,int r){ __int64 ans=1,buff=a; while(b) { if(b&1)ans=(ans*buff)%r; buff=(buff*buff)%r; b>>... 阅读全文
posted @ 2012-06-02 13:21 LegendaryAC 阅读(170) 评论(0) 推荐(0)
HDU 2138 How many prime numbers
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2138米勒拉宾素数测试,解大规模素数问题。View Code #include <iostream>using namespace std ;__int64 qpow(int a,int b,int r){ __int64 ans=1,buff=a; while(b) { if(b&1)ans=(ans*buff)%r; buff=(buff*buff)%r; b>>=1; } return ans;}bool Miller_Rabbin... 阅读全文
posted @ 2012-06-01 18:32 LegendaryAC 阅读(224) 评论(0) 推荐(0)
HDU 1563 Find your present!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1563找只出现一次的数,排个序处理下就行View Code #include <iostream>#include <algorithm>using namespace std ;int main(){ int n; while(scanf("%d",&n),n) { int a[201]; a[1]=a[n+1]=-1; for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(... 阅读全文
posted @ 2012-05-31 23:51 LegendaryAC 阅读(204) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 13 下一页