Общий форумIf your code on pascal, don't use "CASE x oF" it's got CE(Compilation error) Consider for instance the first drawing : in my perception, the staircase has 4 steps because there are 4 horizontal levels. So the first step (ie the lower one) is made up with 4 blocks, the second with 3 blocks, the third one with 2 blocks and the fourth with 2 blocks again ; so the sizes of the steps are not in _strictly_ descending order (the sizes are 4 3 2 2). So what does "size of a step" really mean? the number of blocks between two consecutive horizontal levels ? the height from the ground of a given level? the height between two consécutive levels? "descending order" : how do you count the steps? from right to left? from top to bottom? The task is no more than finding the number of partitions of n into at least two distinct parts. Edited by author 29.06.2013 04:27 here is my code. In my computer he got AC on test#1. But in timus that got WA#1 var a:array[0..500010] of longint; procedure sort(l,r:longint); var i,j,p,x:longint; begin randomize; i:=l; j:=r; x:=a[random(r-l+1)+l]; repeat while x>a[i] do inc(i); while x<a[j] do dec(j); if i<=j then begin p:=a[i];a[i]:=a[j];a[j]:=p; inc(i); dec(j); end; until i>j; if i<r then sort(i,r); if l<j then sort(l,j); end; var p,j,k,n,i,temp,have:longint; begin readln(n); for i:=1 to n do readln(a[i]); sort(1,n); temp:=-1; for i:=1 to n do begin if a[i]=temp then begin inc(have); continue; end; if n mod 2=1 then k:=1 else k:=0; if have>=n div 2+k then begin writeln(temp); halt; end; have:=1;temp:=a[i]; end; if n=1 then writeln(temp); end. Transposing means swapping two tombstones NOT reversing the order of all the stones between selected two. 1...n print(i) (n+1)...n+m print(i*n) I have WA on test 8. Can someone help. I tried every given test in the site but I can't find any mistakes. This is my code: // #include<iostream> #include<cmath> #include<algorithm> #include<iomanip> using namespace std; bool b[2005][2005]; long double a[2005][2005]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long double diag=sqrt(2)*100; int n,m,k,k1,r; cin>>n>>m>>r; for(int i=0;i<r;i++) { cin>>k>>k1; b[k][k1]=1; } n++; m++; for(int i=2;i<=n;i++)a[1][i]=a[1][i-1]+100; for(int i=2;i<=n;i++) { for(int j=1;j<=m;j++) { a[i][j]=a[i-1][j]+100; if(j!=1 && a[i][j]>a[i][j-1]+100)a[i][j]=a[i][j-1]+100; if(b[i-1][j-1] && a[i][j]>a[i-1][j-1]+diag+0.001)a[i][j]=a[i-1][j-1]+diag; } } cout<<fixed<<setprecision(0)<<a[n][m]<<"\n"; return 0; } If you got WA #3, check case n=1 ;) input: HELLO. I AM ANJELA! AND YOU? I AM BLONDE. output: Hello. I am anjela! And you? I am blonde. Give me test . please! 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 ...! 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. 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? 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. |
|