Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | WA #3 | TheDreamCatcher | 1161. Stripies | 26 июн 2013 22:02 | 2 | WA #3 TheDreamCatcher 14 авг 2011 13:17 If you got WA #3, check case n=1 ;) Re: WA #3 [TDUweAI] daminus 26 июн 2013 22:02 | | Test #2 for you! | [TDUweAI] daminus | 1601. АнтиКАПС | 26 июн 2013 21:55 | 1 | input: HELLO. I AM ANJELA! AND YOU? I AM BLONDE. output: Hello. I am anjela! And you? I am blonde. | | Why Test 11 ! | Adhambek | 1963. Воздушный змей | 26 июн 2013 18:04 | 4 | I had troubles with this problem when used fractional arithmetic instead of integer one (WA #32). Maybe this could help. Not pretty sure, but maybe "trapeze". 0 0 2 2 8 2 10 0 Answer: 2 Edited by author 26.06.2013 15:28 thanks. I have known my mistake . Really my mistake is in trapeze ...! | | test 5 boundary case? | Bogatyr | 1900. Машина счастья | 26 июн 2013 14:50 | 11 | I can't get past WA #5. I know it's an n=500 case, but my solution works for n=500 with various k and passenger data as far as I can tell. Any other boundary conditions known to be in test 5? Try data: 3 2 9 2 1 6 3 8 Edited by author 15.10.2012 17:43 I have problems with this test too. My answer is 23 1 3 Is the correct? But your example is ill-formed because you've included data correct for n=4 but you specify n=3 Assuming you meant "4 2" instead of "3 2", yes my solution also produces: 23 1 3 which a visual check shows is the correct answer (based on my understanding! If you have AC and get a different result than "23/1 3", please respond!) Edited by author 16.10.2012 02:47 I'm beginning to wonder if the test 5 answer set includes all possible correct answers, since in many problems there will be quite a lot of legal answers when there are ties for each maximum span. Of course everyone thinks their problem is right and the tests are wrong :). What is it I'm missing, I must be brainwashed not to see it! What's wrong with my thinking? + add the passenger groups into the corresponding spans + greedy approach, take max, then 2nd max, etc., k times + make sure to count a particular passenger group only once if it participates in finding one of the k max spans + total up each max span, and output the spans in ascending order What else is there? Must be a silly mistake or misunderstanding....! Yes, I meant "4 2". I got WA #5 too and my programm correctly work on my example, but I understand that my programm may not work properly in the examples, like the one that I brought. My example is simple, but it shows that in the first selection, each railroad crossing gives us 12 happy people, but the end result depends on the first choice. If first choice is 2nd, than result — 21 / 1 2 Try it: 5 2 9 11 4 2 4 9 2 8 7 9 48 / 2 4 is wrong answer. 52 / 1 3 is correct. @samplex: Thank you! This shows my "choose the first max" greedy approach is wrong. I suspected this was the problem but didn't work hard enough to come up with a counter-example. So my code matches my solution approach, but my solution approach was wrong. Back to the drawing board... always be skeptical of the greedy approach! I am getting correct answer for all the test cases listed here but still I have WA5, any idea why? If you have WA 5 you may try this test: 4 2 6 9 1 2 20 10 ans: 46 1 3 > My example is simple, but it shows that in the first selection, each railroad crossing > gives us 12 happy people, but the end result depends on the first choice. If first > choice is 2nd, than result — 21 / 1 2 Yes I missed this point, thanks again. | | Expression for this problem | Phan Hoài Nam - Đại học Ngoại ngữ Tin Học TP.HCM | 1120. Сумма последовательных чисел | 25 июн 2013 23:57 | 4 | P 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? | | If you have WA4 - see this test | Leonid (SLenik) Andrievskiy | 1796. Парк аттракционов | 25 июн 2013 23:34 | 4 | 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. | | Wrong answer!!! | Bibhubrata Narendra | 1225. Флаги | 25 июн 2013 20:25 | 6 | 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 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 | | help on pascal! | [TDUweAI] daminus | 1001. Обратный корень | 25 июн 2013 19:38 | 1 | use operator SEEKEOF while seekeof do begin read(x); ..... ..... end; | | test 3 wrong. WHY? | bahasdu | 1837. Число Исенбаева | 25 июн 2013 19:22 | 4 | 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 | | WA #17 | Pastafarianist | 1837. Число Исенбаева | 25 июн 2013 19:19 | 5 | WA #17 Pastafarianist 11 ноя 2011 03:26 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!! | | error in 6 test | daemon | 1654. Шифровка | 25 июн 2013 18:50 | 2 | just change char mas_n[200000]={0}; into char mas_n[200005]={0}; )) Edited by author 26.07.2012 18:28 | | I don't understand the problem‘s meaning,just ac it by guessing ! | kaa..........ai | 1935. Слёзы утопленников | 25 июн 2013 18:06 | 1 | | | Some tests | Vavan | 1398. Слон и пешка | 25 июн 2013 13:40 | 3 | ? 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 | | WA 11. Give me some tests, please! | Marshal | 1450. Российские газопроводы | 25 июн 2013 13:31 | 4 | 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. | | Ford - Bellman | Ivan | 1450. Российские газопроводы | 25 июн 2013 13:29 | 1 | My solution is very simple. All weight of edges are inverted((a)->(-a)). Ford-Bellman! | | What's wrong in this? (C++) | pbiiii | 1068. Сумма | 25 июн 2013 09:27 | 4 | #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; | | what is the problem in my code?? | Md.Forhad Hossain | 1079. Максимум | 25 июн 2013 07:46 | 3 | #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 ... | | chorti amocanaa | Avtandil Goqadze | 1156. Два тура | 25 июн 2013 03:14 | 2 | | | Working time - 0.14 | And_rey | 1044. Счастливые билеты. Easy! | 24 июн 2013 20:09 | 8 | 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! :-) 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} | | What is the easiest way to solve this problem?(I have already got AC) | Ярославцев Григорий | 1066. Гирлянда | 24 июн 2013 14:19 | 9 | 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. |
|
|