顯示具有 程式設計比賽 標籤的文章。 顯示所有文章
顯示具有 程式設計比賽 標籤的文章。 顯示所有文章

2008年5月24日 星期六

96 試題一

ISBN(International Standard Book Number)是一種世界共通的書籍編碼方法,世界上任何一本書籍之出版,皆有著唯一的一組ISBN碼。此碼由十個位數組成,每一位數可以為0~9的任何一個數字,或者為X,代表此位數為10;試寫出一個程式來判斷所輸入的ISBN碼是否為合法的。其判斷方法如下,首先,將此ISBN碼的十個位數分開,自左而右依次為第一位數,第二位數至第十位數,接著進行第一次的累加,使得第二位數成為第一位數到第二位數的和,第三位數為第一位數到第三位數的累加和,第十位數為第一位數到第十位數的累加和;進行完第一次的累加和後,接著再依照相同之方法進行第二次的累加動作,我們稱此時最後所求得之累加和為此ISBN碼之識別碼,倘若此識別碼為11的倍數,則此ISBN碼為合法的,故請輸出YES,反之請輸出NO。注意:為便於識別,在此ISBN碼中可能會插入'-'符號,此符號不具任何意義,可以直接忽略它。例如,若輸入之ISBN碼為013-162-959X,則其運算之過成如下表所示:

ISBN碼 0 1 3 1 6 2 9 5 9 10(X)
第一次累加和 0 1 4 5 11 13 22 27 36 46
第二次累加和 0 1 5 10 21 34 56 83 119 165

經由計算可得其識別碼為165,乃是11之倍數,故此為一合法之ISBN碼,因此應該要輸出YES於螢幕上。

試題一解答
試題目錄
回到首頁

2008年5月22日 星期四

96 試題二

實踐大學高雄校區資管系96學年程式設計比賽試題

題二:亂數產生器


運用電腦進行模擬時經常用到亂數,產生虛擬亂數的方法之一是使用下列的公式
seed(x+1) = [seed(x) + STEP] % MOD

%是計算餘數。
此一公式可以產生0到MOD-1之間的數,這個公式有個問題,就是產生的亂數會週而復始,有相同的序列。減少這種情形必須慎選STEP和MOD兩數,以產生較佳的平均分配亂數,值在0與MOD-1間。

例如,如果STEP=3且MOD=5,這個公式將產生0、3、1、4、2的重複循環,每次循環,所有0到MOD-1之間的數字都會出現。此公式的一個特性是如果每次seed(x)都產生相同seed(x+1),則每次循環都會產生平均分佈的虛擬亂數。

如果STEP=15且MOD=20,這個公式將產生0、15、10、5的重覆序列(如果seed設定不是零,則啟始值不從零開始)。這個STEP和MOD選擇就很糟,因為不是0和MOD-1之間的每個數字都出現。
你的程式就是決定是否選定的STEP和MOD會產生平均分配的虛擬亂數。
輸入值
每一行數入一對整數STEP和MOD,且 1 <= STEP, MOD <= 100,000
輸出值
每一行輸出包含STEP值佔1~10格向右調整,MOD值佔11~20格向右調整,印出Good Choice或Bad Choice從第25格開始,向左調整。當這個亂數產生了MOD個亂數時,包括了0至MOD-1之間的每個數字,則印出Good Choice,否則印出Bad Choice。在每個測試輸出後,你應該再列印一個空行。
範例輸入
3 5
15 20
63923 99999

範例輸出
         3         5     Good Choice
15 20 Bad Choice
63923 99999 Good Choice



試題二解答(即ACM problem 408解答)
試題目錄
回到首頁

Problem 408 Uniform Generator,平均隨機亂數產生器

這個題目要求每個亂數範圍內的數字若只出現一次,就是好的選擇。我直接想到用陣列來存放每個數字出現的次數,但是陣列要大到100000這麼大,使用C語言時,這就不是個好的辦法。後來我用了土方法,全部亂數產生一次(100000個對電腦來說,一下子就做完了),所有數字加總的結果與公式做比對(公式就是上底加下底乘高除二),不相等就是Bad choice。這個做法上傳ACM裁判系統後,也過關了。
重點C語言程式碼如下:

for (i=0;i<mod-1;i++)
{
seed = (seed+step)%mod;
sum += (double)seed;
}
if (((double)mod-1)*mod/2.0!=sum)
isBad = 1;

程式設計比賽題目二
p408題目連結
回ACM題庫目錄
回首頁

2007年9月30日 星期日

ACM 比賽題庫解題

ACM 程式設計題庫解答
100 The 3n + 1 problem
101 The Blocks Problem
102 Ecological Bin Packing
105 The Skyline Problem
107 The Cat in the Hat
108 Maximum Sum
113 Power of Cryptography
118 Mutant Flatworld Expolrers
119 Greedy Gift Givers
130 Roman Roulette
136 Ugly Numbers
145 Gondwanaland Telecom
146 ID Codes
147 Dollars
151 Power Crisis
160 Factors and Factorials
167 The Sultan's Successors
170 Clock Patience
190 Circle Through Three Points
193 Graph Coloring
195 Anagram
216 Getting in Line
253 Cube painting
256 Quirksome Squares
263 Number Chains
264 Count on Cantor
272 Tex Quotes
291 The House Of Santa Claus
294 Divisors
299 Train Swapping
300 Maya Calendar
311 Packets
324 Factorial Frequencies
326 Extrapolation Using a Difference Table
332 - Rational Numbers from Repeating Fractions
339 SameGame Simulation
340 Master-Mind Hints
341 Non-Stop Travel
344 Roman Digititis
350 Pseudo-Random Numbers
362 18,000 Seconds Remaining
369 Combinations
374 Big Mod
375 Inscribed Circles and Isosceles Triangles
382 Perfection
389 Basically Speaking
392 Polynomial Showdown
400 Unix ls
401 Palindromes
406 Prime Cuts
408 Uniform Generator
409 Excuses, Excuses!
412 Pi
424 Integer Inquiry
438 The Circumference of the Circle
439 Knight Moves
440 Eeny Meeny Moo
441 Lotto
442 Matrix Chain Multiplication
443 Humble Numbers
444 Encoder and Decoder
445 Marvelous Mazes
446 Kibbles `n' Bits `n' Bits `n' Bits
455 Periodic Strings
458 The Decoder
459 Graph Connectivity
465 Overflow
466 Mirror, Mirror
471 Magic Numbers
474 Head / Tails Probability
476 Points in Figures: Rectangles
477 Points in Figures: Rectangles and Circles
482 Permutation Arrays
483 Word Scramble
488 Triangle Wave
492 Pig-Latin
494 Kindergarten Counting Game
495 Fibonacci Freeze
499 What's The Frequency, Kenneth?
530 Binomial Showdown
534 Frogger
541 Error Correction
543 Goldbach's Conjecture
568 Just the Facts
573 The Snail
575 Skew Binary
579 ClockHands
583 Prime Factors
587 There's treasure everywhere!
591 Box of Bricks
617 Nonstop Travel
619 Numerically Speaking
619 Numerically Speaking
623 500!
624 CD
626 Ecosystem
639 Don't Get Rooked
640 Self Numbers
665 False coin
668 Parliament
673 Parentheses Balance
674 Coin Change
679 Dropping Balls
686 Goldbach's Conjecture (II)
706 LCD Display
725 Division
729 The Hamming Distance Problem
740 Baudot Data Communication Code
748 Exponentiation
750 8 Queens Chess Problem
755 487--3279
763 Fibinary Numbers
784 Maze Exploration
785 Grid Colouring
808 Bee Breeding
821 Page Hopping
825 Walking on the Safe Side
834 Continued Fractions
880 Cantor Fractions
913 Joana and the Odd Numbers
944 Happy Numbers
948 Fibonaccimal Base
974 Kaprekar Numbers
993 Product of digits
10004 Bicoloring
10008 What's Cryptanalysis?
10010 Where's Waldorf?
10013 Super long sums
10015 Joseph's Cousin
10018 Reverse and Add
10019 Funny Encryption Method
10026 Shoemaker's Problem
10034 Freckles
10035 Primary Arithmetic
10038 Jolly Jumpers
10041 Vito's family
10048 Audiophobia
10055 Hashmat the brave warrior
10062 Tell me the frequencies, also solved by David.K
10071 Back to High School Physics
10074 Take the Land
10079 Pizza Cutting
10082 WERTYU
10099 The Tourist Guide, see 10048 or 534
10102 The path in the colored field
10104 Euclid Problem
10105 Polynomial coefficients
10106 Product
10107 What is the Median?
10110 Light, more light
10126 Zipf's Law
10127 Ones
10137 The Trip
10147 Highways, see 10034
10161 Ant on a Chessboard
10182 Bee Maja
10189 Minesweeper
10209 Is This Intergration?
10220 I Love Big Numbers !
10254 The Priest Mathematician
10295 Hay Points
10297 Beavergnaw
10300 Ecological Premium
10302 Summation of Polynomials
10327 Flip Sort
10370 Above Average
10300 Ecological Premium
10346 Peter's Smokes
10359 Tiling
10392 Factoring Large Numbers
10393 The One-Handed Typist
10394 Twin Primes
10397 Connect the Campus, see 10034
10405 Longest Common Subsequence
10409 Die Game
10420 List of Conquests
10432 Polygon Inside A Circle
10450 World Cup Noise
10452 Marcus
10465 Homer Simpson
10473 Simple Base Conversion
10474 Where is the Marble?
10491 Cows and Cars
10494 If We Were a Child Again
10497 Sweet Child Makes Trouble
10499 The Land of Justice
10515 Powers Et Al.
10519 !!REALLY STRANGE!!
10530 Guessing Game
10533 Digit Primes
10539 Almost Prime Numbers
10550 Combination Lock
10551 Basic Remains
10573 Geometry Paradox
10579 Fibonacci Numbers
10583 Ubiquitous Religions
10589 Area
10608 Friends
10637 Coprimes
10649 Danger Point
10664 Luggage
10673 Play with Floor and Ceil
10678 The Grazing Cows
10684 The jackpot
10696 f91
10759 Dice Throwing
10763 Foreign Exchange
10783 Odd Sum
10784 Diagonal
10789 Prime Frequency
10790 How Many Points of Intersection?
10810 Ultra-QuickSort
10812 Beat the Spread!
10815 Andy's First Dictionary
10878 Decode the tape
10903 Rock-Paper-Scissors
10905 Children's Game
10911 Forming Quiz Teams
10912 Simple Minded Hashing
10916 Factstone Benchmark
10919 Prerequisities?
10921 Find the Telephone
10922 2 the 9s
10924 Prime Words
10929 You can say 11
10931 Parity
10963 The Swallowing Ground
10970 Big Chocolate
10994 Simple Addition
11000 Bee
11005 Cheapest Base
11015 05-2 Rendezvous
11038 How many 0's?
11069 A Graph Problem
11121 Base -2
11150 Cola
11172 Relational Operators
11185 Ternary
11192 - Group Reverse
11244 Counting Stars
11326 Laser Pointer
11342 Three-square
11401 Triangle Counting
11417 GCD
11428 Cubes
11437 - Triangle Fun
11455 Behold my quadrangle
11462 Age Sort
11461 Square Numbers
11470 Square Sums
11479 Is this the easiest problem?, see 11455
11483 Code Creator
11498 Division of Nlogonia
11520 Fill the Square
11522 Pyramid Number
11526 H(n)
11530 SMS Typing
11538 Chess Queen
11541 Decoding
11547 Automatic Answer
11586 Train Tracks
11597 Spanning Subtree
11608 No Problem
11609 Teams
11614 Etruscan Warriors Never Play Chess
11621 Small Factors
11636 Hello World!
11650 Mirror Clock
11661 Burger Time?
11666 - Logarithms
11677 Alarm Clock
11689 Soda Surpler
11714 Blind Sorting
11715 Car
11716 Digital Fortress
11727 Cost Cutting
11734 Big Number of Teams will Solve This
11743 Credit Check
11764 Jumping Mario
11805 Bafana Bafana

2007年9月3日 星期一

程式設計比賽試題

實踐大學高雄校區資管系程式設計比賽試題
95學年度題目
試題一
試題二
試題三
96學年度題目
試題一
試題二
試題三

2007年7月10日 星期二

95 試題三

實踐大學高雄校區資管系95學年程式設計比賽的試題,這題不會太難,可是要仔細的測試,注意避免輸出負的或是超過180的角度。

題三:

一般的時鐘都有時針和分針兩隻腳,時針每720分鐘走一圈,分針每60分鐘走一圈,走一圈剛好繞360度。這個題目是要讀取一組時間,然後計算出時針與分針的夾角。時間的格式是0:00到12:00,小時數可能為1或2位數,分鐘數總是2位數,00到59之間。輸出角度為0到180之間的值,角度的精確度到千分之一。例如9:00是90.000度,不是-90,也不是270度。

例如,輸入12:00,輸出0.000;輸入9:00,輸出90.000;輸入8:10,輸出175.000。


回到首頁

Problem 256 Quirksome Squares,就是程式設計比賽第二題

程式設計比賽第二題出自於p256,這題也是很容易的題目,在讀取2, 4, 6, 或8之後,程式碼處理如下:

maxint = 1;
halfd = 1;
for (i=0;i > size;i++)
maxint *= 10;
for (i=0;i > size/2;i++)
halfd *= 10;
for (i=0; i > maxint; i++) {
a = i/halfd;
b = i%halfd;
if ((a+b)*(a+b)==i)
printf("%0*d\n",size,i);
}


其實就用暴力法,一個個算出來,最後的printf可以使用"%0*d來印出適當長度的整數來。



p256 題目連結
回程式設計試題目錄
回ACM題庫目錄
回首頁

2007年7月7日 星期六

95 試題二

實踐大學高雄校區資管系95學年程式設計比賽的試題,這題參賽的隊伍幾乎都答對了,可見是個容易的題目,有興趣的人可以試一下。

題二:
3025這個數字有個巧合,如果你將這數字看成字串,將其分為兩半,每一半也都是一個十位數,亦即30和25,則其和平方

(30+25)^2 = 3025

又變成原來的數字了。你的題目是找出這種類似的巧合數字出來,你的程式要讀取一個位數(2、4、6、或8),然後找出該位數的所有類似巧合的數字。例如4位數,從0000到9999。請注意,0也要算在內,也就是說0001也等於(00+01)^2,也是4位數中的巧合數。例如輸入2時,輸出是
00
01
81


試題二解答
試題目錄
回到首頁

2007年7月6日 星期五

95 試題一:解題

試題一題目連結
試題一可以用暴力法來求解,只是到後來會用到許多的CPU時間。
另外,到了第七組解的時候,整數和將超過int的極限,造成錯誤的答案,所以可以用double來解決這個問題。

#include
#include
#define MAX 100000000
int main(void)
{
double i, j, lsum, rsum;

lsum = 0;
rsum = 2;
i = 2;
j = 2;
while (i<100000000) {
lsum += i-1;
rsum -= i;
if (rsum > lsum)
break;
while (rsum < lsum) {
j++;
rsum += j;
}
if (rsum == lsum) {
printf("%10.0lf%10.0lf\n", i,j);
}
i++;
}
system("pause");
return 0;
}


程式設計比賽試題目錄
回到首頁

2007年7月5日 星期四

95 試題一

實踐大學高雄校區資管系95學年程式設計比賽的試題對初學C者,是個小小的挑戰。

題一:

阿美是個程式設計師,每天早晨都要帶她家的狗出門遛一下,他住在一條長長的街上,每次出門,她隨意地選擇向左或向右走,每次走到街的盡頭,就折返回家。有一次,她發現她右邊住家的門牌號碼累加之後,居然等於她家左邊門牌號碼的累加。這種號碼的現象當然與她的住家門牌號碼與整條街的戶數有關。(整條街由1開始,不分單雙)

你的題目是找出有這種特性的數字組合,亦即門號與戶數,你必須列出十個這樣的數字組合,每個數字佔10個欄寬,向右靠齊。列出六個以內不算分。前三個的答案範例如下:

6 8
35 49
204 288


試題一解答
試題目錄
回到首頁