奥数和算法
作者:yaya | 时间:2011年9月20日 | 分类 随便写写 | 标签 奥数 算法 | 3回复
今天做了一道算法题,没有完成。很是郁闷。
突然想起了对于奥数的评价:“它存在的唯一作用就是为了证明自己很笨”。
这样看来,我突然去做算法题,无疑是自己跟自己过不去。为了让自己觉得自己很笨。之所以做,是想做出来,然后数落别人很笨,但结果往往都是这样,自己也做不出来,并且内心弄得来很纠结。
这,就是奥数和算法都具有得魅力。征服与被征服,解决与被解决。
相比算法,奥数更是伤人的利器。算法伤人,还停留在懂算法的层面上,好歹谈论算法的也是比较专业的。而奥数则不同,小学就有奥数,不知道幼儿园出奥数没。而我是家里最大的哥哥,这就免不了弟弟妹妹来问我奥数题。这玩意简直就是无底洞。别管什么学历什么专业了,一道小学奥数,就可以打击到你脆弱的智商信心。越做越没思路,越做越没答案,越做越想坚持做出来,越做越泪奔。其实到最后,你可能也没做出这道小学奥数题,倒是产生了想重新上小学的冲动。
高中参加计算机奥赛培训,是我对奥赛仅存的好感。倒不是因为奥赛本身,而是当时和几个同学借着奥赛上机训练的理由,天天不上课待图书馆电子阅览室上网打游戏。那个时候的感觉就是,奥赛太有意思了。老师来了,问搞定了些什么算法没,我们几个就随便弄个程序跑跑给老师看。我记得当时的班长也参加了,他用c搞了个函数画图的,很得意地给老师看,结果被老师给批了一顿,说你哪是算法。班长很无辜,因为就他没打游戏再搞程序,然后还被说。最后我们几个坚持到后来地也就几个人了,水平都很不行,勉强混个省一二等奖也就罢了。这玩意脸皮不厚的人是玩不起的,一次次被证明智商低,还得一次次去尝试再被证明。
什么事都差不多是这样。想要好成绩,就得多付出,同时还得抱着付出不一定有收获的心态(还真不容易。。。)
不过也只能走下去,解决问题,继续向前。

程设问题
作者:chenpei | 时间:2008年4月18日 | 分类 随便写写 | 标签 程序 算法 编程 | 0回复
这题不错,看看吧
平板问题
Description
一个平板被一组大小不等的长方形覆盖,现在需要为每个长方形上一种颜色。每个长方形需要上的颜色是预先确定的。每种画笔上一种颜色。但为了避免画笔将涂料滴到已经上好色的、且颜色不同的长方形上,在对一个长方形A上色前,要求:位于A正上方的其它长方形都已上好色。每取一次画笔,可以为多个长方形上色。请编写一个程序,计算为了完成一个平板的全部上色,最少需要取多少次画笔。
注意,如果一只笔被多次使用,每次使用都会记数一次.

Input
输入的第一行包含一个整数 M,表示有 M 组测试数据 (1 <= M <= 10). 对于每组测试数据,第一行包含一个整数 N, 表示矩形的个数,随后的 N 行描述所有的矩形信息。每个矩形 R 由包含在同一行的 5 个整数描述: R的左上角的 y 和 x 坐标, R的右下角的 y 和 x 坐标,最后是 R 的颜色.
注意:
- 颜色值是 1 .. 20 之间.
- 平板左上角是(0,0).
- 坐标取值在 0 .. 99 之间.
- N 的取值范围在 1..15 之间.
Output
每组测试数据输出一行,包含取笔的最小次数.
Sample Input
Sample Output
3
1 7 0 0 2 2 1 0 2 1 6 2 2 0 4 2 1 1 2 4 4 2 1 4 3 6 1 4 0 6 4 1 3 4 6 6 2
哈哈
作者:chenpei | 时间:2008年4月12日 | 分类 随便写写 | 标签 程序 算法 编程 | 1回复
Description
The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's call the missing tile 'x'; the object of the puzzle is to arrange the tiles so that they are ordered as:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 x
where the only legal operation is to exchange 'x' with one of the tiles with which it shares an edge. As an example, the following sequence of moves solves a slightly scrambled puzzle:
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
5 6 7 8 5 6 7 8 5 6 7 8 5 6 7 8
9 x 10 12 9 10 x 12 9 10 11 12 9 10 11 12
13 14 11 15 13 14 11 15 13 14 x 15 13 14 15 x
r-> d-> r->
The letters in the previous row indicate which neighbor of the 'x' tile is swapped with the 'x' tile at each step; legal values are 'r','l','u' and 'd', for right, left, up, and down, respectively.
Not all puzzles can be solved; in 1870, a man named Sam Loyd was famous for distributing an unsolvable version of the puzzle, and
frustrating many people. In fact, all you have to do to make a regular puzzle into an unsolvable one is to swap two tiles (not counting the missing 'x' tile, of course).
In this problem, you will write a program for solving the less well-known 8-puzzle, composed of tiles on a three by three
arrangement.
Input
You will receive a description of a configuration of the 8 puzzle. The description is just a list of the tiles in their initial positions, with the rows listed from top to bottom, and the tiles listed from left to right within a row, where the tiles are represented by numbers 1 to 8, plus 'x'. For example, this puzzle
Output
You will print to standard output either the word ``unsolvable'', if the puzzle has no solution, or a string consisting entirely of the letters 'r', 'l', 'u' and 'd' that describes a series of moves that produce a solution. The string should include no spaces and start at the beginning of the line.
Sample Input
Sample Output
ullddrurdllurdruldr
2 3 4 1 5 x 7 6 8
1 2 3
x 4 6
7 5 8
is described by this list:
1 2 3 x 4 6 7 5 8
24点的游戏
作者:yaya | 时间:2008年4月8日 | 分类 学海无涯 | 标签 算法 游戏 编程 | 3回复
朋友说到一个24点游戏的程序,要求输出YES和NO分别代表能运算出24或者不能。
因此就试着做了下。
一个24点的C++程序。
在const int max=5 可以设置几个数字的运算,一般的24点游戏是4个数字,就设置成(4+1)
在const int result=24 设置最好的要求的结果,一般游戏为24.
程序只负责输出能算出结果,YES,不能就是NO。
有时间可以做成界面的程序,并且把表达式输出来。
/////////////////////////////*24 GAME*/
#include <iostream.h>
#include <stdlib.h>
//////////////////////////////////////////////////
const int max=5; //The numbers+1 of input
const int result=24; //The result of all
//////////////////////////////////////////////////
//To Create Temp Array
void createtemparray(const double temp,const int I,const int j,const int p,double a[])
{
int n=1;
for (int k=1;k<=p;k++)
{
if ((k!=i)&&(k!=j))
{
a[n]=a[k];
n++;
}
}
a[n]=temp;
}
//To Make b equals a
void makeit(double b[],const double a[],const int p)
{
b[0]=0;
for (int k=1;k<=p;k++)
{
b[k]=a[k];
}
}
//Procedure that strar the game
void getit(double a[],int p)
{
int j;
double temp;
double temparray[max];
if (p==1)
{
if (a[1]==result)
{
cout<<"YES"<<endl;
exit(0);//exit the program when the fianl result equals result
}
}
else
{
for (int i=1;i<=p;i++)
{
j=i+1;
while (j<=p)
{
/* + */
makeit(temparray,a,p);
temp=a[i]+a[j];
createtemparray(temp,I,j,p,temparray);
getit(temparray,p-1);
/* - */
makeit(temparray,a,p);
temp=a[i]-a[j];
createtemparray(temp,I,j,p,temparray);
getit(temparray,p-1);
/* - */
makeit(temparray,a,p);
temp=a[j]-a[i];
createtemparray(temp,I,j,p,temparray);
getit(temparray,p-1);
/* * */
makeit(temparray,a,p);
temp=a[i]*a[j];
createtemparray(temp,I,j,p,temparray);
getit(temparray,p-1);
/* / */
if (a[j]!=0)
{
makeit(temparray,a,p);
temp=a[i]/a[j];
createtemparray(temp,I,j,p,temparray);
getit(temparray,p-1);
}
/* / */
if (a[i]!=0)
{
makeit(temparray,a,p);
temp=a[j]/a[i];
createtemparray(temp,I,j,p,temparray);
getit(temparray,p-1);
}
j++;
}
}
}
}
////////////////////////////////////////////////////
/////////////main function
int main()
{
double a[max]={0};//a[0]=0 will not be used
for (int i=1;i<=max-1;i++)cin>>a[i];
getit(a,max-1);
cout<<"NO"<<endl;
return 0;//can not become result
}
