Common Board#include "stdafx.h" #include <iostream> #include <conio.h> using namespace std; void bubbleSort(int array[], int col){ int temp=0; for (int i=1; i<col ; i++){ for (int j=0; j<col-i; j++){ if (array [j]>array [j+1]){ temp=array[j]; array [j]=array [j+1]; array [j+1]=temp; } } } } int _tmain(int argc, _TCHAR* argv[]) { int k; int max; int sum; sum = 0; max = 0; cin >> k; int *p = new int[k-1]; int i; for (i = 0; i < k; i++) { cin >> p[i]; }
bubbleSort(p, k-1); k=k/2+1; for (i=0; i<k; i++) { sum = sum + p[i]/2+1; } cout << sum; _getch(); return 0; } kgxvh8-ov2fjo kgxvh8-ov2fjo(1) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory What's wrong? There is no problem in Visual Studio 12 :( My programm passes all my tests, but WA#3. Please, help. Thanks a lot. How you here have applied Dinamic Prog.? I the ambassador aside graph. Hi, Taras. I use simple method: I read two variables ot and ku. If ot and ku are in the same group, I Output('IMPOSSIBLE'); If they are in the different groups then I Continue else I put one variable into the first group and other into the second group. After that I divide "free" tasks between the groups... I hoped that It would get more than two tests... May be I should try to use graphs... BTW, tell me youre ICQ number, I cann't find you... Edited by author 02.05.2006 13:17 try this test, maybe will help you: 4 6 1 2 2 3 3 4 4 5 6 7 7 8 ANS: 1 3 5 7 2 4 6 8 You can use it. I used it as well. First you must paint the graph with black and white (use BFS) so that two vertices with the same edge are of different colors. After that you have pairs of integers and you have to combine them so that you have N in each round (that's not always possible). how I should combine them ?? Thenks, I have AC Edited by author 27.09.2013 15:34 I think my program is correct, but i've gotten wa 27 three times. Does anyone know what this test iss? Sorry please, i find mistake... Edited by author 24.09.2013 18:26 #include<iostream> #include<math.h> using namespace std; int main() {int t=0; int a,b,c; int d=0; long A[4001]; long B[4001]; long C[4001]; long D[4001]={0}; cin >> a; if(a <1 || a > 4000) exit(0); for(int i=0;i<a;i++) { cin >> A[i]; if(A[i] < 0 || A[i] >1000000000) exit(0); } cin >> b; if(b < 1 || b > 4000) exit(0); for(int i=0;i<b;i++) { cin >> B[i]; if(A[i] < 0 || B[i] >1000000000) exit(0); } cin >> c; if(c < 1 || c > 4000) exit(0); for(int i=0;i<c;i++) { cin >> C[i]; if(A[i] < 0 || C[i] >1000000000) exit(0); } for(int i=0;i<a;i++) for(int j=0;j<b;j++) if(A[i] == B[j]) { D[i]=A[i]; B[j]=0; t++; break; } for(int i=0;i<t;i++) for(int j=0;j<c;j++) if(D[i] == C[j]) { d++; C[j]=0; break; } cout << d; system("pause"); return 0; } program djy; var a:array[1..150,1..150] of integer; lx,ly,link:array[1..150] of integer; flagx,flagy:array[1..150] of boolean; n:longint; procedure init; var i,j:longint; begin readln(n); for i:=1 to n do for j:=1 to n do read(a[i,j]); end; procedure prepare; var i,j,s:longint; begin {for i:=1 to n do begin s:=0; for j:=1 to n do s:=s+a[j,i]; for j:=1 to n do a[j,i]:=a[j,i]-s; end;} fillchar(lx,sizeof(lx),0); fillchar(ly,sizeof(ly),0); for i:=1 to n do for j:=1 to n do if a[i,j]>lx[i] then lx[i]:=a[i,j]; end; function find(i:longint):boolean; var j:longint; begin flagx[i]:=true; for j:=1 to n do if (lx[i]+ly[j]=a[i,j]) and (flagy[j]=false) then begin flagy[j]:=true; if (link[j]=0) or (find(link[j])=true) then begin link[j]:=i; find:=true; exit; end; end; find:=false; end; procedure main; var i,j,k,d:longint; begin fillchar(link,sizeof(link),0); for k:=1 to n do repeat fillchar(flagx,sizeof(flagx),false); fillchar(flagy,sizeof(flagy),false); if find(k)=true then break; d:=maxint; for i:=1 to n do for j:=1 to n do if (flagx[i]=true) and (flagy[j]=false) and (lx[i]+ly[j]-a[i,j]<d) then d:=lx[i]+ly[j]-a[i,j]; for i:=1 to n do if flagx[i]=true then lx[i]:=lx[i]-d; for i:=1 to n do if flagy[j]=true then ly[j]:=ly[j]+d; until false; end; procedure print; var i,j,s:longint; begin s:=0; for i:=1 to n do for j:=1 to n do s:=s+a[i,j]; for i:=1 to n do s:=s-a[link[i],i]; writeln(s); end; begin init; prepare; main; print; end. You gotta use A+B code. I don't remember the correct algorithm but you can find'em in the tutorial. I got AC. Seriously. These days I've noticed that some programmer got stuck on BIG problems like "ships version 2", which may cost up to tens of seconds to judge. However the general limit for submitting a solution is 10 second. So, you see a whole lot page of 'waiting'. Maybe increase the interval for these problems? I think it is bad idea to tighten rules because of one genius (who made about 1000 submissions on the problem in several hours) - better just to ban it. But, since it is easy to register again, a good idea for timus maybe to restrict the number of submissions of one user (or from one IP) during the last 24 hours (at most 100, for example). Edited by author 20.09.2013 02:27 Edited by author 20.09.2013 08:33 Sounds readonable. Let's see what the admin has to say lol truth_table = { 'few': lambda x: x > 0 and x < 5, 'several': lambda x: x > 4 and x < 10, 'pack': lambda x: x > 9 and x < 20, 'lots': lambda x: x > 19 and x < 50, 'horde': lambda x: x > 49 and x < 100, 'throng': lambda x: x > 99 and x < 250, 'swarm': lambda x: x > 249 and x < 500, 'zounds': lambda x: x > 499 and x < 1000, 'legion': lambda x: x > 999 } def translate_count(count): for result, func in truth_table.items(): if func(count): return result translate_count(raw_input(u"Number: ")) Проверку локально проходит, может нужно не так обрабатывать входные параметры? It's strange but it works for Python3 (with corrections for print and input). current_key = int(input().strip()) backup_key = int(input().strip()) for thief_key in range(0, 9999): if current_key == thief_key: print("yes") break if thief_key > current_key or thief_key > backup_key: print("no") break temp_key = backup_key backup_key = current_key current_key = temp_key It passes tests with "0001/0000" -> no and "0002/0001" -> yes. And I traced it, it works right. But they said, that I have wrong answers. Why? P.S. Mistake of course was in the line: if thief_key > current_key or thief_key > backup_key: I should use and instead or. Edited by author 24.09.2013 01:56 #include<iostream> using namespace std; int main() { int a; cin >> a; if(a > 100 || a < 1) exit(0); int b[101]; int c; cin >> c; if(c > 100 || c < 1) exit(0); for(int i=0;i<c;i++) { cin >> b[i]; if(b[i] >= 101 || b[i] <= 0) exit(0); } int d=0; int j=0; int k=0; for(int i=0;i<c;i++) { if(i == c-1) k=b[i]-a; j=0; if(b[i] > a) { j=b[i]-a; b[i+1]+=j; d+=a; } } cout << k; system("pause"); return 0; } {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 |
|