Common Board| Show all threads Hide all threads Show all messages Hide all messages | | How should I output? | Dmitry 'Diman_YES' Kovalioff | 1219. Symbolic Sequence | 3 Feb 2011 22:43 | 10 | As you can see the task is to output the sequence consists of 1000000 symbols. I output exactly 1000000 symbols one by one (...Write (sym)...Write(sym)...Write(sym)...), buf after 0.04 seconds I receive "Output Limit". What does it mean and how should I output the sequence? Please, help me! That simply means that you do NOT output 1 million chars! I have the same problem, and I can't solve it. But if I decrease the number of outputs then I get WA. I used putchar(buffer[j]); instead of printf("%s",buffer) and I got accepted. I really don't know why. > As you can see the task is to output the sequence consists of 1000000 > symbols. I output exactly 1000000 symbols one by one (...Write > (sym)...Write(sym)...Write(sym)...), buf after 0.04 seconds I > receive "Output Limit". What does it mean and how should I output the > sequence? > Please, help me! var i:longint; begin randomize; for i:=1 to 1000000 do write(chr(ord('a')+random(26))); end. You are GENIUS!!! The god of programming :)) I think your solution is really perfect! > You are GENIUS!!! The god of programming :)) I think your solution is > really perfect! I made: var i:longint; begin randomize; for i:=1 to 1000000 do write(chr(97+random(26))); end. use 97 instead of ord('a')!!! I still believe u r geinus Aidin To make this program shorter one can substistute "1000000" on 1e6. P.S. To Smilodon_am: You can't use 1e6 with the FOR cycle because it needs only INTEGER expressions. Edited by author 03.01.2009 01:40 Edited by author 03.01.2009 01:41 I also solved like this but the way I got to this solution was kind of intuitive, so I am not still sure why this solution gets AC, I can't prove it. Do you have any proof why it does so? | | problem description has a mistake? | Takamoto | 1005. Stone Pile | 3 Feb 2011 22:27 | 2 | Hi, Maybe I misunderstood the problem. With the given numbers, you could actually make two piles 27,8 in one and 13,14,5,5 in the other, and the difference would be just 2. Where did I misunderstand? sorry, my mistake! the first number is actually the number of stones! | | Whwre am I wrong? | Freezing Sun | 1005. Stone Pile | 3 Feb 2011 22:24 | 6 | My code sorts all the weights in descending order and then arranges them into two piles using algorythm: 1. Start with the heaviest stone; 2. If weight(pile1)<Weight(pile2) add current stone to pile1; Else add current stone to pile2; 3. If there are more stones current stone = next stone; Goto 1; Consider the following example: 5 10 10 8 7 5 Your algo will give answer 4, while the correct one is 0. Use brute-force to solve the problem. why? I think the algorithm described by Freezing Sun would (and should) return the correct answer here: 1 I think that the correct algorithm is using DP, like this: If you figure out a way to find the sum of each possible subsets from {w0...wn}, and you know that w0+w1+..+wn = N... for some N, then the problem is reduced to find the set that gets closer to N/2. IOW: Suppose you have a set and the sum of its elements is equal to N/2.. Then the sum of the other set is also N/2, so the difference is 0... And the difference will always be minimal near N/2.. so if you can't get N/2, try finding the one closer to it. the way I did it is: ... S := {w0,w1,...,wn} B := array(Bool, #(S), false) B[0] := true // you can always pic the empty set for i in S: for j in range(0, N): if B[j] = true: B[j+S[i]] := true ... This gives you all possible sums of the possible subsets of S like this: B[i] = true if there exist a set S' of S such that (sum(S') = i) holds. Hope I wasn't very bad at my english.. :S See ya gaston770@gmail.com gaston770 right , DP. This problem is same tpye as knap of problem. W=Sum of w[i],i=1..n, N=W/2; find N=w[j1]+w[j2]+...+w[jk]:j1,j2,..jk in set[1..n]. Good luck. Edited by author 07.04.2010 08:51 The size of input is too small, so you can try all the dispositions of N/2 stones. c(10,20) is less than 200000 ;) | | What does mean the expected number of seconds a kid will have to wait? I don't understand what does word expeсted means. | Oleg Topalov | 1817. Merry-go-round | 3 Feb 2011 18:38 | 2 | Edited by author 30.01.2011 13:57 Edited by author 30.01.2011 13:57 Edited by author 30.01.2011 13:58 Edited by author 30.01.2011 14:41 | | Test 28 | Timur Sitdikov (MSU TB) | 1075. Thread in a Space | 3 Feb 2011 17:17 | 1 | Test 28 Timur Sitdikov (MSU TB) 3 Feb 2011 17:17 I had WA28. After two hints I get AC. 1) check if A=B 2) check if sphere has intersections with segment using long long integers, not doubles Edited by author 06.02.2011 08:52 | | AC 0.031s 132K using stl | waterlink | 1049. Brave Balloonists | 3 Feb 2011 14:31 | 1 | [hidden code:)] Edited by author 03.02.2011 14:33 | | I don't know, why it crashes | mari | 1000. A+B Problem | 2 Feb 2011 23:47 | 2 | Here is my solution. It works fine in eclipse, but it crashes in here. Could you tell me what is wrong? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Sum {
public static void main(String[] args) {
int x,y; long z;
try { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); x = Integer.parseInt(bf.readLine()); y = Integer.parseInt(bf.readLine()); bf.close(); z = x+y; System.out.println(z); } catch (IOException e) { System.out.println(e); }
} } Test: 1 2 (in one line) Verdict: Crash Besides BufferedReader use java.util.StringTokenizer (better) or java.io.StreamTokenizer. | | No subject | Elbek&Jamol | 1816. Troubles with Pollard | 2 Feb 2011 13:33 | 1 | | | WA 6 | Panzer | 1723. Sandro's Book | 1 Feb 2011 19:00 | 2 | WA 6 Panzer 11 Dec 2010 23:32 Does anybody knows what is the test 6? I forgot to update my max frequency of character. I fixed that and got AC. | | TLE 11 | pmi003 | 1024. Permutations | 1 Feb 2011 17:35 | 1 | TLE 11 pmi003 1 Feb 2011 17:35 HELP!!! #include <iostream> using namespace std; int main() { int const N=1024; int n, a[N], b[N], P=1; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; b[i]=a[i]; } for(;;) { int s=0; for(int i=0;i<n;i++) if(a[i]==i+1) s++; if(s==n) break; else { P++; for(int j=0;j<n;j++) a[j]=b[a[j]-1]; } } cout<<P<<endl; return 0; } | | WA5 | pmi003 | 1584. Pharaohs’ Secrets | 1 Feb 2011 16:58 | 1 | WA5 pmi003 1 Feb 2011 16:58 | | need clarifications on the posted solution | Karthik Duraisamy | 1014. Product of Digits | 1 Feb 2011 15:23 | 1 | using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { double i, j,a; double display=0; Console.WriteLine("enter the number:"); double n = double.Parse(Console.ReadLine()); try { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if ((i * j) == n) { a = double.Parse(string.Concat((object)i, (object)j)); if (i == 1) { if (n == 1) display = 1; else display = a; } else { if (a < display) { display = a; } } } } } Console.WriteLine(display); } catch (NotFiniteNumberException) { Console.WriteLine(-1); } } } } Edited by author 01.02.2011 15:27 | | Do you know a faster algorithm? | lql1993 | 1017. Staircases | 1 Feb 2011 15:20 | 3 | I used dp and this is my program: var f:array[0..500,0..500]of extended; i,j,n:longint; function min(a,b:longint):longint; begin if a<b then exit(a); exit(b); end; begin readln(n); fillchar(f,sizeof(f),0); f[0,0]:=1; for i:=1 to n do for j:=1 to i do f[i,j]:=f[i,j-1]+f[i-j,min(j-1,i-j)]; writeln(f[n,n]:0:0); end. But I want to know a faster algorithm, could you please tell me? let us suppose this is a building. T[i][j] is the total number of buildings which uses i bricks, and its ground floor is exactly j. O(n*logn). AC code. #include<iostream> using namespace std; __int64 T[501][35]; __int64 sum; int n; inline __int64 max(__int64 i,__int64 j) { return i>j?i:j; } int main() { int i,j,k; scanf("%d",&n); T[1][1]=1; for(i=2;i<=n;i++) { for(j=1;((j*(j+1))>>1)<=i;j++) { T[i][j]=T[i-j][j]+T[i-j][j-1]; } } for(j=1;((j*(j+1))>>1)<=n;j++) { sum+=T[n][j]; } printf("%I64d\n",sum-1); return 0; } | | why time limit exited ? | Md.Forhad Hossain | 1024. Permutations | 1 Feb 2011 13:59 | 1 | #include<iostream> using namespace std; int main(void) { int ary1[1000],ary2[1000],n=5,input,result=1,m=0; cin>>n; if(n<1&&n>1000) exit(0); for(int i=0;i<n;i++) { cin>>input; ary2[i]=ary1[i]=input; } for(int x=0;x<n;x++) { if(ary1[x]!=(x+1)) break; else m++; } if(m==n) { cout<<result; exit(0); } else m=0; while(1) { for(int j=0;j<n;j++) { ary2[j]=ary1[ary2[j]-1];
} result++; for(int k=0;k<n;k++) { if(ary2[k]!=(k+1)) break; else m++; } if(m==n) { cout<<result; exit(0); } else m=0; } return 0; } | | Is complicated and sophisticated number theory algorithms are involved? | caoyuan9642 | 1814. Continued Fraction | 1 Feb 2011 12:46 | 3 | I thought the algo is to find the loop of continued fraction. But it seems that if the loop is too small, 10^9 would make this algo fail. Give some hint plz. for example: Sqrt(2)=1+1/(2+1/(2+1/(2+1/...... =[1,2,2,2,2,2,2,2,2......] the loop number is 1 so if k=10^9 , it can fail to calculate [1,2],[1,2,2],[1,2,2,2],[1,2,2,2,2]...... Accepted now. No very complicated number theory is needed. All you need is the chapter about continued fraction in any copy of basic number theory. | | Codecraft and Time Limit Exceeded 2011 | phinfinity | | 31 Jan 2011 16:52 | 1 | Hello, The International Institute of Information Technology, Hyderabad, India cordially invites you to be a part of Felicity, the annual cultural and technical festival, to be held from 18th - 20th February, 2011. 1) Codecraft 2011 CodeCraft 2011, the online programming competition is all set to start on 6th February,2011. Codecraft requires eight hours of brainstorming over some of the toughest algorithms challenges from various fields of Computer Science. Where : http://felicity.iiit.ac.in/codecraft/When : 6th February 2011, 2 pm - 10 pm IST(GMT +5:30). 2) Time Limit Exceeded This is an unusual programming event which emphasizes on solving problems under special constraints. The event is based on C/C++ with the scoring depending on factors like code length, deviation from the best available solution, or even the number of semi-colons and whitespaces used. Where : http://felicity.iiit.ac.in/tle/When : 11th February 2011 2pm to 13th February 2011 2pm (48 hours [2 days]) IST (GMT +5:30). You need to REGISTER online to participate in these event. There are prizes in each of the mentioned events, details of which will be put on the site in due time. Kindly visit the respective sites for more details. For queries , mailto : codecraft.11@gmail.com , felicity11.tle@gmail.com. | | Test #14 | aSSault | 1200. Horns and Hoofs | 30 Jan 2011 22:47 | 3 | When my program had WA14, I changed there: if(a - int(a) >= 0.5) to if(a - int(a) >= 0.5 + 1e-7) And I get AC!! Maybe it will help you! Good Luck!!! Edited by author 05.05.2007 16:50 Please, help WA 14. How can I change this? I think there is my mistake: pr_x >= pr_y and pr_y >= pr_x ----------------------------- double a = input.nextDouble(), b = input.nextDouble(); double pr_x = 0, pr_y = 0; int x = 0, y = 0, k = input.nextInt(); boolean yes; while (true) { pr_x = a - 2 * x - 1; pr_y = b - 2 * y - 1; yes = false; if (pr_x > 0 && pr_x >= pr_y && x + y + 1 <= k) { yes = true; x++; } else if (pr_y > 0 && pr_y >= pr_x && x + y + 1 <= k) { yes = true; y++; } if (!yes) { break; } } System.out.printf("%.2f\n%d %d\n", a * x + b * y - x * x - y * y, x, y); } Edited by author 30.01.2011 22:48 | | SMS reachability | UH++ | 1811. Dual-SIM Phone | 30 Jan 2011 17:29 | 2 | Can send SMS from a to b through z, (a -> z -> b), or can only use one direct edge... if possible the cost would be the sum, or the maximum on the path??? No, we can use only direct edge. | | Irreducable fraction | LSBG | 1812. The Island of Bad Luck 2 | 30 Jan 2011 16:38 | 2 | Hello what should I print if the answer is integer, say 1: 1/1 or 1 ? Thank you. After many trials it turned out it should be printed as 1/1. | | I love Liberty City... | Vit Demidenko | 1815. Farm in San Andreas | 30 Jan 2011 14:18 | 1 | |
|
|