afterward

导航

 

2012年8月23日

摘要: 列举后直接输出:View Code #include<stdio.h>int res[25]= {0,0,0,4,6,0,0,12,40,0,0,171,410, 0,0,1896,5160,0,0,32757,59984,0,0,431095,822229 };int main(){ int n; while(scanf("%d",&n),n) { printf("%d %d\n",n,res[n]); } return 0;}而这些数字是怎么列举出来的看下面代码。将正负号转化为二进制10i=2 两... 阅读全文
posted @ 2012-08-23 11:01 afterward 阅读(297) 评论(0) 推荐(0) 编辑
 

2012年8月20日

摘要: 线段树,虽然没接触过也不太懂,但实用价值好像还蛮大的。View Code /*Sample Input15101 240 331 4 5231 34 51 5Sample OutputCase #1:8 7 6 4 27 4 2 -1 -19 8 7 6 4HintFor the first query, [1,3] has six subintervals: [1,1],[2,2],[3,3],[1,2],[2,3],[1,3]. Interval sums are 101,240,331,341,571,672, correspondence digital roots are 2,6,7 阅读全文
posted @ 2012-08-20 17:33 afterward 阅读(231) 评论(1) 推荐(0) 编辑
 

2012年8月19日

摘要: View Code #include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;const int MM=1000100;long long a[5][205];long long hash[MM];bool counter[MM];int hash_find(long long num){ int t; t=num%MM; if(t<0) t+=MM; while(counter[t] && hash[t 阅读全文
posted @ 2012-08-19 16:50 afterward 阅读(224) 评论(0) 推荐(0) 编辑
 
摘要: View Code #include<iostream>#include<cstdio>#include<queue>using namespace std;char dp[901][8101];//lengthchar d[901][8101];//last digitint main() { for (int i = 1;i <= 9;i++) { dp[i][i * i] = 1; d[i][i * i] = i; } for (int i = 1;i <= 900;i++) { for (int j = i;j <= 8100... 阅读全文
posted @ 2012-08-19 15:21 afterward 阅读(256) 评论(0) 推荐(0) 编辑
 
摘要: 这道题要一步一步来的:(1) n条直线最多分平面问题题目大致如:n条直线,最多可以把平面分为多少个区域。析:可能你以前就见过这题目,这充其量是一道初中的思考题。但一个类型的题目还是从简单的入手,才容易发现规律。当有n-1条直线时,平面最多被分成了f(n-1)个区域。则第n条直线要是切成的区域数最多,就必须与每条直线相交且不能有同一交点。 这样就会得到n-1个交点。这些交点将第n条直线分为2条射线和n-2条线断。而每条射线和线断将以有的区域一分为二。这样就多出了2+(n-2)个区域。故:f(n)=f(n-1)+n=f(n-2)+(n-1)+n……=f(1)+2+……+n=n(n+1)/2+1(2 阅读全文
posted @ 2012-08-19 15:09 afterward 阅读(2581) 评论(0) 推荐(0) 编辑
 
摘要: View Code #include<iostream>using namespace std;bool flag;void DFS(int n,int *A,int *B,int *C){ if(n==0) { flag = true; return ; } if(B[0]&&n==B[1])//n号不会出现在B柱 { flag = false; return ; } if(A[0]&&n==A[1])//n号在A柱上 { A[1]=A[0]-1; DFS(n-... 阅读全文
posted @ 2012-08-19 15:07 afterward 阅读(213) 评论(0) 推荐(0) 编辑
 

2012年8月13日

摘要: 还是看大神的代码把!View Code #include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int MAXN = 200010;char s[MAXN];int next[MAXN];//next 指向的是以此点开始的字符串应该与原串中的哪个字符进行比较// 当然比较的时候此串也要找对应的字符进行比较 如果超过字符串长度 说明相等void getNext(){ int i, j; int l = 1, 阅读全文
posted @ 2012-08-13 16:38 afterward 阅读(269) 评论(0) 推荐(0) 编辑
 

2012年8月12日

摘要: 杭电acm step 的题还真不错。已知抛物线的顶点和两个与直线的交点,求相交的面积View Code /*已知抛物线的顶点和两直线的交点,求相交的面积。用微积分求面积, 简单的数学题.求出k, h, a, b, cy1 = kx + h; y2 = a*x*x + b * x + c;再求出f (x) = (y1 - y2)的原积函数(x2 ~ x3)area = F(x3) - F(x2).*/#include <stdio.h>#include <stdlib.h>int main(){ int cas; double x1, y1, x2, y2, x3, y3 阅读全文
posted @ 2012-08-12 19:27 afterward 阅读(154) 评论(0) 推荐(0) 编辑
 

2012年8月10日

摘要: 求排序的数最少的交换次数。只能相邻的交换。归并排序算法:View Code #include<stdio.h>#include<limits.h>const int MAXN = 500000 + 10;const int INF = INT_MAX;long long tot;//tot为逆序数总数。int arr[MAXN];//将b数组中的元素复制到a数组中。void CopyArray(int a[], int b[], int len, int left){ for(int i = 0; i < len; i++) { a[left++] = b[i]; 阅读全文
posted @ 2012-08-10 12:39 afterward 阅读(238) 评论(0) 推荐(0) 编辑
 

2012年8月9日

摘要: 当想出来只是求余的问题的时候就不难了。其实都不想发的。View Code #include<iostream>#include<stdio.h>using namespace std;int a[53],b[53];int main(){ int t,n,l,r,i,j; int s,w; cin>>t; int d=0; while(t--) { for(i=0;i<52;i++) cin>>a[i]; cin>>n>>l>>r; s=r-l+1; //... 阅读全文
posted @ 2012-08-09 20:02 afterward 阅读(245) 评论(0) 推荐(0) 编辑