/* cs */ /* * Problem : LUCKY * Contest : UOI-2006 (Dnepropetrovsk) * Type : Solution * Date : Aprlil 1, 2006 * Author : Shamil Yagiyayev * Language : C# * Compiler : .NET 1.1 * Algorithm: Author Solution. Allows operating with multiple tests in one folder, generates statistics. */ using System; using System.Collections; using System.IO; using System.Text; using System.Text.RegularExpressions; public class IntSequence { public int[] s; public override string ToString() { StringBuilder sb = new StringBuilder(); for (int i=0; i /// Fills the poland array /// /// Next symbol from ticket to use /// Current index in poland /// How many operations we can add /// Actual depth of the recursion static void FillPoland(int depth, int curr, int operations, int plnum) { // if (solution != null) return; if (depth == TICKET_LENGTH && operations == 0) { if (poland[0] == k || poland[0] == -k) { solution = (string[]) pl.Clone(); solDepth = plnum; manySols++; if (poland[0] == k) haveToUseUnary = false; if (solDepth < minSolDepth) minSolDepth = solDepth; if (solDepth > maxSolDepth) maxSolDepth = solDepth; WriteSolution(); } return; } if (depth < TICKET_LENGTH) { for (int i=1; i<=TICKET_LENGTH-depth; i++) { poland[curr] = int.Parse(ticket.Substring(depth,i)); pl[plnum] = ticket.Substring(depth,i); FillPoland(depth+i, curr+1, operations+1, plnum+1); } } if (operations > 0) { int a = poland[curr-2]; int b = poland[curr-1]; int prev = poland[curr-2]; poland[curr-2] = a+b; pl[plnum] = "+"; FillPoland(depth, curr-1, operations-1, plnum+1); poland[curr-2] = a-b; pl[plnum] = "-"; FillPoland(depth, curr-1, operations-1, plnum+1); poland[curr-2] = a*b; pl[plnum] = "*"; FillPoland(depth, curr-1, operations-1, plnum+1); if (b !=0 && a % b == 0) { poland[curr-2] = a/b; pl[plnum] = "/"; FillPoland(depth, curr-1, operations-1, plnum+1); } poland[curr-2] = prev; } } static void PrintPoland(string[] a, int leng, StreamWriter sw, bool operations) { bool written = false; for (int i=0;i= solDepth) haveToUsePlus = false; if (Array.IndexOf(solution, "-") == -1 || Array.IndexOf(solution, "-") >= solDepth) haveToUseMinus = false; if (Array.IndexOf(solution, "*") == -1 || Array.IndexOf(solution, "*") >= solDepth) haveToUseMultiply = false; if (Array.IndexOf(solution, "/") == -1 || Array.IndexOf(solution, "/") >= solDepth) haveToUseDivide = false; IntSequence iseq = new IntSequence(solution, solDepth); bool was = false; for(int i=0;i