随笔分类 - OJ编程算法练习
摘要:Q253: Cube painting我們想要為方塊塗上顏色,我們有三種顏色:藍色、紅色、綠色。方塊的每一面塗上其中一種顏色。現在,我們把方塊的6個面以1~6來編號,如下圖Figure 1:因為一個方塊有6面,所以我們有36=729種不同的方式來塗方塊。然而當我們忽略面上的編號時,不同塗方塊的方式就會少很多,那是因為方塊可以旋轉的緣故。請看以下的例子:我們以6個字元來表達一個方塊6個面上塗的顏色(字元為b,r,g其中之一,分別代表blue, red, green)。第i個字元代表第i面上的顏色,例如下圖Figure 2就是rbgggr的圖,Figure 3就是rggbgr的圖。請注意:Figu
阅读全文
摘要:#include <iostream> #include <cmath> using namespace std; int main(int ac, char *av[]) { int step; while (cin >> step, step) { // 确定步数数字所在的列或者行。 //ceil 返回大于或者等于指定表达式的最小整数 int column = (int)ceil(sqrt(step)); // 确定对角线上的数字:column * (column -...
阅读全文
摘要:最近都没有做什么,很懒,也做不出来,干脆看别人的吧这份代码很漂亮#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> struct Teams { char name[35]; int a_rank, b_point, c_games, d_wins, e_ties, f_losses, g_dif, h_sco, i...
阅读全文
摘要:AnanagramsMost crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are ca
阅读全文
摘要:滑雪Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 58507Accepted: 21298DescriptionMichael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一个人可以从某个点滑向...
阅读全文
摘要:就是翻转饼干的题目,代码写得不是很好,算了#include <iostream>#include <string>#include <algorithm>#include <sstream>#include <vector>//#include <iterator>//#include "boost/foreach.hpp"using namespace std;int main(){ //循环处理输入的每组字符串。每次循环一轮要输出最后的0和换行 for (string strLine; getlin
阅读全文
摘要://做这种题我知道了,以后数字能定多大就定多大,最后就long long int,前面都是把数字定义为int,老是WA#include <iostream>#include <string>#include <sstream>#include <algorithm>using namespace std;int main(){ string str1,str2,str3; while(cin>>str1>>str2>>str3) { unsigned long int p = 0; unsigned long
阅读全文
摘要:没做,没感觉,做这类题提不起劲#include <stdio.h> #include <string.h> long long p[10001]; char num[10001]; int main() { long long i,j,k,len,n,mod; char lat[3]; while(scanf("%s%s%lld",num,lat,&n)!=EOF) { memset (p,0,sizeof(p)); len = strlen(num); for(i = 0;i <= len-1;i ++) ...
阅读全文
摘要:这题没做,直接在网上看了别人的代码,对数字的一些问题不是很了解学习一下istringstream的用法:#include <iostream>#include <string>#include <sstream>//使用istringstream()需要调入的头文件using namespace std;string getMaxStr(){ int n=0x7fffffff; string s=""; while(n!=0) { s=(char)(n%10+'0')+s; n=n/10; } return s;}bool
阅读全文
摘要:#include <iostream>#include <algorithm>#include <cstring>using namespace std;int mutil(char * x, char * y , char * z){ char * px = x; char * py = y; int carry =0 , temp; if(strcmp(x,"0") == 0 || strcmp(y,"0") == 0) { z[0] = 0; return 1; } int i,j; for(i = 0 ; *(
阅读全文
摘要:水题,就是把非常大的数组进行相加#include <iostream>#include <algorithm>#include <cstring>using namespace std;char table_atoi[128];//下标字母 对应 数字int main(){ int i =0; char c = '0'; for( ; i < 10 ; ++i ,++c) { table_atoi[c] = i; } char buff[100]; char result[100] = {0}; char carry = 0; int
阅读全文
摘要:该题有ANSI C写了一遍,通过使用二叉树的思想可以很好的解决这个问题,该题是用UVa系统测评的,发现如果用标准的C写代码的话,语法要求真的很严格,提交了几次都是语法错误,单行注释都报错,最要紧的是连内建的bool类型都没有,所以我用int型代替,下面是AC的代码#include <stdio.h>#define Nil -1char left[50], right[50], tree_index[50];char code[40];int top = 0;int tree_root = -1;char* out_buff_is = "Set %d is immediat
阅读全文
摘要:Text-processing tools like awk and sed allow you to automatically perform a sequence of editing operations based on a script. For this problem we consider the specific case in which we want to perform a series of string replacements, within a single line of text, based on a fixed set of rules. Each
阅读全文
摘要:Immediate DecodabilityAn encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the same, that each code has at l.
阅读全文
摘要:Artificial Intelligence?Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understand the problem first!So they don't state a problem like ``U=10V, I=5A, P=?" but rather like ``You have an
阅读全文
摘要:Problem IAutomatic Poetry Input: standard inputOutput: standard outputTime Limit: 2 secondsMemory Limit: 32 MB“Oh God”, Lara Croft exclaims, “it’s one of these dumb riddles again!”In Tomb Raider XIV, Lara is, as ever, gunning her way through ancient Egyptian pyramids, prehistoric caves and medival h
阅读全文
摘要:Q10010: Where's Waldorf?給你一個m*n的字元方塊(1 <= m,n <=50),以及一些字串,請你找出這些字串在字元方塊中出現的位置。請參考Sample Output。我們在字元方塊中尋找字串的方向可以有8個:往左、往右、往上、往下、往左上、往左下、往右上、往右下。另外,請忽略字元大小寫,即 A 和 a 應被視為相同的字元。Input輸入的第一列有一個整數代表以下有幾組測試資料。每組測試資料的第1列,有2個整數m,n(1 <= m,n <=50),代表接下來的文字方塊有m列,每列有n個字元。在文字方塊之後的一列有一個整數 k,代表接下來的
阅读全文
摘要:PalindromesA regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left. A mirrored string is
阅读全文
摘要:Q489: Hangman JudgeHangman Judge是一個猜英文單字的小遊戲(在電子字典中常會看到),遊戲規則如下: 答案單字寫在紙上(每個字元一張紙),並且被蓋起來,玩家每次猜一個英文字元(letter)。 如果這個英文字元猜中(在答案的英文單字中有出現),被猜中的字元就被翻開。例如:答案是book,如果你猜o,book中的兩個o就會被視為已猜中。 如果這個英文字元未出現在答案的單字中,就會在hangman的圖中多加一劃。要完成hangman圖共需7劃,如下圖。注意:同一個猜錯的字元只能再圖上畫一劃,例如:答案是book,第一次你猜a(未猜中)會在圖上畫一劃,但第二次...
阅读全文
摘要:Q445: Marvelous Mazes本題中你的任務是寫一支可以畫迷宮的程式,這個迷宮將由A-Z26個字母及*(星號)和空白字元組成。Input and Output你的程式必須從input讀入迷宮的資訊,輸入將包含數列字元,你的程式必須依照指示畫出迷宮。迷宮的每一列都會藉由一系列的數字和字元來表達,數字代表這個字元被使用多少次。如果數字超過一位數則這個字元重複出現的次數為每一位數相加的總合。在input中小寫的"b"代表空白字元,驚嘆號(!)以及換行都代表結束一列。迷宮的列數並沒有限制,但是每一列不會超過132個字元。Sample Input1T1b5T!1T2b1T
阅读全文

浙公网安备 33010602011771号