上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 57 下一页

2011年7月22日

poj 3641 Pseudoprime numbers

摘要: #include <iostream> //二分using namespace std;__int64 p;bool prime(__int64 n){ for(__int64 i=2;i*i<=n;++i) if(n%i==0) return false; return true;}__int64 query(__int64 a,__int64 n){ if(n==1) return a; __int64 q=query(a,n/2),t=(q*q)%p; if(n%2==0) return t; else return (t*a)%p;}int main(){ __int 阅读全文

posted @ 2011-07-22 20:19 sysu_mjc 阅读(151) 评论(0) 推荐(0) 编辑

poj 3616 Milking Time

摘要: #include<iostream> //dp#include<algorithm>using namespace std;int dp[1005],n,m,r;struct node{ int s,e,eff; bool operator<(const node& o) { return s<o.s||(s==o.s&&e<o.e); }}ans[1005];int main(){ int i,j; cin>>n>>m>>r; for(i=0;i<m;++i) { cin>> 阅读全文

posted @ 2011-07-22 20:18 sysu_mjc 阅读(108) 评论(0) 推荐(0) 编辑

poj 3280 Cheapest Palindrome

摘要: //参照poj1 1159 Palindrome// 题意:对一字符串增加或删除字符来使其变成回文字符串,而增加或删除字符都有一个花费,// 求解使该字符串变成回文串需要的最小花费.#include <iostream> // DP + 滚动数组#include <string>using namespace std;#define MAXN 2005int ans[2][MAXN];int main(){ int n,m; char s[MAXN]; scanf("%d%d%s",&m,&n,s); char ch[2]; int 阅读全文

posted @ 2011-07-22 20:17 sysu_mjc 阅读(144) 评论(0) 推荐(0) 编辑

poj 3461 Oulipo

摘要: #include <iostream> //KMP算法using namespace std;char A[5000000],B[5000000]; int n,m,next[5000000],res; void get_next(){ next[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&&B[j+1]!=B[i]) j=next[j]; if(B[j+1]==B[i]) j=j+1; next[i]=j; }}void kmp(){ res=0; int j=0; for(int i=1;i< 阅读全文

posted @ 2011-07-22 20:17 sysu_mjc 阅读(124) 评论(0) 推荐(0) 编辑

poj 3126 Prime Path

摘要: #include <iostream> //bfs#include <algorithm>#include<deque>using namespace std;bool prime(int n){ for(int i=2;i*i<=n;++i) if(n%i==0) return false; return true;}bool p[10000],visited[10000];struct node{ int n,c;}ans[10000];void init(){ for(int i=1000;i<10000;++i) if(prime(i)) 阅读全文

posted @ 2011-07-22 20:16 sysu_mjc 阅读(147) 评论(0) 推荐(0) 编辑

poj 3219 Binomial Coefficients

摘要: //判断C(n,k)的奇偶性//如果n!中因子2的个数大于k!和(n-k)!中因子2的个数之和,那么C(n,k)就是偶数,否则C(n,k)就是奇数。//而且计算N!中2的阶数,只要计算N/2+N/4……#include <iostream> using namespace std;int fac(int d) //计算d!中2的阶数,即因子2的个数{ int s=0; while((d=d>>1)!=0) s+=d; return s;}int f(int n,int k){ if(k==0||k==n) return 1; int a=fac(n),b=fac(n-k 阅读全文

posted @ 2011-07-22 20:16 sysu_mjc 阅读(156) 评论(0) 推荐(0) 编辑

poj 2752 Seek the Name, Seek the Fame

摘要: #include <iostream> //KMP算法using namespace std;char A[500000];int m,P[500000],res[500000];void get_next(){ P[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&&A[j+1]!=A[i]) j=P[j]; if(A[j+1]==A[i]) j=j+1; P[i]=j; }}int main(){ while(scanf("%s",A+1)!=EOF) { for(m=0;A[m+1 阅读全文

posted @ 2011-07-22 20:15 sysu_mjc 阅读(182) 评论(0) 推荐(0) 编辑

poj 2488 A Knight's Journey

摘要: #include<iostream> //dfs,注意字典顺序using namespace std;int ans[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}}; //按字典序排列int t,r,c,n,path[30][2],vis[30][30],rear;void dfs(int x,int y){ for(int i=0;i<8;++i) { int px=x+ans[i][0],py=y+ans[i][1]; if(px>0&&px<=r&& 阅读全文

posted @ 2011-07-22 20:14 sysu_mjc 阅读(118) 评论(0) 推荐(0) 编辑

poj 2533 Longest Ordered Subsequence

摘要: #include<iostream> //最长严格上升子序列(LIS)算法,时间复杂度为O(nlogn)using namespace std;int seq[1002]; //seq[i]是记录在所有最长严格上升子序列的长度为 i 之中,选取结束位置上最小的值int main(){ int n,p; cin>>n>>p; int rear=0; seq[++rear]=p; while(--n) { cin>>p; if(p>seq[rear]) //当p==seq[rear],不能压入... 阅读全文

posted @ 2011-07-22 20:14 sysu_mjc 阅读(100) 评论(0) 推荐(0) 编辑

poj 2392 Space Elevator

摘要: #include<iostream> //多重背包#include<algorithm>using namespace std;int dp[50000];struct node{ int h,a,c; bool operator<(const node& o) { return a<o.a; }}ans[405];int k;int main(){ cin>>k; for(int i=0;i<k;++i) cin>>ans[i].h>>ans[i].a>>ans[i].c; sort(ans,a 阅读全文

posted @ 2011-07-22 20:13 sysu_mjc 阅读(108) 评论(0) 推荐(0) 编辑

上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 57 下一页

导航