1、從S開始枚舉每個十進制數,判斷其對應的B進制是否迴文數。
/* ID: gengjia1 LANG: C TASK: dualpal */ #include <stdio.h> #include <stdlib.h> //#define NDEBUG #include <assert.h> int N, S; const char *num = "0123456789"; int main(void) { FILE *fin = fopen ("dualpal.in", "r"); FILE *fout = fopen ("dualpal.out", "w"); int pal; int tmp; int B; char b[33]; int count; int i, j, k; fscanf (fin, "%d", &N); assert(N >= 1); assert(N <= 15); fscanf (fin, "%d", &S); assert(S > 0); assert(S < 10000); i = 0; while(i < N) { S += 1; count = 0; for(B = 2; B < 11; B++) { tmp = S; 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) { count += 1; if(count >= 2) { fprintf(fout, "%d/n", S); i += 1; break; } } } } 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