Common BoardP and A must satisfy the condition : P ( P + 2A - 1) = 2N good luck ! It's boring! Nobody doesn't know it! and what we can take with this? Test 0 0 0 0 0 1 499 Answer 10 1 2 3 4 5 6 7 8 9 10 This is not the test 4, because I've the same problem but my program does this test correctly. I am not getting how my program is giving wrong answer for some test case#12. Can someone help pls [code deleted] Edited by author 21.06.2013 16:13 Edited by moderator 21.10.2013 20:39 int -> long long Hi Alexey, Thanks for the reply. Could you pls elaborate.I still cant get the point. long long arr[46]; ... printf("%lld", arr[N]); data type Edited by author 25.06.2013 20:33 Edited by author 25.06.2013 20:33 use operator SEEKEOF while seekeof do begin read(x); ..... ..... end; package problemsPackage; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.StringTokenizer; public class IsenbayevNumbers { public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int numberOfTeams = Integer.parseInt(in.readLine()); // Node containing Names of progers in team LinkedList<String[]> teamsList = new LinkedList<String[]>(); LinkedList<String> uniqueParticipantsName = new LinkedList<String>();
while (numberOfTeams != 0) { StringTokenizer tokenizer = new StringTokenizer(in.readLine(), " "); String members[] = new String[3]; int i = 0; while (tokenizer.hasMoreTokens()) { members[i] = tokenizer.nextToken(); addToList(uniqueParticipantsName, members[i]); i++; } teamsList.add(members); numberOfTeams--; } int array[][] = new int[uniqueParticipantsName.size()][uniqueParticipantsName.size()]; fillArray(array,uniqueParticipantsName,teamsList); int participants = uniqueParticipantsName.size(); int esenId = getIndex("Isenbaev", uniqueParticipantsName);
int[] tentativeDistances = new int[participants]; LinkedList<Integer>unvisitedNodes = new LinkedList<Integer>(); for(int i=0;i<participants;i++){ unvisitedNodes.add(i); if(i==esenId) tentativeDistances[i]=0; else tentativeDistances[i]=4000; }
while(unvisitedNodes.size()!=0){ int node = getCurrentNode(tentativeDistances,unvisitedNodes); processNode(node,tentativeDistances,unvisitedNodes,array); } String names[] = new String[uniqueParticipantsName.size()]; for(int i=0;i<uniqueParticipantsName.size();i++){ names[i]=uniqueParticipantsName.get(i); }
java.util.Arrays.sort(names);
for(int i=0;i<names.length;i++){ int index = getIndex(names[i], uniqueParticipantsName); int distance = tentativeDistances[index]; if(distance!=4000) System.out.print(names[i]+" "+distance+"\n"); else System.out.print(names[i]+" undefined\n"); } }
private static void processNode(int node, int[] tentativeDistances, LinkedList<Integer> unvisitedNodes, int[][] array) {
LinkedList<Integer>neighbors = new LinkedList<Integer>(); for(int j=0;j<array.length;j++){ if(node!=j) if(array[node][j]==1) neighbors.add(j); }
for(int i=0;i<neighbors.size();i++){ if(tentativeDistances[neighbors.get(i)]>tentativeDistances[node]+1) tentativeDistances[neighbors.get(i)]=tentativeDistances[node]+1; }
for(int i=0;i<unvisitedNodes.size();i++){ if(unvisitedNodes.get(i)==node){ unvisitedNodes.remove(i); break; } } } private static int getCurrentNode(int[] tentativeDistances, LinkedList<Integer> unvisitedNodes) { int minimum=10000; int index=0; for(int i=0;i<unvisitedNodes.size();i++){ if(tentativeDistances[unvisitedNodes.get(i)]<minimum){ minimum=tentativeDistances[unvisitedNodes.get(i)]; index=unvisitedNodes.get(i); } } return index; } /** * Fill twodimensional array * @param array * @param uniqueParticipantsName * @param teamsList */ private static void fillArray(int[][] array, LinkedList<String> uniqueParticipantsName, LinkedList<String[]> teamsList) { for(int i=0;i<uniqueParticipantsName.size();i++){ String name = uniqueParticipantsName.get(i); for(int j=0;j<teamsList.size();j++){ boolean exist=false; if(teamsList.get(j)[0].equalsIgnoreCase(name) || teamsList.get(j)[1].equalsIgnoreCase(name) || teamsList.get(j)[2].equalsIgnoreCase(name)) exist=true; if(exist){ if(!teamsList.get(j)[0].equalsIgnoreCase(name)) array[getIndex(name, uniqueParticipantsName)][getIndex(teamsList.get(j)[0], uniqueParticipantsName)]=1; if(!teamsList.get(j)[1].equalsIgnoreCase(name)) array[getIndex(name, uniqueParticipantsName)][getIndex(teamsList.get(j)[1], uniqueParticipantsName)]=1; if(!teamsList.get(j)[2].equalsIgnoreCase(name)) array[getIndex(name, uniqueParticipantsName)][getIndex(teamsList.get(j)[2], uniqueParticipantsName)]=1; } } } }
/** * Index of name in list. * @param name * @param uniqueParticipantsName * @return */ private static int getIndex(String name,LinkedList<String> uniqueParticipantsName){ int index=0; for(int i=0;i<uniqueParticipantsName.size();i++){ if(uniqueParticipantsName.get(i).equalsIgnoreCase(name)){ index=i; break; } } return index; }
/** * Store unique participant names into list * @param uniqueParticipantsName * @param string */ private static void addToList(LinkedList<String> uniqueParticipantsName, String string) { boolean exist = false; for (int i = 0; i < uniqueParticipantsName.size(); i++) { if (uniqueParticipantsName.get(i).equalsIgnoreCase(string)) { exist = true; break; } } if (!exist) uniqueParticipantsName.add(string); }
} Edited by author 22.02.2012 14:51 Try this test: 1 a b c Answer is a undefined b undefined c undefined Any suggestions please? I'm a complete newbie at graph theory, so I guess this is something really stupid. Solved it. It wasn't actually a WA but a RT. The point is, #17 seems to contain 300 names with no Isenbaev. Thus, if you always give some fixed ID (say, zero) while giving other people other IDs, you will have an "index out of bounds" exception. My program caught that exception, printed stack trace (as you might have already guessed, my program is in Java) and exited with exit code 9000. Since stack trace is printed in stdout, Timus's checking system couldn't parse that output which resulted in WA. *if you always give HIM some fixed ID, of course Thank you very much.I got AC.>-< because, array need more than 300!! just change char mas_n[200000]={0}; into char mas_n[200005]={0}; )) Edited by author 26.07.2012 18:28 ? Edited by author 10.05.2012 01:08 c2 b2 WHITE a2 b2 DRAW a1 f7 WHITE d2 f7 WHITE g6 e2 BLACK h2 g2 DRAW h8 g7 WHITE Somebody.... Anybody... Help I have WA#11 too. Please help me. give me some tests or any hint. Edited by author 23.01.2007 21:09 I have WA#11 too. Please help me. My solution is very simple. All weight of edges are inverted((a)->(-a)). Ford-Bellman! #include <iostream> //where is my mistake? using namespace std; int main() { int number, result; cout << "Enter number: " << endl; cin >> number; result = number; if (number > 0 && number <= 10000) { for (int i = 1; i<number; i++) { result = result + i; } } else if (number <= 0 && number >= -10000) { for (int j = 1; j > number; j--) { result = result + j; } } else { cout << "Enter the number within the limits of [-10000;10000]" << endl; return main(); } cout << "Otvet: " << result << endl; return 0; } Edited by author 25.02.2013 22:28 You should not output any other text, only the solution. You shound't cout any extral words! For example : not cout << "Enter number: " << endl; and change cout << "Otvet: " << result << endl; tocout << result << endl; #include<iostream> using namespace std; int x=1; int recursive(int n) { if(n==0) return 0; if(n==1) return n; if((n%2)==0) recursive(n/2); else if(n>2 ) { if(n%2) { recursive(n/2); return 1+recursive((n/2)+1); }
} return x; } int maxi(int input) { int temp,result=0; for(int i=0;i<=input;i++) { temp=recursive(i); if(result<temp) { result=temp; } } return result; } int main(void) { int result,input=-1; while(1) { cin>>input; if(input==0) break; result=maxi(input); cout<<result<<endl; } return 0; } you can't do brute thing ... 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 We worked exactly the same time! :-) And i have 0.015 :) Can you explain your codes? 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); } } 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; } } } 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]; } } } 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} My solution uses binary search to find such height for second lamp that garland is never under the floor and this height is the lowest possible. For checking that garland is never under the floor I use simple O(N). I have used a simulation method, first I have built that garland thinking that second lamp is at the same height as first, then Ive calculated then minimum of i*H[i] and lowered the garland by the result, and the resulted height of Nth lamp was the answer. Overall O(n) I think. I like the idea of binary search, but I check that garland is never under the floor in O(1). It easily can be proved, that the garland has an equation x*x+p*x+A. p is a parameter of binary search. Also it's known, that such a parabola(defined in integer points only) has minimum in floor(0.5-p/2). So the checking is very easy. Edited by author 27.07.2004 14:40 Knowing that the form of the garland is parabola and knowing exact solution for h[i], it is very easy to check minimal B: n--; for(i=1;i<n;i++) if((tmp=(n-i)*(n*i-a)/i) >b) b = tmp; That's all! b is answer! It is short. But while you will think about a garland's form, I will have written a solution, based on binary search. In real competition it is better. Actually,we can get the formula by mathematical induction very easily.We can see: h1=h1, h2=h2, Since hn+1=2hn-h(n-1)+2, so we can find: h3=2h2-h1+2, h4=3h2-2h1+6, h5=4h2-3h1+12, and by mathematical induction,not difficult to prove: hn=(n-1)h2-(n-2)h1+n(n+1). Thus we can trace every hi>0 and get the minimum for h2 and then we can find hn. Guys why this cleverness. Binary search - is solution that author recognized I think. But about parabolf thinking is good idea - you're clever boys ;) I have change h2 to h, h1 to A and n to x. Then i have get something like x^2+bx+c. hn>0 if that formula ax^2+bx+c>=0. Its possible only if D<=0. I have found and get the othe formula but now with h like h^2+bh+c. After that i have found h1 and h2, and choose the smallest bigger than 0. And that result i have written in the first formula, and have found B. But the problem that my result is different from the real, but not very much. its my code: #include <stdio.h> #include <math.h> int main() { int N,i; double h1,h2,A,B,min; scanf("%d%lf",&N,&A); h1=A+1.0+2*sqrt(A); h2=A+1.0-2*sqrt(A);; if(h2<h1&&h2>0) min=h2; else min=h1; B=(N-1)*min-(N-2)*A+(N-1)*(N-2); printf("%0.2lf",B); return 0; } PS sorry for my English Edited by author 27.06.2008 02:38 a2=(1/2)a1 + (1/2)a3 -1 a3=(1/3)a1 + (2/3)a4 -2 a4=(1/4)a1 + (3/4)a5 -3 ... an=(1/n)a1 + ((n-1)/n) a(n+1) - (n-1) Just by putting a2 into a3's initial formula a3=(1/2)(a2+a4) -1 and so on, you can get the relationship of an and a(n+1), then you can guess An, and calculate the whole sequence. As long as ai>=0, An can be lower, in this way you'll get the answer. 1 Any (but only one) symbol 0 is replaced by 1. 2 Any (but only one) symbol is removed. 3 A symbol (0 or 1) is inserted at any position. a word is changed only once through 1 or 2 or 3. so it needn't think about a word is changed by both or three. answer of output : Миша — 5 Вадик — 20 Лёша — 12 Саша — 2 Ваня Б. — 1 Никита — 4 Федя — 6 Ваня К. — 1 Ден — 4 Егор — 4 Сяохун — 1 Виталий — 0 Num = int(raw_input()) Array = [0] * (Num + 1) def Rec (Sum, Start): global Array if Start == Num + 1 or Sum + Start > Num: return if Sum + Start <= Num and Sum != 0: Array[Sum + Start] += 1 Rec (Sum + Start, Start + 1) Rec (Sum, Start + 1) Rec (0, 1) print Array[Num] It produces following output (first column input, second column output) 0 0 1 0 2 0 3 1 4 1 5 2 6 3 7 4 8 5 9 7 10 9 11 11 12 14 13 17 14 21 15 26 16 31 17 37 18 45 19 53 20 63 But it exceeds 1 sec limit when the input is 88. Edited by author 23.06.2013 10:28 Edited by author 23.06.2013 10:28 Num = int(raw_input()) Array = [0] * (Num + 1) def Rec (Sum, Start): global Array if Start == Num + 1 or Sum + Start > Num: return if Sum + Start <= Num and Sum != 0: Array[Sum + Start] += 1 Rec (Sum + Start, Start + 1) Rec (Sum, Start + 1) Rec (0, 1) print Array[Num] It produces following output (first column input, second column output) 0 0 1 0 2 0 3 1 4 1 5 2 6 3 7 4 8 5 9 7 10 9 11 11 12 14 13 17 14 21 15 26 16 31 17 37 18 45 19 53 20 63 But it exceeds 1 sec limit when the input is 88. Never mind. Memoization did the trick. i get WA when i use for M unsigned char. i replace to unsigned short and get AC. Used merge sort. |
|