Общий форум{No.1030 Titanic.} Const pi=3.1415926535897932384626433832795; Var Char1,NS1,EW1,NS2,EW2:Char; A1,B1,C1,D1,E1,F1,A2,B2,C2,D2,E2,F2:Integer; SqrD,Alpha,L,X1,Y1,Z1,X2,Y2,Z2:Real; Function ReadNum:Integer; Var Str1:String; Code,Num:Integer; Char1:Char; Begin Str1:='##'; Read(Str1[1]); Read(Str1[2]); Read(Char1); If Char1 In ['0'..'9'] Then Str1:=Str1+Char1; Val(Str1,Num,Code); ReadNum:=Num; End; Procedure Cal(Theta1,Theta2:Real;NS,EW:Char;Var X,Y,Z:Real); Begin If NS='N' Then Z:=Sin(Theta1) Else Z:=-Sin(Theta1); X:=Cos(Theta2)*Cos(Theta1); If EW='E' Then Y:=Sin(Theta2)*Cos(Theta1) Else Y:=-Sin(Theta2)*Cos(Theta1); End; Begin ReadLn; ReadLn; ReadLn; A1:=ReadNum; B1:=ReadNum; C1:=ReadNum; Read(Char1); Read(NS1); ReadLn; Read(Char1); Read(Char1); Read(Char1); Read(Char1); D1:=ReadNum; E1:=ReadNum; F1:=ReadNum; Read(Char1); Read(EW1); ReadLn; ReadLn; A2:=ReadNum; B2:=ReadNum; C2:=ReadNum; Read(Char1); Read(NS2); ReadLn; Read(Char1); Read(Char1); Read(Char1); Read(Char1); D2:=ReadNum; E2:=ReadNum; F2:=ReadNum; Read(Char1); Read(EW2); ReadLn; ReadLn; Cal((((C1/60)+B1)/60+A1)/180*pi,(((F1/60) +E1)/60+D1)/180*pi,NS1,EW1,X1,Y1,Z1); Cal((((C2/60)+B2)/60+A2)/180*pi,(((F2/60) +E2)/60+D2)/180*pi,NS2,EW2,X2,Y2,Z2); If (Abs(X1+X2)<1E-7) And (Abs(Y1+Y2)<1E-7) And (Abs(Z1+Z2)<1E-7) Then Alpha:=pi Else Begin SqrD:=Sqr(X1-X2)+Sqr(Y1-Y2)+Sqr(Z1-Z2); Alpha:=Arctan(Sqrt(SqrD)/2/Sqrt(1-SqrD/4))*2; End; L:=Alpha*6875/2; WriteLn('The distance to the iceberg: ',L:0:2,' miles.'); If 100-L>1E-7 Then WriteLn('DANGER!'); End. This possibly mean that you try to access the element of the array with the number that doesn't exist or something like that. Good Luck!!! {No.1030 Titanic.} {$N+} Const pi=3.1415926535897932384626433832795; Var Char1,NS1,EW1,NS2,EW2:Char; A1,B1,C1,D1,E1,F1,A2,B2,C2,D2,E2,F2:Integer; SqrD,Alpha,L,X1,Y1,Z1,X2,Y2,Z2:Double; Function ReadNum:Integer; Var Str1:String; Code,Num:Integer; Char1:Char; Begin Str1:=''; Read(Char1); Str1:=Str1+Char1; Read(Char1); If Char1 In ['0'..'9'] Then Begin Str1:=Str1+Char1; Read(Char1); If Char1 In ['0'..'9'] Then Str1:=Str1+Char1; End; Val(Str1,Num,Code); ReadNum:=Num; End; Procedure Cal(Theta1,Theta2:Double;NS,EW:Char;Var X,Y,Z:Double); Begin If NS='N' Then Z:=Sin(Theta1) Else Z:=-Sin(Theta1); X:=Cos(Theta2)*Cos(Theta1); If EW='E' Then Y:=Sin(Theta2)*Cos(Theta1) Else Y:=-Sin(Theta2)*Cos(Theta1); End; Begin ReadLn; ReadLn; ReadLn; A1:=ReadNum; B1:=ReadNum; C1:=ReadNum; Read(Char1); Read(NS1); ReadLn; Read(Char1); Read(Char1); Read(Char1); Read(Char1); D1:=ReadNum; E1:=ReadNum; F1:=ReadNum; Read(Char1); Read(EW1); ReadLn; ReadLn; A2:=ReadNum; B2:=ReadNum; C2:=ReadNum; Read(Char1); Read(NS2); ReadLn; Read(Char1); Read(Char1); Read(Char1); Read(Char1); D2:=ReadNum; E2:=ReadNum; F2:=ReadNum; Read(Char1); Read(EW2); ReadLn; ReadLn; Cal((((C1/60)+B1)/60+A1)/180*pi,(((F1/60) +E1)/60+D1)/180*pi,NS1,EW1,X1,Y1,Z1); Cal((((C2/60)+B2)/60+A2)/180*pi,(((F2/60) +E2)/60+D2)/180*pi,NS2,EW2,X2,Y2,Z2); If (Abs(X1+X2)<1E-10) And (Abs(Y1+Y2)<1E-10) And (Abs(Z1+Z2)<1E- 10) Then Alpha:=pi Else Begin SqrD:=Sqr(X1-X2)+Sqr(Y1-Y2)+Sqr(Z1-Z2); Alpha:=Arctan(Sqrt(SqrD)/2/Sqrt(1-SqrD/4))*2; End; L:=Alpha*6875/2; WriteLn('The distance to the iceberg: ',L:0:2,' miles.'); If 100-L>0 Then WriteLn('DANGER!'); End. {No.1030 Titanic.} {$N+} Const pi=3.1415926535897932384626433832795; Var Char1,NS1,EW1,NS2,EW2:Char; A1,B1,C1,D1,E1,F1,A2,B2,C2,D2,E2,F2:Integer; SqrD,Alpha,L,X1,Y1,Z1,X2,Y2,Z2:Double; Function ReadNum:Integer; Var Str1:String; Code,Num:Integer; Char1:Char; Begin Str1:=''; Read(Char1); Str1:=Str1+Char1; Read(Char1); If Char1 In ['0'..'9'] Then Begin Str1:=Str1+Char1; Read(Char1); If Char1 In ['0'..'9'] Then Str1:=Str1+Char1; End; Val(Str1,Num,Code); ReadNum:=Num; End; Procedure Cal(Theta1,Theta2:Double;NS,EW:Char;Var X,Y,Z:Double); Begin If NS='N' Then Z:=Sin(Theta1) Else Z:=-Sin(Theta1); X:=Cos(Theta2)*Cos(Theta1); If EW='E' Then Y:=Sin(Theta2)*Cos(Theta1) Else Y:=-Sin(Theta2)*Cos(Theta1); End; Begin ReadLn; ReadLn; ReadLn; A1:=ReadNum; B1:=ReadNum; C1:=ReadNum; Read(Char1); Read(NS1); ReadLn; Read(Char1); Read(Char1); Read(Char1); Read(Char1); D1:=ReadNum; E1:=ReadNum; F1:=ReadNum; Read(Char1); Read(EW1); ReadLn; ReadLn; A2:=ReadNum; B2:=ReadNum; C2:=ReadNum; Read(Char1); Read(NS2); ReadLn; Read(Char1); Read(Char1); Read(Char1); Read(Char1); D2:=ReadNum; E2:=ReadNum; F2:=ReadNum; Read(Char1); Read(EW2); ReadLn; ReadLn; Cal((((C1/60)+B1)/60+A1)/180*pi,(((F1/60) +E1)/60+D1)/180*pi,NS1,EW1,X1,Y1,Z1); Cal((((C2/60)+B2)/60+A2)/180*pi,(((F2/60) +E2)/60+D2)/180*pi,NS2,EW2,X2,Y2,Z2); If (Abs(X1+X2)<1E-10) And (Abs(Y1+Y2)<1E-10) And (Abs(Z1+Z2)<1E- 10) Then Alpha:=pi Else Begin SqrD:=Sqr(X1-X2)+Sqr(Y1-Y2)+Sqr(Z1-Z2); Alpha:=Arctan(Sqrt(SqrD)/2/Sqrt(1-SqrD/4))*2; End; L:=Alpha*6875/2; Write('The distance to the iceberg: '); Write(L:0:2); WriteLn(' miles.'); If Round(L*100)<10000 Then WriteLn('DANGER!'); End. Message #488. Received at 18:15:23. Current ship's coordinates are 45^00'00" SL and 45^00'00" WL. An iceberg was noticed at 45^00'00" NL and 45^00'00" WL. === Message #488. Received at 18:15:23. Current ship's coordinates are 41^46'00" NL and 50^14'00" WL. An iceberg was noticed at 41^14'11" NL and 51^09'00" WL. === Message #488. Received at 18:15:23. Current ship's coordinates are 45^00'00" SL and 45^00'00" WL. An iceberg was noticed at 45^00'00" NL and 135^00'00" EL. === Message #488. Received at 18:15:23. Current ship's coordinates are 90^00'00" NL and 50^14'00" WL. An iceberg was noticed at 90^00'00" SL and 151^09'00" WL. === Message #488. Received at 18:15:23. Current ship's coordinates are 0^00'00" NL and 50^00'00" WL. An iceberg was noticed at 0^00'00" SL and 130^00'00" EL. === Message #488. Received at 18:15:23. Current ship's coordinates are 40^00'00" NL and 1^00'00" WL. An iceberg was noticed at 40^00'00" NL and 1^00'00" EL. === Message #488. Received at 18:15:23. Current ship's coordinates are 40^09'18" NL and 1^00'01" WL. An iceberg was noticed at 40^50'11" NL and 1^00'00" EL. === Message #488. Received at 18:15:23. Current ship's coordinates are 40^09'19" NL and 1^00'01" WL. An iceberg was noticed at 40^50'12" NL and 1^00'00" EL. === The distance to the iceberg: 5399.61 miles. The distance to the iceberg: 52.04 miles. DANGER! The distance to the iceberg: 7199.48 miles. The distance to the iceberg: 10799.22 miles. The distance to the iceberg: 4799.66 miles. The distance to the iceberg: 91.92 miles. DANGER! The distance to the iceberg: 100.00 miles. The distance to the iceberg: 99.99 miles. DANGER! > The distance to the iceberg: 5399.61 miles. > The distance to the iceberg: 52.04 miles. > DANGER! > The distance to the iceberg: 7199.48 miles. > The distance to the iceberg: 10799.22 miles. > The distance to the iceberg: 4799.66 miles. > The distance to the iceberg: 91.92 miles. > DANGER! > The distance to the iceberg: 100.00 miles. > The distance to the iceberg: 99.99 miles. > DANGER! > > The distance to the iceberg: 5399.61 miles. > The distance to the iceberg: 52.04 miles. > DANGER! > The distance to the iceberg: 7199.48 miles. > The distance to the iceberg: 10799.22 miles. > The distance to the iceberg: 4799.66 miles. > The distance to the iceberg: 91.92 miles. > DANGER! > The distance to the iceberg: 100.00 miles. > The distance to the iceberg: 99.99 miles. > DANGER! > Look carefully at test : Message #488. Received at 18:15:23. Current ship's coordinates are 45^00'00" SL and 45^00'00" WL. An iceberg was noticed at 45^00'00" NL and 135^00'00" EL. === My answer is 10799.22 AC program gives answers The distance to the iceberg: 5399.61 miles. The distance to the iceberg: 52.04 miles. DANGER! The distance to the iceberg: 10799.22 miles. The distance to the iceberg: 10799.22 miles. The distance to the iceberg: 10799.22 miles. The distance to the iceberg: 91.92 miles. DANGER! The distance to the iceberg: 100.00 miles. The distance to the iceberg: 99.99 miles. DANGER! Why answer for A1A is 22? Shouldn't it be 11? If u assume A1A is in base 11, the decimal equivalent is 1231. Clearly its not divisible by (11-1). Hope it explains. Try it as base 22 and you will see the resultant number is divisible by 21. Edited by author 21.09.2013 16:23 Consider two test cases: 3 3 3 1 2 2 3 3 1 and 3 3 3 1 3 2 1 3 2 Although they are symmetric and the answers must be equal, my AC programs (5180921 or 5180891) output different answers for them. Your tests were added. Thank you. Hello My python code is as follows: [code deleted] I get TLE in # 20 Where can I save time? Edited by moderator 01.12.2019 21:35 I'm not sure, but maybe a lot of .append()'s could work too slow... Maybe you could try a = [0] * n and then a[i] = ... Hello When I change my solution with a=[0]*n it takes 0.546 sec Before the change it took 0.515 sec. The first hint brings no AC Edited by author 20.09.2013 22:41 Edited by author 20.09.2013 22:41 Tough to AC, but possible (finally I managed to do it). Since there can be up to 100000 queries, bottleneck is output as usual with Python. Don't use print - use sys.stdout.write() instead (interestingly, why you used sys.stdin for input and print for output?) Edited by author 18.09.2013 04:30 Using sys.stdout.write ('\n'.join ([str (x) for x in b]) My solution takes .515 sec No AC Looking at TLE times in testing queue is a misleading way to analyze your code effectiveness (actually, it shows time after which your code was halted with TLE verdict rather than acrtual running time). Test it locally on large tests and measure time efficiency of each alternative. Also, I see you submit on Python 3. That may be the problem - I ACed on Python 2. I used python 2.7.5 this time. My code was unchanged AC in .468 Thanks for all the advise Edited by author 21.09.2013 03:57 var a,b:integer; begin readln(a,b); writeln(a mod 10 + a div 10 * 10 + b mod 10 + b div 10 * 10); readln; end. 15 3 1 5 11 correct output:1 Some of these are not mentioned in the problem statement - The input can have other separators than spaces, eg: 'Re ad' is two words and so is 'Re*ad' - There is no word with length 0, so there can be two separators, eg: 'Re**ad' is two words not three (if you have WA#6 check this) - Inputs are of multiple lines, so you can use EOF to check for end of input. Edited by author 09.04.2013 17:18 Edited by author 09.04.2013 17:18 Robert Help! [1] 19 сен 2013 11:52 Edited by author 19.09.2013 12:43 Edited by author 19.09.2013 12:44 Edited by author 19.09.2013 12:43 "(one|puton|out|output|in|input)+" it has simple solve using regexp, but i got ML 1. How to read correctly? Edited by author 18.09.2013 18:24 Read only char-by-char (token-by-token). In the worst case you will have one string of 10^7 chars - this will get ML anyway (and with java it will occur much earlier). So, don't cheat, write parser honestly. Can anyone help me with test 4? #include <iostream> #include <cstdio> using namespace std; int main() { char c[3]; float v[3]; float R = 8.314, p, V, T, n; scanf("%c = %f\n", &c[0], &v[0]); scanf("%c = %f\n", &c[1], &v[1]); scanf("%c = %f", &c[2], &v[2]); for(int i = 0; i < 3; i++) { if(c[i] == 'p') p = v[i]; else if(c[i] == 'V') V = v[i]; else if(c[i] == 'T') T = v[i]; else if(c[i] == 'n') n = v[i]; } if(c[0] != 'n' && c[1] != 'n' && c[2] != 'n') { n = p*V/(R*T); if(T == 0 && (p == 0 || V == 0)) cout << "undefined\n"; else if(T == 0 && (p != 0 || V != 0)) cout << "error\n"; else if(p < 0 || V < 0 || T < 0 || n < 0) cout << "error\n"; else printf("n = %f\n", n); } else if(c[0] != 'T' && c[1] != 'T' && c[2] != 'T') { T = p*V/(R*n); if(n == 0 && (p == 0 || V == 0)) cout << "undefined\n"; else if(n == 0 && (p != 0 || V != 0)) cout << "error\n"; else if(p < 0 || V < 0 || n < 0 || T < 0) cout << "error\n"; else printf("T = %f\n", T); } else if(c[0] != 'V' && c[1] != 'V' && c[2] != 'V') { V = n*T*R/p; if(p == 0 && (T == 0 || n == 0)) cout << "undefined\n"; else if(p == 0 && (T != 0 || n != 0)) cout << "error\n"; else if(p < 0 || T < 0 || n < 0 || V < 0) cout << "error\n"; else printf("V = %f\n", V); } else if(c[0] != 'p' && c[1] != 'p' && c[2] != 'p') { p = n*T*R/V; if(T == 0 && (n == 0 || V == 0)) cout << "undefined\n"; else if(T == 0 && (n != 0 || V != 0)) cout << "error\n"; else if(V < 0 || n < 0 || T < 0) cout << "error\n"; else printf("p = %f\n", p); } return 0; } If you have WA4 try test 3 2 1 asnwer: 2 1 Edited by author 18.09.2013 18:27 using System; class Program { static void Main() { int a = 1; int N; N = int.Parse(Console.ReadLine()); if(Math.Abs(N)<10000) if (N >= 1) Console.WriteLine(((a + N) / 2) * N); else Console.WriteLine(((a+Math.Abs(N)) / 2) * N+1); else Console.WriteLine("ERROR"); } } Edited by author 18.09.2013 00:10 Edited by author 18.09.2013 00:12 what if the output is N=2 (a+N)/2=1.5 1.5*2=3.0 this is not an integer better: (N+1)*N div 2 if N<0: -((N+1)*N div 2) + 1 if you're writing in c++ - use unordered_map instead of map :) #include <conio.h> #include <algorithm> #include <iostream> #include <cstdio> #include <stdio.h> #include <string.h> using namespace std; int povtor (char str[31],char mas2[1001][31],int mas2len) { int i; for (i=0; i<mas2len; i++) { if (strcmp(str,mas2[i])==0) return 0; } return 1; } int main() { int N; char mas[1001][31]; char mas2[1001][31];
int mas2len=0;
cin >> N; for (int i=0; i<N; i++) { cin >> mas[i]; }
for (int i=0; i<N; i++) { if (povtor(mas[i],mas2,mas2len)) strcpy(mas2[mas2len++],mas[i]); }
cout << N-mas2len;
getch(); } Write your own sqrt function (with blackjack and hookers) with supporting __int64 and it'll be OK. It helped me. Edited by author 15.09.2013 16:35 = =!If there are some place wrong in my case,please notice me. 100 100 2 24 100 65 92 100 9 56 100 40 55 100 68 14 100 76 21 100 21 15 100 82 86 100 3 40 100 72 40 100 92 45 100 39 82 100 84 72 100 44 63 100 88 17 100 62 21 100 41 15 100 73 82 100 36 70 100 33 22 100 78 60 100 57 34 100 66 71 100 56 83 100 93 56 100 25 70 100 99 64 100 68 39 100 85 70 100 86 29 100 91 67 100 52 18 100 4 44 100 81 97 100 59 38 100 17 78 100 73 83 100 98 44 100 45 37 100 11 9 100 97 99 100 63 94 100 75 54 100 6 7 100 84 15 100 97 19 100 30 90 100 51 39 100 42 9 100 88 16 100 70 38 100 70 64 100 5 82 100 37 41 100 76 95 100 69 18 100 72 54 100 100 55 100 28 4 100 60 1 100 8 86 100 1 66 100 87 53 100 87 27 100 18 79 100 14 19 100 21 41 100 93 8 100 31 100 100 63 74 100 48 10 100 62 74 100 42 59 100 31 50 100 97 21 100 15 93 100 64 16 100 37 56 100 88 41 100 99 16 100 76 19 100 89 61 100 97 18 100 47 73 100 9 29 100 100 38 100 83 15 100 94 47 100 72 37 100 3 38 100 51 89 100 63 55 100 84 22 100 14 95 100 64 16 100 99 8 100 39 37 100 15 78 100 11 22 100 64 44 100 Your test was added. Thank you. Problem statement, tests and time limit were changed. Read the Site news for more information. |
|