2014年3月13日

Sudoku Solver leetcode

摘要: 用位运算优化了一下,需要填入的点也事先扫描出来,每个格子属于哪个九宫格也事先算出。class Solution { struct point { int x,y; point(int X=0,int Y=0):x(X),y(Y){} }next_point[9][9]; vector> *pData; static const int mask=0x000001FF; char log2ADD1[513]; int hash[9][9]; int row_forbid[9],col_forbid[9],cur_forb... 阅读全文

posted @ 2014-03-13 20:04 Deller 阅读(130) 评论(0) 推荐(0)

2013年12月18日

ZJU PAT 2-08 扑克牌 24点

摘要: 暴力枚举表达式树,计算表达式值,输出表达式#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;const double eps=1e-6;char op[4]={'+','-','*','/'};struct node{ int val,l,r; bool covered;}tree[8];do 阅读全文

posted @ 2013-12-18 19:54 Deller 阅读(185) 评论(0) 推荐(0)

2013年3月30日

PKU POJ 2479 Maximum sum 最大连续子序列和

摘要: 这里子序列不能为空,至少要一个,特殊一点。View Code #include <iostream>#include <stdio.h>using namespace std;__int64 n,a[50005],dpl[50005],dpr[50005];int main(){ __int64 T,i,sum,mmax; scanf("%I64d",&T); while (T--) { scanf("%I64d",&n); for (i=0;i<n;++i) scanf("%I64d", 阅读全文

posted @ 2013-03-30 20:20 Deller 阅读(136) 评论(0) 推荐(0)

2013年3月28日

PKU POJ 3903 Stock Exchange 最长递增子序列

摘要: 必须要nlogn算法才能过View Code #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int L,a[100005];int list[100005],numoflist;int bsearch(int value){ int l=0,r=numoflist-1,mid; while (l<r) { mid=(l+r)>>1; if (list[mid]>=value) 阅读全文

posted @ 2013-03-28 18:55 Deller 阅读(144) 评论(0) 推荐(0)

PKU POJ 1458 Common Subsequence LCA 最长公共子序列

摘要: View Code #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int LCS(char x[],int l1,char y[],int l2){ int i,j,p,dp[2][1005]; memset(dp[0],0,sizeof(dp[0])); for (j=0,p=1;j<l2;++j) { dp[p][0]=0; for (i=0;i<l1;++i) { ... 阅读全文

posted @ 2013-03-28 16:07 Deller 阅读(161) 评论(0) 推荐(0)

2013年3月19日

PKU POJ 2531 Network Saboteur 搜索

摘要: 暴力搜索也能过,剪枝去掉重复搜索,可以到1s内View Code #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int n,c[25][25];bool t[25];int mmax;void dfs(int p,int x){ int i; if(x==0||n-p==x) { if(x>0) for (i=p;i<n;++i) t[i]=true; ... 阅读全文

posted @ 2013-03-19 16:19 Deller 阅读(140) 评论(0) 推荐(0)

2013年3月18日

PKU POJ 1088 滑雪 搜索

摘要: #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int r,c;int map[105][105],height[105][105];int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};inline bool judge(int x,int y){ return x>=0&&y>=0&&x<r&&y< 阅读全文

posted @ 2013-03-18 21:53 Deller 阅读(164) 评论(0) 推荐(0)

2013年3月14日

PKU POJ 1002 487-3279 水题

摘要: #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int a[100005];int t(char c){ if(c<'Q') return (c-'A')/3+2; else return (c-'B')/3+2;}int trans(char s[]){ int res=0; for (int i=0;i<strlen(s);++i) { i 阅读全文

posted @ 2013-03-14 21:13 Deller 阅读(143) 评论(0) 推荐(0)

2013年3月9日

PKU POJ 1946 Cow Cycling DP

摘要: 题目让一队牛(n只)骑车,只要有一个过终点(跑d圈),就算完成任务。每只牛刚开始的能量为e,当队伍速度为x圈/分钟时,领头的消耗为x^2能量/分钟,后面的消耗为x。求最快完成时间。dp[i][j][k]代表还剩i只牛没领跑,已经跑了j圈,领头的牛还有k能量的情况下最短用时。#include <iostream>using namespace std;int dp[25][105][105];int mmin(int a,int b){ if (a==0) return b; else return a<b?a:b;}int main(){ int ... 阅读全文

posted @ 2013-03-09 16:10 Deller 阅读(164) 评论(0) 推荐(0)

2013年3月8日

PKU POJ 1671 Rhyme Schemes DP

摘要: 基础DP,从长度为i-1的方案数得到长度为i的方案数,dp[i][j]长度为i有j种字母组成的方案数。#include <iostream>using namespace std;double dp[1000][1000];void init(){ int i,j; dp[1][1]=1; for (i=2;i<1000;++i) { dp[i][i]=dp[i][1]=1; for (j=2;j<i;++j) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; }}int main(){ ... 阅读全文

posted @ 2013-03-08 17:43 Deller 阅读(147) 评论(0) 推荐(0)

导航