03 2012 档案
摘要:1. 数学题,欧几里得算法,求不定方程的整数解问题;2. 必要的数学知识(转):此题其实就是扩展欧几里德算法-求解不定方程,线性同余方程。 设过s步后两青蛙相遇,则必满足以下等式: (x+m*s)-(y+n*s)=k*l(k=0,1,2....) 稍微变一下形得: (n-m)*s+k*l=x-y 令n-m=a,k=b,x-y=c,即 a*s+b*l=c 只要上式存在整数解,则两青蛙能相遇,否则不能。扩展欧几里德算法是用来在已知a, b求解一组x,y使得a*x+b*y=Gcd(a,b)(解一定存在,根据数论中的相关定理)。扩展欧几里德常用在求解模线性方程及方程组中。下面是...
阅读全文
摘要:1. 模拟题,按照题目的要求做即可,但是要细心,比较繁琐,尤其是边界问题;2. 20分钟写完程序,但是WA了七八次,检查了一个小时,最后加上循环输入输出,居然AC了,欲哭无泪。#include #include #include using namespace std;
const int MAXn = 10010; bool cmp(int a, int b)
{ return a > n >> m) { for (i = 0; i > rmovNum[i]; memset(curList, 0, sizeof(curList)); ...
阅读全文
摘要:1. 简单题,根据题意,这个人总是坐着最先到达的自行车到达,因此只需要算出最先到达的自行车的时间即可。2. 值得注意的是出发时间小于0的,这个人不可能坐上这辆车。#include #include using namespace std; int speed;
int stime;
double dtime; int main()
{ int n, min, i; while (cin >> n) { if (n == 0) break; min = 1000000; for (i = 0;...
阅读全文
摘要:1. 简单题#include #include using namespace std; int main()
{ int n, i, ans, t[11], s; while (cin >> n) { if (n == -1) break; memset(t, 0, sizeof(t)); ans = 0; for (i = 1; i > s >> t[i]; ans += s * (t[i] - t[i-1]); } ...
阅读全文
摘要:1. 简单题,故意用了栈,另外从这个题上可以体会到OJ判题模式#include #include #include using namespace std; int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout); stack st; int i, j, n; string str; for (i = 1; ; i++) { cin >> n; if (n == 0) ...
阅读全文
摘要:1. 指针可以操作数组元素#include using namespace std;
int main()
{ int a[5] = {1, 2, 3, 4, 5}; int *p = &a[2]; cout << p[1] << ' ' << p[-2] << endl;
}
2.
阅读全文
摘要:1. 这道题根本不会做,直接看的别人的解体报告,看了别人的解题报告的算法说明,还是不会做,只好看代码了;2. 这篇博客写得比我写得好(http://jovesky.info/blog/2011/08/12/poj-1057-file-mapping-c-edition/),我就是看人家的看懂的;3. 递归+vector,一层套一层,以后还得看看怎么做的。现在思路会了,但是vector还是不会用,上午刚看了primer还是不会用,另外细节问题很繁琐,日后就是为了学递归也得再做一遍这道题。#include #include #include #include using namespace...
阅读全文
摘要:1. 根本没有思路,看到如下的解释,才明白怎么做: 这个题目很经典的说,O(N^3)的DP。 首先偶们考察这样的题目,简化版: 已知一列数,求任意连续若干个数和的最大值。 SAMPLE: 3 2 -6 2 -1 7 原数3 2 -6 2 -1 7 处理3 5 -1 2 1 8 因为是连续若干个自然数的和,那么,前面的某个数字取与不取的条件在于:以前面这个数字为结尾的连续数的和最大值是否大于0,如果大于0,那么这个数字必然要会出现在包括数字的序列中,否则无法做到最大...
阅读全文
摘要:1. 一下午就做了这么一道题,蛋疼的模拟题。刚开始没有考虑当超过100的时候怎么处理,一直WA,上网看解题报告才知道。。。2. memset()函数的用法。只能初始化为0或者-1。当初始值为其他数时,是在每一位上是这个数(这句话没明白),记住只能把数组初始化为0或者-1就行了;3. 此题属于模拟题,不得不说,模拟题的if语句就是多啊;#include #include using namespace std; int main()
{ int step[100], map[101], turn[7], cur[7]; int step_num, i, peo, sx, e...
阅读全文
摘要:1. C++中string类的练习,使用的数据结构慢慢地开始有心得了;2. string类中的+=操作符和append( )函数的使用;3. 这道题很简单,开始出错是因为string类型的变量没有初始化。string str = "";//初始化为空字符串;4. 推荐一个c++的网站(cplusplus.com - The C++ Resources Network)。#include #include #include using namespace std;
struct type
{ string str; char let; int len;
}ltr[3...
阅读全文
摘要:1. 好久没碰到这种难度的题了:看题没思路,经过思考,推算,一次AC。以前的题要不太难,只能看解题报告,要不太简单,不用思考,这种难度的题正好适合我;2. 具体思路是通过P序列还原成括号序列,然后通过括号序列得到W序列的值。注意map[ p[ i ] + i] = ‘)’。通过flag数组标记“)”之前的没有匹配的左括号;3. 这道题属于模拟题(以后知道题的类型就分个类);#include #include using namespace std; int main()
{ int i, j, k, tmp, t, n; int P, W[22], map[50], fl...
阅读全文
摘要:1.物理题,不会求解。。。参考(http://blog.csdn.net/uestcshe/article/details/5621292)推出的公式,直接算出结果的;2. 第一次使用iostream输出有要求的小数。原来在书上看到的cout
#include using namespace std; int main()
{ double Vs, R, C, w, Vr; int n; cin >> Vs >> R >> C >> n; while (n--) { cin >> w; Vr = Vs * R * C ...
阅读全文
摘要:1.题目的大意是给定三个数a1, a2, a3,求出一个数,这个数除以23, 28, 33得到的余数为a1, a2, a3;2.从网上查到用中国余数定理,以下是找到的资料:若某数x分别被d1、、…、dn除得的余数为r1、r2、…、rn,则可表示为下式:x=R1r1+R2r2+…+Rnrn+RD其中R1是d2、d3、…、dn的公倍数,而且被d1除,余数为1;R1 、R2…、Rn是d1、d2、…、dn-1的公倍数,而且被dn除,余数为1;D是d1、d2、…、的最小公倍数;R是任意整数,可根据实际需要决定;且d1、、…、必须互质,以保证每个Ri(i=1,2,…,n)都能求得.根据上面的条件求出常数R
阅读全文
摘要:1.刚开始想成是整个圆了,所以一直出错;2.ceil()函数,第一次用,详见(ceil_百度百科)#include #include using namespace std;
const double PI = 3.1415926; int main()
{ double x, y, n; cin >> n; for(int i = 1; i > x >> y; cout << "Property " << i << ": This property will begin eroding in ye
阅读全文
摘要:1. 试了各种数据类型保存输入的字符串,比如string,字符数组。在string类型中,不能一个一个字符地拷贝字符串,因为字符串末尾还有一个字符。2. 字符型数字转换成int类型;3. 自我感觉change函数写的比较巧妙,跟Curling 2.0有点类似。是把一个数组(有重复元素)无重复的放到另外一个数组。#include
#include
#include
#include
#include
using namespace std;
int telnum[100010];
int tel[100010][7];
int n;
struct Node
{ int ans; ...
阅读全文
摘要:1.字符型数字转换成int型(http://topic.csdn.net/t/20060329/20/4649488.html)
阅读全文
摘要:1.scanf()的用法,见百度百科;2.scanf用来接收小数,把输入变量声明为float不行,声明为double就可以了,scanf里%f不行,但是%lf就行了。#include int main()
{ double sum, in; int num; while(scanf("%lf", &in) != EOF) { if(in == 0.00) break; num = 1; sum = 0.5; while(sum < in) { ...
阅读全文
摘要:1.输出2位小数,用%.2f表示。%m.nf表示输出数据共占m列,其中有n位小数,左端补齐;#include int main()
{ float num[12], ans = 0; for(int i = 0; i < 12; i++) { scanf("%f", &num[i]); ans = ans + num[i]; } printf("%c%.2f", '$', ans / 12); return 0;
}
阅读全文
摘要:1.做得很痛苦的题,过程清楚,也可以用语句描述出来,但是输出结果这块想不清楚;2.参考了别人的代码,跟我写的基本上差不多,只是他递归的时候传递了step,我没有传递,但是设的全局变量,为什么就不行啊??3.这样还一直出错,最后把数组开大了,开到22也不行,直到开到50才AC,为啥啊,范围不就是到20吗?#include #include #include using namespace std;
int sx, sy, ans;
int w, h;
int dir[4][2]= {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int map[50][50];//我...
阅读全文
摘要:1.比迷宫问题多了一个reset按钮,算法还是BFS;2.看解题报告看了很久才看懂,当初自己卡在如何判断该不该走reset这个点;3.BFS和DFS的题的思路已经清晰,就是每道题在结束循环的条件不同,并且需要用到的变量结构不同而已;4.开始弄错横纵坐标了,以后只要保持一致就行。以下是代码,参考别人的,几乎快能背过了。。。#include #include using namespace std;
struct Node
{ int x; int y; int remtime; int step;
} begin;
int map[8][8];
int mar...
阅读全文
摘要:1.成功的使用结构体:想清楚算法需要记录哪些内容,这些内容之间有什么关系,然后再确定用单个变量还是用结构体,还是用结构体数组;2.位与&运算的使用,第一次接触这一块,还是不明白check()函数中使用&运算的道理,这一部分是借鉴来的,自己写着写着逻辑就混乱了。。。关于位运算(位运算);3.知道了typedef的用法,也算是做这道题的额外收获吧;4.这道题错了好几次,方向弄错,多加return等错误,这方面的经验还要慢慢积累;5.这道题最简单的算法是列举每一个modules,dfs找到与它连通的房间,其实和水池那道题基本类似。以下是代码:#include using namesp
阅读全文
摘要:听了MIT的《Introduction to Algorithm》真是着迷,这里把讲过的伪代码中关于排序的实现了,总结在下边1.插入排序,n方的复杂度void insertion_sort(int arr[])
{ for(int j = 1; j = 0 && key < arr[i]) { arr[i+1] = arr[i]; i--; } arr[i+1] = key; }
}2.合并排序,nlog2n复杂度,代码未写
阅读全文
摘要:1.大牛们都说是简单的DFS,想自己A一道,结果还是没A出来,最后还是看了别人的结题报告;2.递归还是不熟悉,做DFS用递归,总是出现错误。通过这个题,用递归函数,首先要包含一个结束条件,然后才能用递归;3.自己第一遍写代码的过程中,学会了用sort()函数对结构体的某一个元素进行排序的方法,参考(C/C++ sort函数的用法_真爱无限_新浪博客);4.自始至终对整道题所要用的变量没有合理的安排,之前做的稍微复杂点的题都这样,如何改进是个问题以下是代码:#include #include using namespace std;
int x, y ,tstep, n;
bool used..
阅读全文
摘要:#include #include #include using namespace std; char tiles[22][22];
int used[22][22];
int count, w, h; void countstep(int i, int j)
{ count ++; if (i > 1 && used[i-1][j] == 0) //向上 { used[i-1][j] = 1; countstep(i-1, j); } if (i 0 && used[i][j-1] == 0) //向左...
阅读全文
摘要:1.思路果然清晰了,十分钟搞定#include #include #include #include using namespace std; int n, k;
queue q;
int step[100010]; int bfs(int a)
{ if(a == k) return step[k]; else { if(a - 1 >= 0 && step[a - 1] == 0) { step[a - 1] = step[a] + 1; q.push(a...
阅读全文
摘要:1.典型的bfs。2.难点在剪枝部分。有一个记录所走step的数组,记录到每个点所走的步数,如果一个点没走过,放进队列中,如果一个点走过,比较原来这个点的step值和由当前点计算的值,如果大,另其等于当前点的step值+1;3.这道题犯了超级低级的错误。。。写好了bfs()函数,结果在main()函数中没有添加bfs();语句,导致调试了好久得不到想要的结果。。。#include #include #include #include using namespace std; struct Node
{ int x, y;
} sta, end; char a, c;
in...
阅读全文
|