Общий форумI wrote two idental programs in C++ and Pascal. First works for 0.565 sec, another for 0.062. I means, that tests for C++ and Pascal are different?! But why time is different??? If you used cin and cout ... I used cin/cout and still AC 0.046 #include <cstdlib> #include <iostream> using namespace std; int main() { int k=0,n,i,s=1,j; char c[50]; cin>>n;
if(n>=1 && n<=10) { cin.get(c,20); for(i=0;i<20;i++){ if(c[i]=='!') k=k+1; }
if(k>=1 && k<=20){
if(n%k!=0) { for(j=0;j<=(n-1)/k;j++) s=s*(n-j*k); cout<<s; } else if(n%k==0) { for(int j=0;j<=n/k;j++) s=s*(n-j*k); cout<<s; } }}
return 0; } what is test#10.i can;t understand Got AC with a 34-lines Java program. 5 lines for the RE: "('[^']*'|#\\d+)|"+ // 1: str "(\\d+(?:\\.\\d+)?)|"+ // 2: num "(\\{[^}]*\\}|//[^\\r\\n]*)|"+ // 3: comment "([a-z_][a-z_0-9]*)|"+ // 4: ID "(.)" // 5: anything else 5 lines of kw: {"and", "array", "begin", "case", "class", "const", "div", "do", "else", "end", "for", "function", "if", "implementation", "interface", "mod", "not", "of", "or", "procedure", "program", "record", "repeat", "shl", "shr", "string", "then", "to", "type", "unit", "until", "uses", "var", "while", "with"}; and 10 copy/pasted lines of the main loop: while in.findWithinHorizon is not null, check which group matched and print accordingly Pitfalls: The list of the keywords in the statement is not sorted and thus binarySearch in it fails. The statement about "//..." comments is simply wrong: line feed is \n, in reality test 6 uses carriage-return (\r). Edited by author 05.04.2010 05:23 Edited by author 05.04.2010 05:24 Edited by author 05.04.2010 05:24 Edited by author 05.04.2010 05:24 I think my solution is right, I tried it on many test, but the system gives WA#1. Could you give me this test? System gives WA#1 me too. ____ Sorry for my English. Edited by author 29.01.2010 23:40 WA#2 :( but I think my solution is right i'm think yoursolution not right or not enough case. See you later. good look Simply use angles comparison method and You'll get AC! How? What's that algorithm For all brute force solvers: it's enough to provide 1E-4 precision to AC :)) Very true!!! > Posted by SkorKNURE October 12, 2008 02:36 > > For all brute force solvers: it's enough to provide 1E-4 > precision to AC :)) Edited by author 29.03.2010 07:19 Edited by author 29.03.2010 07:19 Edited by author 29.03.2010 01:54 TT AC T 6 2 1 3 2 1 4 2 5 2 2 6 7 2 Edited by author 28.03.2010 19:19 import java.util.*; import java.io.*; import java.lang.String; public class P1014{ public static void main(String[] args){ Scanner in=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); long m=0; int i=0; String num; try{ int n=in.nextInt(); if(n==1) out.println("1"); else if(n<10) out.println("1"+n); else { for(i=9;i>1;i--) { if(n%i==0) { n=n/i; m=m*10+i; i++; }} if(n!=1) out.print("-1"); else{ String s=Long.toString(m); for(i=s.length()-1;i>=0;i--) out.print(s.charAt(i)); }} }catch(Exception e){ out.println(e); } out.flush(); }} For C++ code and other queqtions write imran_yusubov@yahoo.com Edited by author 10.09.2008 06:38 I think Mister Bean,too . Timus Online Judge is playground for intelligence of student information technology. Learn algorithm to solve is main. thank you Mister Bean, you help me very much. Edited by author 28.03.2010 18:31 I've got WA on test 1. =( var flag, i, ans:integer; s:string; begin assign(input, 'C:\a.txt');reset(input); ans := 0; flag := 0; while not eof(input) do begin readln(s); i:=1; while i<=length(s) do begin while s[i] in [' ', ',', ';', ':', '-'] do i:=i+1; if (flag = 0)and((ord(s[i])<ord('A')) or (ord(s[i])>ord('Z'))) then ans:= ans + 1; flag:=1; if ((ord(s[i-1])>=ord('A')) and (ord(s[i-1])<=ord('Z'))) and ((ord(s[i])>=ord('A')) and (ord(s[i])<=ord('Z'))) then ans:= ans+1; if s[i] in ['.', '?', '!'] then flag := 0; i:=i + 1; end; end; writeln(ans); end. Edited by author 28.03.2010 00:56 do not read from "C:/a.txt"!? let conseder the example: the first- 27+8=35, the second- 5+5+14+13=37, 37-35=2 but you write 3. You are not right. First number 5 is amount of stones, and in sample you have only 5 stones, not 6. Edited by author 27.03.2010 18:37 In VS 2008 work both "%I64d" and "%lld". If you would like to use long long here use cin/cout! True... And kind of crazy... at first sight! =) #include <stdio.h> int main() { long i=3; long long a; scanf("%I64d",&a); while (a%i!=0) i++; printf("%ld",i-1); return 0; } bobchennan, DO NOT post your solutions! melkiy says right. but post "good idea" to solve problem. Algorithm to solve is important Edited by author 26.03.2010 18:41 Edited by author 26.03.2010 18:41 How you think, from what attempt it is possible to get AC? cout<<rand()%10; Seems that probability of AC is (1/10) ^ k where k is number of tests. So probability to get just one AC after N attempts is 1 - ( 1 - (1/10) ^ k ) ^ N ^_^ Good luck. ;) P.S.: if k = 10, you have to make 6931471806 attempts for making this probability greater then 0.5 xD P.P.S: ...if i made no mistakes. ;) yes, it will be 1 just in case, for 0 it will be 10 why WA in test 7 ???? please make your array bigger! |
|