
ACM
Vigor
微信
schrodingerman
展开
-
最长公共子序列的长度 Length of Longest common subsequence
求最长最长公共子序列的长度的时间复杂度为O(m*n),空间复杂度同样为O(m*n)算法简介: 首先初始化一个n*n的二维数组m[a.size()][b.size()]全为0 然后写一个二重循环逐个计算二维数组中的值。主要利用一下递推关系: if(a[i] == b[i]) m[i + 1][j + 1] = m[i原创 2012-04-14 21:39:44 · 658 阅读 · 0 评论 -
Sicily 2012 King[Special judge] (不是水题胜似水题)
题目的意思是:在这个柔弱强食的年代,能打架才是王道,打架最强才能称霸天下给你1000个人如果A打赢B,那么A可以傲视B如果A打赢B,B能打赢C,那么A可以傲视C问你谁能傲视群雄?这个题很容易被误导成为一个可达性问题,但是不是。其实如果A打赢B,B能打赢C,C能打赢D,A是不能傲视D的,所以不是可达性问题,可达算法的时间复杂度能到O(n*n*n)其实可以理解成为一个简单矩原创 2012-05-08 00:06:03 · 1116 阅读 · 0 评论 -
2012百度之星资格赛 J:百度的新大厦(不是水题胜似水题)
http://baidu.openjudge.org/qual/J/J:百度的新大厦查看提交统计提问时间限制: 1000ms内存限制: 65536kB描述继百度搜索框大厦之后,百度又于2012年初在深圳奠基了新的百度国际大厦,作为未来百度国际化的桥头堡。不同于百度在北京的搜索框大厦,新的百度国际大厦是一栋高楼,有非常多的楼层,让每个楼中的电梯都能到达所有原创 2012-05-29 21:27:33 · 2292 阅读 · 0 评论 -
2012年百度之星资格赛 E:C++ 与Java(不是水题胜似水题)
http://baidu.openjudge.org/qual/E/E:C++ 与Java查看提交统计提问时间限制: 2000ms内存限制: 65536kB描述在百度之星的贴吧里面,Java的爱好者和C++的爱好者总是能为这两种语言哪个更好争论上几个小时。Java的爱好者会说他们的程序更加整洁且不易出错。C++的爱好者则会嘲笑Java程序很慢而且代码很长原创 2012-05-29 21:25:12 · 811 阅读 · 0 评论 -
ZJUT 1277 素数的位数和 (不是水题胜似水题)
不想说什么,输入只有不到300种,直接暴力打表吧。#include #include #include using namespace std;//int wei;int a[7][60] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0原创 2012-06-02 00:50:26 · 800 阅读 · 2 评论 -
Sicily 4630. 计算三角形面积 (难得水题)
已三点坐标求三角形的面积,直接用行列式吧,希望海伦公式的也可以试试,这里不装B了。在坐标系中已知三顶点坐标由三个顶点构成的三角形,其面积是下式的绝对值:代码如下: #include double area(double T[3][2]){ double sum; sum = fabs(((T[1][0] - T[0][0]) * (T[2][1] - T[0][1]原创 2012-05-24 23:53:25 · 931 阅读 · 0 评论 -
Sicily 3835. 计算三角形的周长 (难得水题)
直接用距离公式,这个不想说什么了。代码如下:#include #include int main(){ int i; int te; double a[6]; double sum; scanf("%d", &te); while(te--) { for(i = 0; i < 6; i++) { scanf("%lf", &a[i]); }原创 2012-05-25 00:05:16 · 781 阅读 · 0 评论 -
ZJUT 1191 12!配对 (不是水题胜似水题)
http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1191直接暴力,搞得我还防溢出,原来没有测试溢出的数据代码如下:#include #include int main(){ int i; int j; int re = 0; int a[100000]; bool b[100000]; int counter = 0原创 2012-05-25 18:55:28 · 825 阅读 · 0 评论 -
ZJUT 1197 倒杨辉三角形 (不是水题胜似水题)
http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1197完全是控制空格的输出,真的。代码如下:#include int main(){ int n; int a[11][11]; int i; int j; int k; int ini; int p; int flag; //freopen("a.txt","r原创 2012-05-26 23:42:13 · 1169 阅读 · 0 评论 -
最长公共子序列求解
求多个字符串的最长公共子序列可以转化为逐步求2个字符串的最长公共子序列来求解直至收敛,虽然过程会比较复杂一些。下面的代码将采用动态规划的方法来求解2个字符串的最长公共子序列的问题,当然里面还包含了测试例子关于本代码的详情解释请看算法导论第二版 机械工业出版社 15章动态规划15.3,看了你再运行代码你会更容易明白#include #include using namespace原创 2012-10-18 21:28:34 · 803 阅读 · 0 评论 -
快速排序的经典实现
快速排序是一种排序算法,虽然最快情况运行时间为O(n*n),但快速排序通常是排序的最佳选择,这是因为它的平均性能好,期望的运行时间为O(n*logn),而且这个渐进的常数因子很小。下面给出他的C++实现。在程序中是选取了最后一个元素为主元,当然,在其他的版本中可以选取其他元素作为主元甚至随机取数来作为主元以获得更好的平衡性。本程序的详情请见 算法导论第二版 机械工业出版社 第7章 快速排序原创 2012-10-19 20:27:08 · 928 阅读 · 0 评论 -
POJ上的水题
分类: poj1002:电话上按键对应着数字。现在给n个电话,求排序。相同的归一类poj1003:求最小的n让1+1/2+1/3+...+1/n大于给的一个实数poj1004:求一堆实数的平均数poj1005:由坐标 (0,0) 开始,以半圆为形状每年侵蚀50m^2,问(0,0)开始到(x,y)结束需要多长时间poj1006:三个周期是常数。现在给三个周期出现转载 2012-12-18 22:11:20 · 675 阅读 · 0 评论 -
Sicily 1158. Pick numbers
DescriptionGiven a matrix of size M*N, the elements of which are integer numbers from -10 to 10. You task is to go from the top-left corner (1, 1) to the bottom-right corner (M, N). You can only mov原创 2013-09-24 21:55:30 · 1252 阅读 · 0 评论 -
Sicily 1011. Lenny's Lucky Lotto
ConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionLenny likes to play the game of lotto. In the lotto game, he picks a list of N unique numbers in the range from 1 to M. If his原创 2013-09-24 20:16:20 · 949 阅读 · 0 评论 -
Sicily 1121. Tri Tiling
DescriptionIn how many ways can you tile a 3xn rectangle with 2x1 dominoes?Here is a sample tiling of a 3x12 rectangle.InputInput consists of several test cases followed by a line co原创 2013-09-26 14:54:53 · 1725 阅读 · 0 评论 -
Sicily 3391 Minimal Sum (难得水题)
排序求和#include #include #include using namespace std;int a[1001];bool cmp(int a, int b){ if(a < b) { return true; } return false;}int main(){ int n; int m; int t; int i; int j;原创 2012-05-07 17:44:09 · 558 阅读 · 0 评论 -
Sicily 2593 Begin the contest with a very easy problem (难得水题)
找最值。#include int main(){ int te; int n; int min; int max; int t; scanf("%d", &te); while(te--) { scanf("%d", &n); scanf("%d", &t); min = t; max = t; n--; while(n--) { sca原创 2012-05-07 17:23:52 · 541 阅读 · 0 评论 -
Sicily 4629 A + B Again(难得水题)
此题不水,谁与争锋!代码如下:#include int gcd(int m, int n){ int middle; if(m > n) { middle = gcd(m - n, n); } if(m < n) { middle = gcd(m, n - m); } if(m == n) { middle = m; } return middle;原创 2012-04-30 01:04:24 · 850 阅读 · 0 评论 -
单源最短路径长度Dijkstra(迪杰斯特拉)算法
求单源最短路径长度的时间复杂度为O(n*n),空间复杂度同样为O(n*n),n为总的节点个数模块化实现函数源代码如下:#define POINT 250#define MAXLENGTH 1000001int road[POINT][POINT];int len[POINT];int found[POINT]; void dj(int count, int source){原创 2012-04-15 14:10:02 · 2429 阅读 · 0 评论 -
Sicily 3912 计算星期几 (难得水题)
日期的各种水,用之前编过的一个程序改改交了就过。代码如下:#include #include int monthLimit[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};char weekDay[7][10] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Frida原创 2012-04-29 13:47:11 · 675 阅读 · 0 评论 -
Sicily 4187 合法三角形 (难得水题)
没有人能阻止水题了代码如下:#include #include int main(){ int te; int a; int b; int c; scanf("%d", &te); while(te--) { scanf("%d %d %d", &a, &b, &c); if(abs(a - b) < c && abs(a - c) < b && abs(原创 2012-04-29 14:31:38 · 610 阅读 · 0 评论 -
Sicily 4700 小明与奶牛 (难得水题)
别怪我,继续水代码如下:#include int main(){ int te; int a[3]; int n; int i; int x; int y; scanf("%d", &te); while(te--) { scanf("%d", &n); for(i = 0; i < 3; i++) { a[i] = 0; } for(原创 2012-04-29 02:23:08 · 1160 阅读 · 0 评论 -
Sicily 4699 简单哈希 (难得水题)
这个是真水。代码如下:#include #include int h[10010];int main(){ int n; int m; int i; int key; int t; scanf("%d %d", &n, &m); for(i = 0; i <= m; i++) { h[i] = -1; } for(i = 0; i < n; i++)原创 2012-04-29 03:01:46 · 1463 阅读 · 0 评论 -
Sicily 3499 分数统计 (难得水题)
看懂就能过。代码如下:#include int main(){ int te; double sum; int n; int t; int i; int min; int max; scanf("%d", &te); while(te--) { min = 101; max = -1; sum = 0; scanf("%d", &n); f原创 2012-04-29 14:48:55 · 646 阅读 · 0 评论 -
Sicily 3718 批改作业 (难得水题)
没有最水,只有更水。代码如下:#include int main(){ int n; int m; int counter; int i; int j; double sum; int t; counter = 0; scanf("%d %d", &n, &m); for(i = 0; i < n; i++) { sum = 0; for(j =0;原创 2012-04-30 00:43:34 · 640 阅读 · 0 评论 -
Sicily 4495 Print permutations解题报告
先求出全排列,然后快速排序排个字典序,就搞定。代码如下:#include #include #include using namespace std;const int MaxNum=9;char iArr[MaxNum];int count;char result[40320][10];void ksort(int l, int h, char a[][10] )原创 2012-04-30 02:09:02 · 801 阅读 · 0 评论 -
Sicily 1094 Cude解题报告
这个题目是搜索指定矩阵中判断是否存在立方体的展开图,看似简单,其实情况复杂。当然,如果你很懂立方体的展开图,这就是一道水题。接下来说下立方体展开图的知识:立体图形的相关问题可以转化为平面图形来研究,但是我的空间想象能力较差,只有通过探索总结出规律才能解决问题。一、立方体平面展开图中的特点1、当我们从立方体的某顶点出发,最多只能观察到三个面,这三个面中必包括三组相对面中的各一个,原创 2012-04-28 21:05:56 · 1033 阅读 · 1 评论 -
Sicily 3497 水仙花数(难得水题)
继续水吧,编程入门题#include int main(){ int i; int a; int b; int c; for(i = 100; i < 1000; i++) { a = i / 100; b = i % 100 / 10; c = i % 10; if(i = a * a * a + b * b * b + c * c * c) {原创 2012-04-29 00:10:45 · 645 阅读 · 0 评论 -
Sicily 3980 二进制转十进制 (难得水题)
不想水了。代码如下:#include #include int main(){ int te; int w; int i; int length; char s[33]; int sum; scanf("%d", &te); while(te--) { sum = 0; scanf("%s", s); length = strlen(s); w原创 2012-04-29 14:00:55 · 650 阅读 · 0 评论 -
Sicily 4312 A + B (难得水题)
逆序A + B水题爱好者都来刷了吧,保证几分钟AC,不喜欢水题的请离开吧代码如下:#include #include int main(){ int te; int i; int length; char aa[10]; char bb[10]; int x; int y; int w; scanf("%d", &te); while(te--) {原创 2012-04-28 23:46:38 · 826 阅读 · 0 评论 -
Sicily 3498 分解质因数 (难得水题)
继续水吧,水水更健康!代码如下:#include #include int isPrime(int n){ int divisor = 1; int i; for(i = 2; i <= sqrt(n) && divisor == 1; i++) { if(n % i == 0) { divisor = 0; } } return divisor;}原创 2012-04-29 00:31:04 · 1254 阅读 · 0 评论 -
Sicily 4189 统计数字(难得水题)
一次快速排序就解决。代码如下:// Problem#: 1486// Submission#: 560195// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommo原创 2012-04-29 13:29:44 · 1218 阅读 · 0 评论 -
Sicily 3725 陶陶考试 (难得水题)
陶陶是个极品。代码如下:#include int main(){ int n; int t; int i; int max; while(scanf("%d", &n) && n != 0) { max = -1000000; for(i = 0; i < n; i++) { scanf("%d", &t); if(t > max) {原创 2012-04-29 14:54:24 · 731 阅读 · 0 评论 -
百度最新面试题集锦
转载请标明出处,原文地址:http://blog.youkuaiyun.com/hackbuteer1/article/details/73489681、实现一个函数,对一个正整数n,算得到1需要的最少操作次数。操作规则为:如果n为偶数,将其除以2;如果n为奇数,可以加1或减1;一直处理下去。例子:func(7) = 4,可以证明最少需要4次运算n = 7n-1 6n/2转载 2014-04-02 22:57:13 · 952 阅读 · 0 评论