1 / 3

11033 :Help my Brother

11033 :Help my Brother. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11033 : Help my Brother 解題者: 賴建維 解題日期: 20 14 年 6 月 12 日 題意: 在 4X4 的棋盤中,每格只能放 1~7 ,每行每列以及雙對角線各別的和為 N ,所有數乘積餘 M 不能大於 P ,印出多少解且如果大於兩組解,印出前兩組, 第一種解法的意思是說如果你把第二列、第三列和第四列放到第一列的後面,這個組合起來的數字最小的就是第一種解法。. 題意範例:

Download Presentation

11033 :Help my Brother

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 11033 :Help my Brother • ★★★★☆ • 題組:Problem Set Archive with Online Judge • 題號:11033: Help my Brother • 解題者:賴建維 • 解題日期:2014年6月12日 • 題意:在4X4的棋盤中,每格只能放1~7,每行每列以及雙對角線各別的和為N ,所有數乘積餘M不能大於P,印出多少解且如果大於兩組解,印出前兩組,第一種解法的意思是說如果你把第二列、第三列和第四列放到第一列的後面,這個組合起來的數字最小的就是第一種解法。

  2. 題意範例: Input : output 453 Set 1: Set 2: Set 3: 395 1 0 8 597 1111 1112 1111 1211 11112111 1111 1121 …. …. 1112 2111 1121 1211 …..

  3. 每行判斷左三個最後一個可推得 每列判斷上三個最後一個可推得 每格有1到7,黃色9格9層迴圈 9格結束後紅色已定,開始判斷。 • 解法: • 討論:不分格子16格直接暴力會TLE,每格都去判斷餘數也會TLE,因為迴圈數多,迴圈內指令數越少越好。 判斷紅色格子 a3 = N-a0-a1-a2 (1<=a3<=7) 餘式判斷方法 X= (a0…a3)%M*(b0…b3)%M*(c0…c3)%M*(d0…d3) X % M <= P(餘式定理) 若從第一列開始迴圈,可達題目要求順序解。

More Related