2014年1月14日
摘要: 暴力果断超时 下面给出一个大神的证明:http://www.cnblogs.com/devymex/archive/2010/08/07/1799713.html这是一道数论题,用数学的语言描述就是:x, y, z∈N,给定一个数n,找出所有的x, y, z ≤ n,使得x2+ y2= z2成立。如果要穷举所有的x, y, z的话,按照题目所给的数据量,肯定是无法在限定时间内完成的。考虑利用毕达哥拉斯数的性质生成所有的x, y, z来解决,数学推导简要介绍如下:先假定x, y, z两两互质,由于x, y互质,故x, y中至少有1个是奇数。下面用反证法证明x和y中有且只有1个奇数。假定x, y都 阅读全文
posted @ 2014-01-14 17:23 风流monkey 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 就是问在一个n*m的棋盘里最多能放多少个knight,一开始想是回溯么,最后一想不是;分为三种情况 n==1 || m==1 这种都明白n==2 || m==2 这种情况下要除4,商乘4加上对余数的处理(画图后一目了然)最后一种是n*m/2,不能整除时加一#include #include #include #include using std::min;using std::max;int n,m;int solve(){ int a=min(n,m); int b=n+m-a; if(a==1) return b; else if(a==2) {... 阅读全文
posted @ 2014-01-14 15:33 风流monkey 阅读(167) 评论(0) 推荐(0) 编辑
  2013年11月23日
摘要: 大数+简单dp 自己的思路不知为何老是Re 借鉴了别人的方法。。。确实自己在dp方面欠缺很多#include #include #include char dp[110][10010][110];char s[10010],str[110];void solve(char *s, char *str, char *s2){//puts(str);//puts(s2); int a[110],b[110],c[110]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); ... 阅读全文
posted @ 2013-11-23 20:58 风流monkey 阅读(163) 评论(0) 推荐(0) 编辑
  2013年11月14日
摘要: 位运算+记忆化搜索#include #include #include #include #include using namespace std;int dp[5000];int dfs(int x){ if(dp[x]!=-1) return dp[x]; int _min=0; for(int i=0; i0 && !(x&(1<<(i-1)))) { int t=x^(1<<i); t^= 1<<(i+1); t^= 1<<(i-1); _mi... 阅读全文
posted @ 2013-11-14 17:39 风流monkey 阅读(123) 评论(0) 推荐(0) 编辑
  2013年11月7日
摘要: 水题 大数fibs数列+二分查找。。。#include #include #define N 500char s[N][N];char s2[110],str[110];void ans(int *a, int *b){ for(int i=0; i=0; --k) if(a[k]) break; for(int i=k; i>=0; --i) s[j++]=a[i]+'0';}void solve(){ int a[N]; int b[N]; int c[N]; memset(a, 0, sizeof(a)); memset(b, 0,... 阅读全文
posted @ 2013-11-07 20:36 风流monkey 阅读(127) 评论(0) 推荐(0) 编辑
  2013年11月4日
摘要: 斐波那契函数 不过因为有1000个数据 所以要用大数#include #include #define N 1000char s[1002][N];void ans(int *a, int *b){ for(int i=0; i=0; --k) if(a[k]) break; for(int i=k; i>=0; --i) s[j++]=a[i]+'0';}void solve(){ int a[N]; int b[N]; int c[N]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b))... 阅读全文
posted @ 2013-11-04 22:27 风流monkey 阅读(111) 评论(0) 推荐(0) 编辑
  2013年10月31日
摘要: 规律题k 1 2 3 4 5 6 7 8....1 1 2 3 4 5 6 7 8....2 1 3 6 10 15 20...3 1 4 10 20 35 55...就是dp[i][j]=dp[i-1][j]+dp[i-1][j]#include #include #define N 110#define mod 1000000int dp[N][N];void solve(){ memset(dp, 0, sizeof(dp)); for(int i=1; i<N; ++i) dp[i][1]=dp[0][i]=1; for(int i=1; i<N; ++i) {... 阅读全文
posted @ 2013-10-31 23:35 风流monkey 阅读(165) 评论(0) 推荐(0) 编辑
  2013年10月27日
摘要: 素数表+快速幂#include #include #include #include #include #include #include #define N 65000+10#define INF 0x3f3f3f3f#define LL long longusing namespace std;int n;bool prime[N];void is_prime(){ prime[0]=prime[1]=false; for(int i=2; i<N; ++i) { if(prime[i]) { for(int j=i+i;... 阅读全文
posted @ 2013-10-27 16:48 风流monkey 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 简单的概率,递推学的不好,只能分了四步来做,因为只有16支队伍,经过四轮就可以决出冠军#include #include #include #include #include #include #include #define N 50000+10#define INF 0x3f3f3f3fusing namespace std;int n;char s[20][20];double dp[5][20];double w[20][20];int p[20];int main(){ for(int i=0; i<16; ++i) scanf("%s",s[i]); me 阅读全文
posted @ 2013-10-27 12:56 风流monkey 阅读(210) 评论(0) 推荐(0) 编辑
  2013年10月24日
摘要: 巨水。。。直接回溯暴力居然过了。。。#include #include #include #define N 110char s[6][5]= {"XXL","XL","L","M","S","XS"};int solve(char *str){ for(int i=0; in) return false; return true; } int u=ans[cur].u; int v=ans[cur].v; num[u]++; if(num[u]>n) num[u]-- 阅读全文
posted @ 2013-10-24 23:21 风流monkey 阅读(116) 评论(0) 推荐(0) 编辑