06 2011 档案
2011百度之星 复赛(下)第一题
摘要:// BDFS2_1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;#define MAX 1000005#define min(x,y) ((x)<(y)?(x):(y))#define INF 99999... 阅读全文
posted @ 2011-06-19 22:44 yangyh 阅读(424) 评论(0) 推荐(0)
2011百度之星 个人源码
摘要:A场:求最大分离度 这道题做错了,3分 #include <iostream>#include <algorithm>using namespace std;int cmp( int arg1, int arg2 ) { return arg1 > arg2;}int main(int argc, char* argv[]){ //freopen("i://input.txt","r",stdin... 阅读全文
posted @ 2011-06-17 00:18 yangyh 阅读(512) 评论(0) 推荐(0)
全排列/递归/八皇后问题
摘要:分别交换第1个元素与第2、3、4、5..len-1个元素 void permutation(char *str,int begin,int len){ if(len==1){ printf("%s\n",str); count++; return; } char tmp = str[begin]; for(int i=0;i<len;i++){ char tmp2=str[begin+i]; s... 阅读全文
posted @ 2011-06-16 23:40 yangyh 阅读(328) 评论(0) 推荐(0)
堆排序
摘要:不稳定排序 比较次数与初始序列有关(基本有序时可以减少堆的调整次数) // HeapSort.cpp : Defines the entry point for the console application.//#include "stdafx.h"void swap(int *a,int *b);void printArr(int arr[],int length){ for(in... 阅读全文
posted @ 2011-06-15 23:32 yangyh 阅读(255) 评论(0) 推荐(0)
6.15笔试
摘要:对称加密和非对称加密 首先引入两个术语:明文和密文。明文是指未加密前的原始数据,密文是指加密后的数据。根据加密和解密时的密码不同,可以分为两种类型的加密解密算法。 (1)对称加密/解密。 加密和解密使用相同的密码,有代表性的有DES、Blowfish、TEA、Base64。对称加密解密的特点是运算相对非对称加密解密简单、速度块,主要应用于需要加密大量数据的场合,例如游戏的资源文件加密。 (2)非对... 阅读全文
posted @ 2011-06-15 23:31 yangyh 阅读(236) 评论(0) 推荐(0)
常用正则表达式
摘要://电子邮件匹配 Regex emailReg = new Regex("^(?<name>\\w+([.+-]\\w+)*?)@(?<domain>\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)$"); 待续 阅读全文
posted @ 2011-06-15 10:13 yangyh 阅读(123) 评论(0) 推荐(0)
POJ 3624 /背包问题
摘要:背包大小为m,对于每一个物品,枚举背包大小j(m到w),对于此物品(重量w、价值v),如果dp[j-w]+v大于dp[j],则采用该方案(dp[j]=dp[j-w]+v) 最后dp[实际背包大小m]就是最大价值 #include <iostream>using namespace std;#define SIZE 12881int dp[SIZE];int main(int argc, char... 阅读全文
posted @ 2011-06-12 14:16 yangyh 阅读(344) 评论(0) 推荐(0)
POJ 1328 贪心、快排/求最少雷达数量
摘要:对于每个岛屿,计算出在区间[A,B]内必须有一个雷达,对这些区间的左坐标进行排序 第一个岛屿的右坐标为right, 初始雷达数量为1,对于第二个岛屿,如果它的右坐标比right小,则说明区间2包含了区间1,不用增加雷达数量,并设置right = 岛屿2的右坐标; 如果它的右坐标比right大,又岛屿2的左坐标大于right,则雷达数量+1,并设置right = 岛屿2的右坐标. #include ... 阅读全文
posted @ 2011-06-10 21:51 yangyh 阅读(530) 评论(0) 推荐(0)
poj 2299/归并排序、逆序数
摘要:归并排序 合并两个有序数组 p,mid 1 3 5 6 7 12 q 2 4 6 8 9 11 找到3比2大,则3之后的都比2大,所以2的逆序数就有mid-p+1个 // 2299.cpp : Defines the entry point for the console application.//#include <iostream>using namespace std;#define MA... 阅读全文
posted @ 2011-06-08 22:27 yangyh 阅读(249) 评论(0) 推荐(0)
POJ 2362/DFS:判断是否能形成正方形
摘要:1011简单改一下就OK了 #include <iostream>#include <algorithm>using namespace std;#define MAX 64int sticks[MAX];bool used[MAX];int stickNum,plen,n;bool compare(int a, int b){ return a > b; }//从beginIndex号开始匹配,... 阅读全文
posted @ 2011-06-06 21:52 yangyh 阅读(440) 评论(0) 推荐(0)
POJ 1011/DFS:子集划分
摘要:问题描述:原有若干sticks,每支stick被分割成若干支,现在要恢复一下。找出这样的子集,使得每个子集的和(plen)相等,并且最小 算法:排序,遍历所有可能plen 剪枝:排序后, a[0] a[1] a[2].....a[n-1],如果想从a[i]开始(不包括i)匹配一个数v,如果i+1,i+2......n-1都匹配不成功了,则肯定i+2,i+3....n-1也匹配不成功了,所以从TL... 阅读全文
posted @ 2011-06-06 18:48 yangyh 阅读(419) 评论(0) 推荐(0)
POJ 1753/BFS:翻转棋
摘要:黑白棋翻转 4X4的棋盘有2^16种状态,如果状态值为0或65535则算法结束 第一层:初始状态 第二层:初始状态翻0、初始状态翻1、初始状态翻……初始状态翻15 第三层: …………………………. 如果该状态值未访问过,则入队列 #include <iostream>#define MAX_STATE 65535#define ALL_BLACK 65535#define ALL_WHITE 0#... 阅读全文
posted @ 2011-06-05 21:12 yangyh 阅读(385) 评论(0) 推荐(0)
POJ 2255/递归:前序中序求后序
摘要:Sample InputDBACEGF ABCDEFG已知二叉树的前序遍历与后序遍历求后序遍历 算法:前序遍历时,第一位为根:D;找到中序中的D,则前面的ABC在左子树,右边的EFG在右子树,则后序为为左子树+右子树+根:solve(BAC,ABC)+solve(EGF,EFG)+D#include <iostream>#include <string>using namespace std;s... 阅读全文
posted @ 2011-06-05 20:17 yangyh 阅读(374) 评论(1) 推荐(0)
POJ 2386/栈:计算水堆数
摘要:Sample Input10 12W........WW..WWW.....WWW....WW...WW..........WW..........W....W......W...W.W.....WW.W.W.W.....W..W.W......W...W.......W.Sample Output3每个点与其周围的8个可以看作同一堆 算法: 1.遍历每个点,如果它没有被访问过,并且有水,则它入... 阅读全文
posted @ 2011-06-05 20:08 yangyh 阅读(295) 评论(0) 推荐(0)
Poj2965,翻转行与列
摘要:-+-----------+--翻一个位置必须翻转所在行与列的其它所有棋子要翻转一个位置而不改变其它位置的方法:该位置所在的行与列的总共7个翻面,知道此方法后这题就可以不用做了网上代码特别多:#include <iostream> using namespace std; const int ROW = 4; int main() { //freopen("d:/t.txt","r",stdin); bool HANDLES[ROW][ROW] = {false}; char handle; int i; for( i = 0; i < 阅读全文
posted @ 2011-06-05 19:47 yangyh 阅读(286) 评论(0) 推荐(0)
POJ 3154/模拟(最小墓地移动长度)
摘要:原来有a个坑,现在要添加b个坑,前后每个坑的间距都要是一样的,环形圈的长度为10000,求最小的坑移动长度原来肯定有一个坑不动,剩下a-1个坑,a+b个坑的平均间距为average,对于这a-1个坑,如果它的坐标x满足:average*j<=x<=average*(j+1),则min(x-average*j,average*(j+1)-x)则为此坑移动距离Sample Inputsample input #12 1sample input #22 3sample input #33 1sample input #410 10Sample Outputsample output #1 阅读全文
posted @ 2011-06-04 11:32 yangyh 阅读(411) 评论(0) 推荐(0)
优先队列/POJ3253,哈夫曼树(求最小木板分割费用)
摘要:描述:一个需要 9 10 11三块木板,现在他有9+10+11长度的木板,但是分割L长度的木板费用就是L,因此求怎么分割费用最小算法:构造哈夫曼树,队列中取出最小的两个数放在底层,它们的和入队,如此反复;可以利用优先队列priority_queue优先队列priority_queue默认大的数先出队,因此需要重载小于号Sample Input3858Sample Output34HintHe wants to cut a board of length 21 into pieces of lengths 8, 5, and 8. The original board measures 8+5+ 阅读全文
posted @ 2011-06-04 10:43 yangyh 阅读(504) 评论(0) 推荐(0)
栈/POJ2395(判断是否为恒真式)
摘要:题目:p q r s t是变量N表示非:如NrE表示是否相等:如Ers = r==sA表示或:如Ars = r||sK表示与:如Krs = r&&sC表示推导:Crs= !r || s算法:只有5个变量,枚举0~31,每位分别是p q r s t的值,看每次计算的值是不是true从字符串结尾开始入栈:是变量则入栈是操作符则出栈计算完成后再入栈最后看栈顶就可以了Sample Input ApNp ApNq 0 Sample Output tautology not#include <stack>using namespace std;int main(int argc 阅读全文
posted @ 2011-06-04 10:21 yangyh 阅读(419) 评论(0) 推荐(0)
一道关于C++ 继承/虚函数 笔试题
摘要:#include "stdafx.h"#include "stdio.h"#include "string.h"class Father{public: name() {printf("father name\n");}; virtual call() {printf("father call\n");}; };class Son: public Father{public: name() {p... 阅读全文
posted @ 2011-06-04 01:06 yangyh 阅读(1967) 评论(0) 推荐(1)