Common Boardif i use exit(0) or analogs in Python 3.3 programs, it gets runtime error, why does it happens, and how can I avoid this problem? Using exit([arg]) you're raising SystemExit exception. If you don't want that (which usually is the case), use import os os._exit(1) instead (actually, this is receipt for Python 2.x, maybe it is a bit different in 3.x) What should I do if the hull consist of one or two points? For example, test 1 1 1 Obviously, answer is 1 1 But these "three" points lie on one line. this sample code works #include <stdio.h> int main(){ long long a,b; scanf("%lli%lli",&a,&b); printf("%li",(long)(a+b)); } and this do not #include <stdio.h> int main(){ long long a,b; scanf("%lli%lli",&a,&b); printf("%lli",(a+b)); } same with iostream output why? i solve this problem with floyd ,but i got crash I think no. After using Floyd you'll get d[i][j] - array with shortest paths and w[i][j] - array with intermediate vertexes. However it will be impossible to find paths that does not contain duplicate vertexes (Floyd doesn't take care of that). And also Floyd will prefer short paths (e.g. 1,2,1) and it doesn't match to requirement of this problem. So Floyd in it's original form is not applicable here. Possibly some adoption is. But I don't actually know how this adoption should work. It is applicable. You can run it instead of N Dijkstra algorithms. who can explain this statement? It confused me very much.. :/ import java.util.Scanner; public class _1197 { public static void main( String[] args ) { int[][] accessibility = { { 2, 3, 4, 4, 4, 4, 3, 2 } ,{ 3, 4, 6, 6, 6, 6 ,4, 3 } ,{ 4, 6, 8, 8, 8, 8, 6, 4 } ,{ 4, 6, 8, 8, 8, 8, 6, 4 } ,{ 4, 6, 8, 8, 8, 8, 6, 4 } ,{ 4, 6, 8, 8, 8, 8, 6, 4 } ,{ 3, 4, 6, 6, 6, 6, 4, 3 } ,{ 2, 3, 4, 4, 4, 4, 3, 2 } } ; Scanner in = new Scanner( System.in ); int N = in.nextInt(); for( int i=0 ; i<N ; i++ ) { String p = in.next(); System.out.println( accessibility[p.charAt(0)-'a'][p.charAt(1)-'1'] ); } } } Stop posting your solutions, or you will be banned! I don't see that in the FAQ, is posting solutions disallowed? Edited by author 06.10.2012 19:25 import java.util.*; public class LonesomeKnight { public static void main(String[] args) { Scanner key=new Scanner(System.in); int a=key.nextInt(); String[] grid=new String[a]; for(int i=0;i<a;i++) { grid[i]=key.next(); } for(int i=0;i<a;i++) { if(grid[i].equals("a1") || grid[i].equals("h1") || grid[i].equals("a8") || grid[i].equals ("h8")) { System.out.println(2); } if(grid[i].equals("a2") || grid[i].equals("b1") || grid[i].equals("g1") || grid[i].equals ("h2") || grid[i].equals("a7") || grid[i].equals("b8") || grid[i].equals("h7") || grid [i].equals("g8") ) { System.out.println(3); } if(grid[i].equals("a3") || grid[i].equals("a4") || grid[i].equals("a5") || grid[i].equals ("a6") || grid[i].equals("b2") || grid[i].equals("b7") || grid[i].equals("c1") || grid [i].equals("c8") || grid[i].equals("d1") || grid[i].equals("d8") || grid[i].equals("e1") || grid[i].equals("e8") || grid[i].equals("f1") || grid[i].equals("f8") || grid[i].equals("g2") || grid[i].equals("g7") || grid[i].equals("h1") || grid[i].equals("h8")) { System.out.println(4); } if(grid[i].equals("b3") || grid[i].equals("b4") || grid[i].equals("b5") || grid[i].equals ("b6") || grid[i].equals("c2") || grid[i].equals("c7") || grid[i].equals("d2") || grid [i].equals("d7") || grid[i].equals("e2") || grid[i].equals("e7") || grid[i].equals("f2") || grid[i].equals("f7") || grid[i].equals("g3") || grid[i].equals("g4") || grid[i].equals("g5") || grid[i].equals("g6")) { System.out.println(6); } if(grid[i].equals("c3") || grid[i].equals("c4") || grid[i].equals("c5") || grid[i].equals ("c6") || grid[i].equals("d3") || grid[i].equals("d4") || grid[i].equals("d5") || grid [i].equals("d6") || grid[i].equals("e3") || grid[i].equals("e4") || grid[i].equals("e5") || grid[i].equals("e6") || grid[i].equals("f3") || grid[i].equals("f4") || grid[i].equals("f5") || grid[i].equals("f6")) { System.out.println(8); } } } } Well, it's crazy one =) Let's solve this problem just like classical prefix-function solution, but let's get prefix-func from Z-function instead of using KMP. Here is a part of my code. z[0]=0; l=r=m=0; for(int i=1;i<n;i++) { if(i<r) z[i]=min(z[i-l],r-i+1); else z[i]=0; while(i+z[i]<n && t[i+z[i]]==t[z[i]])z[i]++; if(i+z[i]-1>r) l=i,r=i+z[i]-1; } fill(p,p+n,0); for(int i=0;i<n;i++) for(int j=0;j<z[i] && !p[i-j];j++) p[i-j]=z[i]-j; Sunnat C 0.015 316 КБ I don't know KMP but I know HASH... and i have accepted... try this test: (())() ans: 2 import java.util.*; public class ReverseRoot { static int[] a=new int[1]; static int i=-1; static int[] b; public static void main(String[] args) { Scanner key=new Scanner(System.in); while(key.hasNext()) { i++; if(i>a.length-1) resize(a.length+1); a[i]=key.nextInt(); } for(int s=a.length-1;s>=0;s--) System.out.println(Math.sqrt(a[s])); } public static void resize(int size) { b=new int[size]; for(int s=0;s<a.length;s++) b[s]=a[s]; a=b; } } why? I have passed through it by changing the place where I considered that a particular stripe has been already rotated. I have no idea why it was wrong though. I got WA 27, and I found that my program could not pass the following test: 7 2 6 4 5 3 The correct answer should be 1 -2 or 2 -1, but my incorrect program output 0. I fixed it and got AC. Можно ли увеличить TL для решений которые сдаются на python? Некоторые задачи невозможно сдать при текущих ограничениях TL используя python. Edited by author 19.02.2014 20:50 Edited by author 19.02.2014 20:51 Nobody said that it is possible to solve any problem using any language. Quote from FAQ: "Due to some peculiarities of the Java programming language, Java solutions often work slower and use more memory than solutions written in other programming languages regardless of problem difficulty. Nevertheless, it is guaranteed that almost all Timus Online Judge problems may be solved in Java as well as in other programming languages. Here is the list of the problems which are not guaranteed to be solvable in Java: 1220, 1275, 1306." So, Python, C#, Java and some other languages has similar problems. I think that Python solutions often work slower than Java solutions and use more memory than Java solutions. What do you think? Judge, what about this? input : 3 answer : 1110001011 Edited by author 21.02.2014 00:33 what can be in test 2///// I guess it is an anti-hash string < https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence> My additive hash with N=10 uint64_t still works, while N=5 does not: F(i,N) r[i] += ((a<<40) ^ (b<<20) ^ c) * s[i] % q[i] a,b,c are letters; s[i] and q[i] are primes; F(i,n) is for(int i = 0; i < (n); ++i) Have somebody any things about test N 26? Thank you! I have founf a mistake. AC now. I had WA 26 too. Stuped mistake. =) Was: ( v + f + i*p + k*q )%2==0 && ( -v + f + i*p - k*q )%2==0 && ( u + s - i*q - k*p )%2==0 && ( -u + s - i*q + k*p )%2==0 This get AC: ( v + f + i*(p/g) + k*(q/g) )%2==0 && ( -v + f + i*(p/g) - k*(q/g) )%2==0 && ( u + s - i*(q/g) - k*(p/g) )%2==0 && ( -u + s - i*(q/g) + k*(p/g) )%2==0 i guess || instead of && ? Edited by author 18.02.2014 14:04 First of all, yes, the two players can be in the same cell, even at the beginning of the game. That only means that the first player that arrived there will take its value. Test: 5 1 2 3 4 5 1 1 Answer: 15 0 Test: 5 1 2 3 4 5 5 5 Answer: 15 0 Secondly, both players play optimally, so it is not a good idea to try and solve this problem using greedy methods. Furthermore, it is not even necessary to try and iterate each move. It suffices to find a technique that applies for each game and then it all reduces to computing a simple sum:) Good luck! Why I have Runtime error? I use C#. Code is here. using System; using System.Globalization; class EntryPoint { static void Main() { CultureInfo ci = new CultureInfo("en-US"); double p = Convert.ToDouble(Console.ReadLine(),ci); double q = Convert.ToDouble(Console.ReadLine(),ci); int x = 1; while (true) { if ((int)(q * x / 100) - (int)(p * x / 100) > 0) break; x++; } Console.WriteLine(x); } } Quote from problem description: "These numbers are separated by some spaces or "end of line" symbols" |
|