å
æãçµã¿åããççºãæ°ãããããããã話é¡ã«ãªãã¾ããã
http://d.hatena.ne.jp/nowokay/20120911#1347338066
çµã³ã«ãªã£ã¦ãããããããããã«æãã¦ããããã»ã»ã»ãããã£ã¡ã«ãæãã¦ãããããã£ãã®ã§ããããã調ã¹ã¦ã¿ã¾ããã
ã¨ãããããæ ¼åã®ã°ã©ããä½ãå¿
è¦ãããã£ã½ãã®ã§ãã¾ãã¯ãã®ã°ã©ãã®çæããã
ãããªæãã®ã°ã©ãã使ããã¾ãã
ããã§ãå·¦ä¸ãå§ç¹ãå³ä¸ãçµç¹ã¨ãã¦ãå§ç¹ããè¿ãé ã«é ç¹ã«çªå·ãæ¯ã£ã¦ãå¹
åªå
ã§è¾ºãçæãã¦ãã¨ããããã¨ã§å¤§åã«ãªãã¾ãã
ãã¿ãã¬ãã¦ããã¨ããã®ãã°ã©ãã§ã®çµè·¯ã®æ°ãä¸ãåé¡ã¯ãã¯ãã¼ã¹å çã®ãThe Art of Computer Programming Volume 4, Fascicle 1ãã®7.1.4äºå決å®å³ã®ç« ã®æ¼ç¿åé¡225ã¨ãã¦è¼ã£ã¦ãã¾ãã
- ä½è : Donald E. Knuth,åç°è±ä¸
- åºç社/ã¡ã¼ã«ã¼: ã¢ã¹ãã¼ã»ã¡ãã£ã¢ã¯ã¼ã¯ã¹
- çºå£²æ¥: 2011/05/20
- ã¡ãã£ã¢: 大忬
- è³¼å ¥: 2人 ã¯ãªãã¯: 17å
- ãã®ååãå«ãããã° (14ä»¶) ãè¦ã
è§£çã¿ã¦ãããããããã®ã§ããã©ãsimpathã§æ¤ç´¢ããã¨ãä»ã®äººã®è§£èª¬ãåºã¦ããã®ã§ããããåèã«ãã¾ãã
ç®æ¬¡
『フカシギの数え方』 おねえさんといっしょにみんなも25万年数えよう
ããããããçµã¿åããççºããæãï¼æ ¼åã°ã©ããçæãã
おねえさんを組み合わせ爆発から救う:2分決定木を作る
おねえさんを組み合わせ爆発から救う:無駄を省いてBDDを作る
おねえさんを組み合わせ爆発から救う:ZDDがおねえさんを救う
おねえさんを組み合わせ爆発から救う:完結編おねえさんは星になった
ã¨ãããããæ ¼åã°ã©ãçæããã°ã©ã ã®ã½ã¼ã¹
package simpath; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class CreateLattice { /** * ãã¼ã */ public static class LatticeNode{ int x; int y; int num; public LatticeNode(int x, int y, int num) { this.x = x; this.y = y; this.num = num; } } /** * ã¨ã㸠*/ public static class LatticeEdge{ LatticeNode from; LatticeNode to; public LatticeEdge(LatticeNode from, LatticeNode to) { this.from = from; this.to = to; } @Override public String toString() { return String.format("%d:%d", from.num, to.num); } } public static void main(String[] args) throws IOException{ List<LatticeEdge> edges = new ArrayList<>(); Map<Integer, LatticeNode> nodeMap = new LinkedHashMap<>(); generateGraph(3, nodeMap, edges); //æç» BufferedImage img = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, 300, 300); g.setColor(Color.BLACK); int gap = 80;int offset = 15; //ã¨ãã¸æç» ((Graphics2D)g).setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[]{2, 4}, 0)); for(LatticeEdge re : edges){ g.drawLine(re.from.x * gap + offset, re.from.y * gap + offset, re.to.x * gap + offset, re.to. y * gap + offset); g.drawString(re.toString(), (re.from.x + re.to. x) * gap / 2 + offset, (re.from.y + re.to.y) * gap / 2 + offset); } //ãã¼ãæç» ((Graphics2D)g).setStroke(new BasicStroke(1)); for(LatticeNode nd : nodeMap.values()){ int x = nd.x * gap + offset - 10; int y = nd.y * gap + offset - 10; g.setColor(Color.WHITE); g.fillOval(x, y, 20, 20); g.setColor(Color.BLACK); g.drawOval(x, y, 20, 20); g.drawString(nd.num + "", x + 7, y + 14); } g.dispose(); //ä¿å //ImageIO.write(img, "png", new File("c:/Users/naoki/Desktop/lattice.png")); //表示 JFrame jf = new JFrame("lattice"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel l = new JLabel(new ImageIcon(img)); jf.add(l); jf.setSize(400, 350); jf.setVisible(true); } static void generateGraph(int size, Map<Integer, LatticeNode> nodeMap, List<LatticeEdge> edges) { LatticeNode root = new LatticeNode(0, 0, 1); nodeMap.put(0, root); List<LatticeNode> tempNodes = Collections.singletonList(root); int counter = root.num; while(!tempNodes.isEmpty()){ List<LatticeNode> nextNodes = new ArrayList<>(); int maxCount = counter; for(LatticeNode rn : tempNodes){ if(rn.x + 1 < size){ //横㸠maxCount = getNode(size, rn, rn.x + 1, rn.y, nodeMap, nextNodes, edges, maxCount); } if(rn.y + 1 < size){ //ä¸ã¸ maxCount = getNode(size, rn, rn.x, rn.y + 1, nodeMap, nextNodes, edges, maxCount); } } counter = maxCount; tempNodes = nextNodes; } } static int getNode(int size, LatticeNode rn, int x, int y, Map<Integer, LatticeNode> nodeMap, List<LatticeNode> nextNodes, List<LatticeEdge> edges, int counter){ int idx = x + y * size; LatticeNode nn = nodeMap.get(idx); if(nn == null){ nn = new LatticeNode(x, y, counter + 1); nodeMap.put(idx, nn); nextNodes.add(nn); } edges.add(new LatticeEdge(rn, nn)); return nn.num; } }