ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1044. Lucky Tickets. Easy!

Working time - 0.14
Posted by And_rey 27 Jul 2004 21:11
var i,n,k,m,j,MaxSum,t:word;
    s,c:longint;
function Dig_sum(x:word):word;
var res:word;
begin
  res:=0;
  while (x>0) do
   begin
     res:=res+(x mod 10);
     x:=x div 10
   end;
  Dig_sum:=res;
end;
begin
 readln(n);
 k:=1; t:=(n div 2);
 for i:=1 to t do k:=k*10; dec(k);
 MaxSum:=9*t;
 s:=0;
 for i:=0 to MaxSum do
  begin
    c:=0;
    for j:=0 to k do
           begin
             if Dig_sum(j)=i then inc(c);
           end;
    s:=s+c*c;
  end;
 if (n mod 2)=1 then s:=s*10;
 writeln(s);
 {Ukraine,Khmelnitsky State University}
end.

Edited by author 27.07.2004 21:14
Re: Working time - 0.14
Posted by hollydonkey 9 Sep 2004 15:43
 We worked exactly the same time! :-)
Re: Working time - 0.14
Posted by SK1 9 Sep 2004 22:13
And i have 0.015 :)
Re: Working time - 0.14
Posted by akademi 30 Oct 2004 17:45
Can you explain your codes?
Re: Working time - 0.125
Posted by Meni Packeou 7 Nov 2007 13:50
My code:



import java.util.Scanner;
import java.io.IOException;
 public class Lucky{
  public static void main(String[] args)throws IOException{
   Scanner sc=new Scanner(System.in);
   int n=sc.nextInt();
   int[] m=new int[37];
   int k=0,l=0,f=(int)Math.pow(10,n/2)-1,f1=n/2*9,luk=0,n1=n/2;
   long s=0;
   while(l<=f){
    k=0;
     luk=l;
     for(int i=1;i<=n1;i++){
      k+=(luk%10);
      luk/=10;
     }
    m[k]+=1;
    l++;
   }
   for(int i=0;i<=f1;i++)
    s+=m[i]*m[i];
   System.out.println(s);
  }
 }
Working time - 0.078
Posted by Viknet 22 Sep 2009 05:24
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try
        {
            //BufferedReader br = new BufferedReader(new FileReader("/Users/Mac/IdeaProjects/text.txt"));

            int n = Integer.parseInt(br.readLine());
            n/=2;
            int k_m = 9*n;
            long s=0;
            for (int k = 0;k<=k_m;k++)
            {
            if (k==0)
            {
                s+=1;
                continue;
            }
            long[][] a = new long[n+1][k+1];
            a[n][k] = 1;
            for (int i=n-1;i>=0;i--)
            {
                for (int j=k;j>=0;j--)
                {
                    for(int y=0;y<=9 && j+y<=k;y++)
                    {
                        a[i][j] += a[i+1][j+y];
                    }
                }
            }
            s+=a[0][0]*a[0][0];
            }
            System.out.println(s);
        }
        catch (IOException e)
        {
            return;
        }
    }
}
Working time - 0.093
Posted by Boland 27 Jul 2011 17:32
My code on C#

using System;
//using System.Text;
//using System.Globalization;
//using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            //Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            int n = int.Parse(Console.ReadLine().Trim());
            //string[] input = Console.ReadLine().Split(new char[]{' ','\t','\r','\n'},
            //                                           StringSplitOptions.RemoveEmptyEntries);
            int count = 0;
            n /= 2;
            for (int sum = 0; sum <= 9 * n; sum++)
            {
                int k = K(sum, n);
                count += k * k;
            }
            Console.WriteLine(count);
            Console.ReadLine();
        }
        static int K(int sum, int n)
        {
            int[] m = new int[sum + 1];
            for (int i = 0; i <= sum; i++)
                if (i > 9) m[i] = 0; else m[i] = 1;
            for (int j = 1; j < n; j++)
            {
                for (int i = sum; i >= 0; i--)
                {
                    int zz = 0;
                    if (i > 9) zz = i - 9;
                    for (int z = zz; z < i; z++) m[i] += m[z];
                }
            }
            return m[sum];
        }
    }
}
Re: Working time - 0.093
Posted by staticor 24 Jun 2013 20:09
I find that there is fewer people using RUBY to solve problem.
So it makes me list my solution, partly ( for the 4|4 situation :) )
------

Sum = Array.new(37,0)
"0000".upto("9999").each {|e|
    temp = 0
    e.each_char { |c|
      temp += c.to_f
    }
    Sum[temp] += 1
}
total = 0
puts Sum.map { |e| total += e*e}