Don't use sqrt. Use a dictionary instead of a big if-else ladder. Cracked it after 7 years :) Has anybody AC with Python 3.3? I tried, but always get TLE. I rewrite code to C and get AC with 0.156s. It's possible, hint : use a dictionary instead of a big if-else ladder :) Hi. Can you give some samples to help fixing WA on test #7? Try using constant with higher precision. Edit: I know that author may not need this hint anymore, but I replied in case anyone was in the same trouble. Edited by author 18.07.2021 21:38 Edited by author 18.07.2021 21:38 InputStream is = System.in; byte[]b = new byte[1000_001]; int L = is.read(b)-1; while(b[L]<48 || b[L]>57) L--; int i=0; double D = Math.sqrt(0.5); double x=0; double y=0; // 1 2 3 4 5 6 7 8 9 double[] shftx = new double[]{0,-D, 0, D,-1, 0, 1,-D, 0, D}; double[] shfty = new double[]{0,-D,-1,-D, 0, 0, 0, D, 1, D}; while(i<=L && b[i]!=48 && b[i]!=0){ x+=shftx[b[i]-48]; y+=shfty[b[i]-48]; i++; } System.out.println(String.format("%.10f %.10f", x, y)); What is "Idleness limit exceeded"? Don't update current x and y on each iteration. Save the total number of jumps of one direction. Ex: int toSouthWest = 0; for (int i = 0; i < a.legth; i++) { if (a[i] == '1'){ toSouthWest++; } if (a[i] == '9'){ toSouthWest--; } if (a[i] == '8'){ toSouth++ } ... } then you sum diractions vectors and get the answer double y = toSouth + (toSouthWest + toSouthEast)*(1/2)^(1/2); double x = ... good luck!! Very simple problem, only what you need is to read the directions of buttons more CAREFULLY. Their keyboard is like 0 789 456 123 Edited by author 11.07.2014 06:36 1=(y-1*sqrt(2)/2) (x-1*sqrt(2)/2) 7=(y+1*sqrt(2)/2) (x-1*sqrt(2)/2) 9=(y+1*sqrt(2)/2) (x+1*sqrt(2)/2) 3=(y-1*sqrt(2)/2) (x+1*sqrt(2)/2) 2=(y-1) 8=(y+1) 4=(x-1) 6=(x+1) that's all Edited by author 09.02.2006 18:40 Edited by author 11.07.2014 06:30 Thanks, It was realy easy, but I read the directions of buttons not exactly and that's why got WA :-) C# using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _1413 { class Program { static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; string[] temp = Console.ReadLine().Split('0'); string l = temp[0]; decimal k = 0,x=0,y=0; decimal sqrt =Convert.ToDecimal( Math.Sqrt(2))/2; for (int i = 1; i < 10; i++) { k = l.Split(new string[]{ i.ToString() }, 1000000000, StringSplitOptions.None).Length - 1; if (i == 1){ x -= k * sqrt;y-=k*sqrt;} if (i == 2) y -= k; if (i == 3) { x += k * sqrt; y -= k * sqrt; } if (i == 4) x -= k; if (i == 6) x += k; if (i == 7) { x -= k * sqrt; y += k * sqrt; } if (i == 8) y += k; if (i == 9) { x += k * sqrt; y += k * sqrt; } } Console.WriteLine("{0:F10} {1:F10}", x, y); } } } Please remember, that: 1. I recommend you to use the most accurate floating-point type you have (C# = decimal, Pascal = extended etc.) 2. use constant: s = 0.70710678118654752440084436210485 3. Some tests have no '0' symbol. 4. (For notebook owners) Remember, that the author of the statement said to use computer digit keys (not telephone digit keys!). So the numbers are situated in such order: 7 8 9 4 5 6 1 2 3 Thank you for keyboard!! P.S. I used to write sqrt(2)/2 and got AC. (use pascal) Hi. Can you give some samples to help fixing WA on test #3? I think you have problem with diagonal movement because I also have the same problem, but now I have AC Good luck use sqrt(2)/2 Hayk Blrtsyan Great thanks! But I don't undestend why? Sorry, for bad english Change x:10,' ',y:10 to x:0:10,' ',y:0:10 find --> nd first --> rst final --> nal finite --> nite Please correct it. Use this Scanner in = new Scanner(new BufferedInputStream(System.in)); It's enought =) And what is faster? Your method or using StreamTokenizer? Don't use Scanner - it's very slow. Instead of it you can use: BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); , which throws IOException, but you can handle it. This is my program: program V1413; const b=sqrt(2)/2; var x,y:real; st:ansistring; i:longint; begin x:=0;y:=0; readln(st); for i:=1 to length(st) do begin case st[i] of '8':y:=y+1; '2':y:=y-1; '4':x:=x-1; '6':x:=x+1; '7':begin x:=x-b; y:=y+b; end; '9':begin x:=x+b; y:=y+b; end; '1':begin x:=x-b; y:=y-b; end; '3':begin x:=x+b; y:=y-b; end; '0':begin writeln(x:0:10,' ',y:0:10); halt; end; end; end; end. I don't know why wa2 ? Sorry for my bad English.Thank you! Edited by author 11.10.2008 19:24 [code deleted] Edited by author 07.05.2007 20:25 Edited by author 08.05.2007 19:10 Edited by author 10.05.2007 19:47 test : 134523 there is no '0', and your while() continue it's work. use: while( scanf("%c",&c)!=EOF && c!='0' ) (sory for my bad english) Thank you very much for help!!!!!Now I have AC!!! Edited by author 08.05.2007 19:10 Thank you very much for help!!!!!Now I have AC!!! here is my code [code deleted] need someone'help Edited by moderator 13.02.2007 20:50 When i used ---sqrt(2)/2--- whith 10 numbers i got WA3 With 12 -Wa7 And with 16- i finally got AC d=0.7071067811865475;-16 numbers Hello! I did everything and I don't know why I have TLE on test 6! Here is my code: {deleted} Edited by author 09.06.2006 16:13 dont give loop condition within the loop as for(i=0;i<strlen(str);i++) instead int n=strlen(str); for(i=0;i<n;i++) also dont call sqrt(2) each time you evaluate x and y. e.g. Inside the loop use statement such as case 1: x-=iroot; y-=iroot; break; where iroot has been previously assigned(before the loop) sqrt(2.0)/2.0 and not case 1: x-=sqrt(2.0)/2; y-=sqrt(2.0)/2; break; Also for those who're getting compilation error in c++: call as sqrt(2.0) and not sqrt(2). One more Important thing for c++ coders. //This gives you TLE#6 string cha; cin>>cha; int n=cha.size();* int ch; for(int i=0;i<n && (ch=int(cha[i]-'0'));i++) //Whereas this gives AC char cha[1000000]; scanf("%s",cha); char f; int ch; int n=strlen(cha); for(int i=0;i<n && (ch=int(cha[i]-'0'));i++) ;) ;) Edited by author 04.12.2007 13:04 I do evrything, but I get Crash (access violation)on test6 Here is my code in C++ Pleaz HEEEEELP me !!! #include <stdio.h> #include <string.h> #include <math.h> #define d sqrt((double)2)/2 double dx[] = { 0,-d,0,d,-1,0,1,-d,0,d }; double dy[] = { 0,-d,-1,-d,0,0,0,d,1,d }; double x, y; int n, i; char s[250005]; int main() { scanf("%s", &s); n = strlen(s); for(i = 0; i < n; i++) { if(s[i] == '0' || s[i] == 13) break; x += dx[s[i]-48]; y += dy[s[i]-48]; } printf("%.11lf %.11lf\n", x, y); return 0; } Edited by author 31.08.2007 16:37 "Not more than 1000000 digits from 0 to 9." Now count number of zeros here. It is 1kk (1 million). And your array is only 250005. Where have you found this number? It's defenetely not enough. |
|