2014年2月26日

摘要: 原题链接题目大意:书本印刷都是用大开的纸张对折。比如一个册子一共4页,为了方便装订,外侧印刷1、4页,内侧印刷2、3页,这样对折之后就可以按照正常阅读习惯翻页了。此题目的就是给出书的总页数,要求计算每张纸正反面应该印刷什么内容。解法:不难,但是略微繁琐。先计算需要的纸张数量,然后分别计算正反面的内容。如果书本页码很少,第一张和第二张纸比较特殊,需要单独列出来,其他内页按照公式推算。参考代码:#includeusing namespace std;int main(){ int n,i,j,k,sheet,r; while(cin>>n&&n!=0){ sheet=( 阅读全文
posted @ 2014-02-26 13:59 KK4SBB 阅读(367) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:FM在一个街道n*n街道的(0,0)点,在每个网格里放着cheese,他要尽可能多的吃这些cheese。有两个规则:1)他跑的总距离不能超过k步;2)下一个节点的cheese的块数必须超过这个节点。解法:题目是去年秋天做的,现在看了下貌似就是用一下广搜,从原点开始一个个查找。我直接把当时的代码贴过来了,看看当时写的注释,发现暑假都过了一半了,算法都没有总结好。惭愧了。参考代码:#includeusing namespace std;int n,k,x,y,block[102][102],dp[102][102];int a[4][2]={{1,0},{-1,0},{0,1}, 阅读全文
posted @ 2014-02-26 13:59 KK4SBB 阅读(420) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:按照HTML的语法处理一段字符。这道题算是字符串类型的经典,熟练之后可以做一个简单的html解析器了。解法:没什么好说的,直接代码。参考代码:#include#includeusing namespace std;void hr(){ cout>str){ if(str==""){ br(); len=0; } else if(str==""){ if(len)cout<<endl; hr(); len=0; } else{ if(len+str.size()<80){ if(len!=0)cout<< 阅读全文
posted @ 2014-02-26 13:59 KK4SBB 阅读(264) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:有一个发射站,覆盖范围是半径一定的一个半圆。在一个1000*1000平方米的地盘里有很多接收站。给定发射站的圆心,求最佳角度时能覆盖接收站的个数。解法:本质上就是给一个原点和其他若干点,找出一个可以覆盖最多点的半圆。用了两个函数判断,一个是判断两点之间的距离,即该点到原点的距离是否在半径之内,筛选出第一步满足的点。另一个是判断两个点A、B是否在同一个半圆内,其实先确定一条直线AO,然后规定B点在AO的左侧就算在半圆内。每个点都遍历一次,找出最大值即可。参考代码:#include#includeusing namespace std;bool isInclude(int xx, 阅读全文
posted @ 2014-02-26 13:58 KK4SBB 阅读(257) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:定义了一种数字Humble Number,他们的质因数只包含2、3、5、7中的一个或者几个,求第n个这样的数,1#include#includeusing namespace std;int main(){ double seven,five,three,two; int a,humber[5842]={0},n=0; for(seven=1;seven>a)&&a!=0){ if(a%10==1&&a%100!=11){ //!!! cout format cout<<"The "<<a< 阅读全文
posted @ 2014-02-26 13:58 KK4SBB 阅读(232) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:FM要去逛街,他可以走任何街道,在任何路口转弯。他走一条陌生街道的速度是20公里每小时,走一条熟悉街道的速度是50公里每小时。输入是街道信息,输出消耗时间。解法:本质就是浮点运算,求两点间距离。参考代码:#include#include#include#includeusing namespace std;int main(){ int x0,y0,x1,x2,y1,y2,time; double dist=0.0,d; string str; char *p; while(cin>>x0>>y0){ //x0,y0 is useless, but s 阅读全文
posted @ 2014-02-26 13:58 KK4SBB 阅读(351) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:迭代求自然常数e。解法:没什么好说的,注意数据类型和输出格式。参考代码:#include#includeint main(){ int n=0; double fact,ee; printf("n e\n"); printf("- -----------\n"); printf("0 1\n1 2\n2 2.5\n"); ee=2.5; fact=2; for(n=3;n<10;n++){ printf("%d ",n); fact*=n; ee=ee+1/fact; printf(&quo 阅读全文
posted @ 2014-02-26 13:58 KK4SBB 阅读(155) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:给一个数字,每一位相加求和,不断重复过程,直到剩一位数字。解法:考虑到输入的数字可以很大,把输入按照字符串格式读入,再逐位处理。参考代码:#include #include using namespace std;int main(){ string str; int sum,sum2,i; while(cin>>str&&str!="0"){ sum=0; for(i=0;i0){ sum2+=sum%10; sum/=10; } if(sum2=10); } return 0;} 阅读全文
posted @ 2014-02-26 13:58 KK4SBB 阅读(215) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:Fred想在Louisiana买一套房子,但是堤坝不牢固,每年都要被河水侵蚀50平方英里。题目给出他豪宅的坐标,要求他被迫移民搬迁的年份。解法:也没什么好说的,先求出两点间的距离,即半径,然后算出面积,在除以每年塌方的面积,向上取整即可。参考代码:#include #include #define PI 3.14int main(){ int n=1,N,year; float X,Y,dist,area; scanf("%d",&N); while(n<=N){ scanf("%f%f",&X,&Y); 阅读全文
posted @ 2014-02-26 13:57 KK4SBB 阅读(310) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:叠扑克牌,给出伸出长度,问最多需要几张扑克牌。解法:循环累加。退出循环后向上取整输出。参考代码:#includeusing namespace std;int main(){ double i,len,sum; while(cin>>len&&len!=0.00){ sum=0.0; i=2; while(sum<len){ sum+=1/i; i++; } cout<<int(i+0.5)-2<<" card(s)"<<endl; } return 0;} 阅读全文
posted @ 2014-02-26 13:57 KK4SBB 阅读(301) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:给出一个格子图,求走完所有节点的最短路径距离。解法:简单啊,如果都是奇数,可以走一次斜边,其他情况就是长*宽。参考代码:#include int main(){ int i,k,m,n; double result; scanf("%d",&k); i=1; while(i<=k){ scanf("%d%d",&m,&n); printf("Scenario #%d:\n",i); if(m%2==0||n%2==0){ result = m*n; printf("%.2f\n 阅读全文
posted @ 2014-02-26 13:57 KK4SBB 阅读(240) 评论(0) 推荐(0) 编辑
 
摘要: /*You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only two men are awake, and the ship is controlled by the intellige 阅读全文
posted @ 2014-02-26 13:56 KK4SBB 阅读(224) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:1/2+1/4+1/6+…1/n解法:直接累加即可。参考代码:#includeint main(){ printf("# Cards Overhang\n"); double extend; int n,i; while(scanf("%d",&n)!=EOF){ extend=0.5; for(i=1;i<n;i++) extend+=0.5/(i+1); printf("%5d%10.3lf\n",n,extend); } return 0;} 阅读全文
posted @ 2014-02-26 13:56 KK4SBB 阅读(178) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:大数,20进制的加法计算。解法:convert函数把字符串转换成数组,add函数把两个大数相加。参考代码:#include#includechar* Digit="0123456789abcdefghij";void convert(char*,int*);void add(int*,int*,int*);void print(int*);int main(){ char str1[101],str2[101]; while(scanf("%s",str1)!=EOF&&scanf("%s",str2 阅读全文
posted @ 2014-02-26 13:56 KK4SBB 阅读(358) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:给一个数组{ A1,A2,…,An } ,要求生成另一个数组B1,B2,…,Bn,使得Bi表示的是在数组A中排在i前面大于i的数字的个数。题目的输入是数组A(字母P表示)或者数组B(字母I表示),要求输出对应的B或者A。解法:先读取首字母,如果是P,则调用permutation(),反之调用inversion()。permutation是按照正常方法寻找。inverse是先设置一个空的数组(相当于A数组),按照B数组的顺序一个个往‘A’中放。参考代码:#includeusing namespace std;void permutation();void inversion() 阅读全文
posted @ 2014-02-26 13:56 KK4SBB 阅读(361) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:某人手上有一大批钻石,他同时有一些盒子恰好放下这些钻石,每个盒子可以放一个或多个,问一共有几种方法。解法:这其实是一道排列与组合计算题,主要是写出组合算法的代码,把计算公式转为程序。参考代码:#include#include#include#includeusing namespace std;int fact(int a){ //recursive factorial function if(a==1) return a; else return a*fact(a-1);}int main(){ int i,j,k,m,n,c,c1,c2,sum,ans; int num. 阅读全文
posted @ 2014-02-26 13:56 KK4SBB 阅读(221) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:给出一列数据,不多于30个。如果其中的两个或多个数之和等于这组数据中的另一个数,如{1,2,3}这个数组中存在等式1+2=3,输出这个等式。找出满足条件的所有等式。如果,找不到符合条件的,输出“Can’t find any equations.”。解法:把这个数组的所有数字排序。首先,从小到大开始累加数字,直到和超过数组的最大值,这样我们可以知道,等式左边最多可以有几个数字。然后,从两个加数开始,用深度优先的方法,从左往右搜索,寻找是否存在满足条件的等式。依次递增搜索的深度。参考代码://参考了这篇日志http://blog.csdn.net/scnu_jiechao/art 阅读全文
posted @ 2014-02-26 13:56 KK4SBB 阅读(474) 评论(0) 推荐(0) 编辑
 
摘要: 原题链接题目大意:有这么一个公式 A,B,C(A using namespace std; int dp[5050][1010]; #define maxn 1>ncase; while(ncase--) { cin>>guests>>chopsticks; for(i = chopsticks;i >= 1;i--) cin>>a[i]; for(i = 1;i = j * 3) { dp[i][j] = dp[i - 1][j]; ... 阅读全文
posted @ 2014-02-26 13:55 KK4SBB 阅读(532) 评论(0) 推荐(0) 编辑
 
摘要: /*In this problems, we’ll talk about BIG numbers. Yes, I’m sorry, big numbers again…. Let N be a positive integer, we call S=NN the “big big power” of N. In this time, I will calculate the exact value of S for a positive integer N. Then, I tell you S, you guess N.Note that I may make mistakes in cal 阅读全文
posted @ 2014-02-26 13:55 KK4SBB 阅读(220) 评论(0) 推荐(0) 编辑
 
摘要: /*In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the WWW simply consists of all the pretty (or not so pretty) HTML-pages that you can read with your WWW browser. But back then, one of the main intentions behind the design of the WWW was to unify severa 阅读全文
posted @ 2014-02-26 13:54 KK4SBB 阅读(336) 评论(0) 推荐(0) 编辑