1、唯一知識點:進制轉換
int 位數=0; while(j不爲零) { b[位數]=j mod 進制 ; j = j / 進制; 位數=位數+1; }
2、思路:窮舉[1,300]所有平方數,轉進制,判斷是否迴文數。注意原數逆序輸出,迴文數不需要。
/* ID: gengjia1 LANG: C TASK: palsquare */ #include <stdio.h> #include <stdlib.h> //#define NDEBUG #include <assert.h> #define N 300 int B; char num[20] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}; char a[10] = {0}; char b[15] = {0}; int main(void) { FILE *fin = fopen ("palsquare.in", "r"); FILE *fout = fopen ("palsquare.out", "w"); int i, j, k, p; int pal; int tmp; char t; fscanf (fin, "%d", &B); assert(B >= 2); assert(B <= 20); for(i = 1; i <= N; i++) { tmp = i * i; pal = 1; j = 0; while(tmp != 0) { b[j] = num[tmp % B]; tmp = tmp / B; j += 1; } b[j] = '/0'; //判斷迴文 for(k = 0; k < j / 2; k++) { if(b[k] != b[j-k-1]) { pal = 0; break; } } if(pal == 1) { tmp = i; k = 0; while(tmp != 0) { a[k] = num[tmp % B]; tmp = tmp / B; k += 1; } for(p = 0; p < k/2; p++) { t = a[p]; a[p] = a[k-p-1]; a[k-p-1] = t; } a[k] = '/0'; fprintf(fout, "%s %s/n", a, b); } } fclose(fin); fclose(fout); exit(0); }
由於這套題某兩題重複了3次,我就只好放在一起寫了 Cow Hopscotch 這道題Bronze,Silver,Gold各有一道,難度依次增加。 對於Bronze的,顏色只有兩種,r和c<=15,O(n^4) 跑一發dp即可(比n
搜索搜索搜索! 每次把一塊積木移動一步,而且每塊積木內部的相對位置是不變的,那麼每次只要記錄積木任意一點的位置表示狀態即可.爲了方便,我們可以設爲每個積木包圍塊的左上角的點. 如何實現? 一種想法是暴搜!可惜T了… 暴
sb題,DP搞不成,解空間太大了。2的31次方 由於數的個數很少,但是解空間很大,加了個剪紙瞎逼搜就過去了 /* ID: daniel.20 LANG: JAVA TASK: tour */ import java.util.*; i
PROB Your Ride Is Here 有些星星上會有UFO來接地球人上去玩,但是這個UFO一次只能有一組人過去。所以要讓這組人知道他們被選中了。方法是這樣的,星星的名字和組名能確定一個小組該去哪兒。然後我們就要寫一個程序,判斷一組
Name That Number Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please
Barn Repair It was a dark and stormy night that ripped the roof and gates off the stalls that hold Farmer John's cows
Transformations A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another
http://usacotraining.blogspot.com/2012/08/problem-333-camelot.html something about github http://blog.sina.com.cn/s/
題目大意 題上的中文題意太不明確了。。。 給出一個拓撲圖,每條有向邊有兩個權值,有兩個人從1出發到n,分別走這兩種權值。問有沒有權值使得這兩個人都能走過這些權值到達n。 思路 看懂了題之後就水了。維護兩個數組表示從1號節點是否能
[題目描述] Packing Rectangles 鋪放矩形塊 IOI 95 給定4個矩形塊,找出一個最小的封閉矩形將這4個矩形塊放入,但不得相互重疊。所謂最小矩形指該矩形面積最小。 所有4個矩形塊的邊都與封閉矩形的邊相平行,圖1示
[題目描述] The Clocks 時鐘 IOI'94 - Day 2 考慮將如此安排在一個 3 x3 行列中的九個時鐘: 目標要找一個最小的移動順序次將所有的指針指向12點。 下面原表格列出了9種不同的旋轉指針的方法,每一種方
//Main idea: //Dynamic Programming //dp[i][j] denote the number of binary trees whose node number is i and height is l
//Main idea //Calculate the shortest path from 'Z' to ohter pastures by Dijkstra algorithm; //And then choose shortest
//Main Idea: //brute force; //shares[i][j] is the initial shares company i own for company j; //fianl_shares[i][j] is t
//Main idea //First we find the two exits and use flood fill to calculate their distance //to any other block;Compare e