[問題]一題找最小數目的方塊足夠蓋滿一個長方形的問題

看板C_and_CPP作者 (哥)時間14年前 (2011/10/17 01:15), 編輯推噓0(0011)
留言11則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) notebook + cmd 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) stdio.h,stdlib.h 問題(Question): http://codeforces.com/problemset/problem/1/A 餵入的資料(Input): 不知 預期的正確結果(Expected Output): AC 錯誤結果(Wrong Output): wrong answer on test 16 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <stdlib.h> int main(){ int n,m,a; scanf("%d %d %d",&n,&m,&a); int b,c; b = m/a; c = n/a; int d = 0; if(a<=n && a<=m){ if(n%a==0 && m%a==0){ d = b*c; } else if(n%a==0 && m%a!=0){ d = c*(b+1); } else if(n%a!=0 && m%a==0){ d = b*(c+1); } else if(n%a!=0 && m%a!=0){ d = (b+1)*(c+1); } } else if(a<=n && a>m){ if(n%a==0){ d = c; } else if(n%a!=0){ d = c+1; } } else if(a>n && a<=m){ if(m%a==0){ d = b; } else if(m%a!=0){ d = b+1; } } else if(a>n && a>m){ d = 1; } printf("%d",d); return 0; } 補充說明(Supplement): 山窮水盡疑無路...... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.243.180

10/17 01:27, , 1F
想法?
10/17 01:27, 1F

10/17 01:30, , 2F
第一個if是長寬都>=a 然後各別整除a or not 去判+1否
10/17 01:30, 2F

10/17 01:31, , 3F
下面兩個elseif是長或寬超過a 看另一個 方法同第一個if
10/17 01:31, 3F

10/17 01:32, , 4F
請修改為較符合內文的標題, 否則刪文
10/17 01:32, 4F

10/17 01:32, , 5F
最後一個else if是當長寬都超過a 就只需要一個
10/17 01:32, 5F

10/17 01:33, , 6F
b是長寬其一除以a的商 c則是另一個 d是解
10/17 01:33, 6F

10/17 01:34, , 7F
ok 等我一下....
10/17 01:34, 7F
※ 編輯: myjackchen 來自: 140.112.243.180 (10/17 01:40)

10/17 01:41, , 8F
看板上好相看不出來有該標題><但我已改了!!!!
10/17 01:41, 8F
※ 編輯: myjackchen 來自: 140.112.243.180 (10/17 01:41)

10/17 01:41, , 9F
目前myjackchen除錯進度■■■■□□□□□□100% (∩_∩)
10/17 01:41, 9F

10/17 01:41, , 10F
文章列表按大T改標題
10/17 01:41, 10F
※ 編輯: myjackchen 來自: 140.112.243.180 (10/17 01:43)

10/17 22:56, , 11F
greedy?
10/17 22:56, 11F
文章代碼(AID): #1Ecn4qAK (C_and_CPP)