Common Board#include <stdio.h> #include <stdlib.h> #include <iostream> #include <cstdlib> #include <math.h> #define PI 3.141592653589793238462643383279502884197169399375 using namespace std; int main(int argc, char** argv){ double a, l, angle = 0.0; cin >> a >> l; if (l <= (a/2.0)) printf("%0.3f", (l*l*PI)); else if (l >= (a*sqrt(2.0)/2.0)) printf("%0.3f", (a*a)); else { while (l*cos(angle) > (a/2.0)) angle += 0.0000001; printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle)))); } } please explain : else { while (l*cos(angle) > (a/2.0)) angle += 0.0000001; printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle)))); } i don't understand with your way of thinking to get that calculation.. please explain to me.. His solution is not stupid instead it is great I tried with mathematic way to find l to the point where the circle crosess the rect but every time i got WA. l*cos(angle) -that means the length to the point where the circle crosses the rect-s side.At the begining it is equals to r but as we increase angel the cos(angel) decreases the value and we find the exact length. and here ("%0.3f", 4.0*((a/2.0)*l*sin(angle) we find the are of triangles and add the are of sectors +(l*l*(PI/4.0-angle))...that is all ..if you don't understand again contact me with the problem name.. imran_yusubov@yahoo.com please explain : else { while (l*cos(angle) > (a/2.0)) angle += 0.0000001; printf("%0.3f", 4.0*((a/2.0)*l*sin(angle)+(l*l*(PI/4.0-angle)))); } i don't understand with your way of thinking to get that calculation.. please explain to me.. Edited by author 07.08.2009 12:19 Edited by author 07.08.2009 12:20Why woudn`t you just use acos(a/(l*2)) to get an angle? ( its arc cos in the triangle we get there) |\ | \ | \ | \ l | \ |a/2 \ | \ |_______\ Edited by author 31.05.2013 05:43 Think about this case If you use DP 2 2 1 1 0 0 when considering the elem 0 at [1, 0] , you can find the way from [0, 1] -> [1, 0] and [0, 1] -> [1, 1] -> [1, 0] have the same sum(both are 1), how to handle this situation ? I handle this by giving the way from `ABOVE` higher priority, or else when printing the path to the answer, you wil get [1, 0] <- [1, 1] <- [1, 0] <- [1, 1] ....... which is WA. and another thing to notice is you may need long long to hold. hope it helps :) I'm trying to solve this in java. This probably sounds silly, but I don't get do I need to use StreamTokenizer as was mentioned in the local java guide? Or I just need to read input char by char? Are spaces between numbers necessary? And where if they are? Same question for both input and output. Edited by author 16.05.2013 05:00 Edited by author 16.05.2013 05:01 I think if L is odd, answer: "Unsuitable device" otherwise we can get all cycles where L%2==0&&L<=n*n. But I got WA#4. What is wrong? (sorry for poor english.) thank. > What is wrong? Might just be a code mistake. I had the exact right idea but two stupid bugs that got hit in WA#4 and WA#5. There is some test cases: For n=5 and L=24 I got Overwhelming power of magic 1 1 2 1 3 1 4 1 5 1 5 2 5 3 5 4 5 5 4 5 4 4 4 3 4 2 3 2 3 3 3 4 3 5 2 5 1 5 1 4 2 4 1 4 1 3 1 2 for n=5 and L=22 Overwhelming power of magic 1 1 2 1 3 1 4 1 5 1 5 2 5 3 5 4 5 5 4 5 4 4 4 3 4 2 3 2 3 3 3 4 3 5 2 5 1 5 1 4 1 3 1 2 for n=5 and L=16 Overwhelming power of magic 1 1 2 1 3 1 4 1 4 2 4 3 4 4 3 4 3 3 3 2 2 2 2 3 2 4 1 4 1 3 1 2 for n=5 and L=4 Overwhelming power of magic 1 1 2 1 2 2 1 2 What is wrong? > What is wrong? 1 4 2 4 1 4 Thank you! My program Accepted. It is my e-mail: oa1990_10_17@mail.ru Кто нибудь на си++ может эту задачу скинуть на мыло... очень надо... Jonzah@list.ru заранее благодарю. если кто-нибудь скинет ,скинь мне прошу)))rtu456@rambler.ru Hi, All I want to download all my accepted solution. Could anyone tell me is there a way to do that? Thanks currently, you have to manually do it one by one. i hope there is an archive function in the future. Try this one: 1 1000000 1 1001 1000 Really right answer: Block the hole And the problem can be solved in integer numbers. thanks. it helped me a lot. Edited by author 15.05.2013 18:25 Edited by author 15.05.2013 18:25 Please, give me some tests, i don't know, what wrong in my program( 725049 No 725870 No 727870 Yes My solution: *** program lam; var st,s1,s2,ins: string; e1,e2,k,n2,n1,e,z,q,i: integer; begin readln(st); z:=0; if st[1]='0' then begin q:=1; for i:=2 to 5 do begin if st[i]='0' then inc(q); if st[i]<>'0' then break; end; end; val(st,e,k); n1:=e+1; n2:=e-1; str(n1,s1); str(n2,s2); if q=1 then begin ins:='0'; insert(ins,s1,1); end; if q=2 then begin ins:='00'; insert(ins,s1,1); end; if q=3 then begin ins:='000'; insert(ins,s1,1); end; if q=4 then begin ins:='0000'; insert(ins,s1,1); end; if q=5 then begin ins:='00000'; insert(ins,s1,1); end; if q=1 then begin ins:='0'; insert(ins,s2,1); end; if q=2 then begin ins:='00'; insert(ins,s2,1); end; if q=3 then begin ins:='000'; insert(ins,s2,1); end; if q=4 then begin ins:='0000'; insert(ins,s2,1); end; if q=5 then begin ins:='00000'; insert(ins,s2,1); end; val(copy(s1,1,3),e1,k); val(copy(s1,4,3),e2,k); if (e1 mod 10)+((e1 mod 100) div 10)+(e1 div 100)=(e2 mod 10)+((e2 mod 100) div 10)+(e2 div 100) then z:=1; val(copy(s2,1,3),e1,k); val(copy(s2,4,3),e2,k); if (e1 mod 10)+((e1 mod 100) div 10)+(e1 div 100)=(e2 mod 10)+((e2 mod 100) div 10)+(e2 div 100) then z:=1; if z=1 then writeln('YES') else writeln('NO'); end. *** очень большое и глупое решение, гораздо проще вот так: function prov(n:longint):integer; var a1,a2,a3,b1,b2,b3:integer; begin a1:=n div 100000; a2:=n div 10000 mod 10; a3:=n div 1000 mod 10; b1:=n div 100 mod 10; b2:=n div 10 mod 10; b3:=n mod 10; if b1+b2+b3=a1+a2+a3 then prov:=1 else prov:=2; end; var n,n1,n2:longint; begin read(n); n1:=n+1; n2:=n-1; if (prov(n1)=1)or(prov(n2)=1) then writeln('Yes') else writeln('No'); end. sorry for russian. P.S. Time 0.031 Memory 118 725870 why No?? 725870 + 1 = 725871 (14 != 16) 725870 - 1 = 725869 (14 != 23) H!. help me please ihave WA in the test # 8, give me test This test helped me: a+a^2+a^3+a^4+a^5+a^6+a^7+a^8+a^9+a^10+a^11+a^12+a^13+a^15+a^14+a^16+a^17+a^18+a^19+a^20+a^21+a^22 b+b^2+b^3+b^4+b^5+b^6+b^7+b^8+b^9+b^10+b^11+b^12+b^13+b^15+b^14+b^16+b^17+b^18+b^19+b^20+b^21+b^22 Answer: a^22*b^22 + a^22*b^21 + a^21*b^22 + a^22*b^20 + a^21*b^21 + a^20*b^22 + a^22*b^19 + a^21*b^20 + a^20*b^21 + a^19*b^22 + a^22*b^18 + a^21*b^19 + a^20*b^20 + a^19*b^21 + a^18*b^22 + a^22*b^17 + a^21*b^18 + a^20*b^19 + a^19*b^20 + a^18*b^21 + a^17*b^22 + a^22*b^16 + a^21*b^17 + a^20*b^18 + a^19*b^19 + a^18*b^20 + a^17*b^21 + a^16*b^22 + a^22*b^15 + a^21*b^16 + a^20*b^17 + a^19*b^18 + a^18*b^19 + a^17*b^20 + a^16*b^21 + a^15*b^22 + a^22*b^14 + a^21*b^15 + a^20*b^16 + a^19*b^17 + a^18*b^18 + a^17*b^19 + a^16*b^20 + a^15*b^21 + a^14*b^22 + a^22*b^13 + a^21*b^14 + a^20*b^15 + a^19*b^16 + a^18*b^17 + a^17*b^18 + a^16*b^19 + a^15*b^20 + a^14*b^21 + a^13*b^22 + a^22*b^12 + a^21*b^13 + a^20*b^14 + a^19*b^15 + a^18*b^16 + a^17*b^17 + a^16*b^18 + a^15*b^19 + a^14*b^20 + a^13*b^21 + a^12*b^22 + a^22*b^11 + a^21*b^12 + a^20*b^13 + a^19*b^14 + a^18*b^15 + a^17*b^16 + a^16*b^17 + a^15*b^18 + a^14*b^19 + a^13*b^20 + a^12*b^21 + a^11*b^22 + a^22*b^10 + a^21*b^11 + a^20*b^12 + a^19*b^13 + a^18*b^14 + a^17*b^15 + a^16*b^16 + a^15*b^17 + a^14*b^18 + a^13*b^19 + a^12*b^20 + a^11*b^21 + a^10*b^22 + a^22*b^9 + a^21*b^10 + a^20*b^11 + a^19*b^12 + a^18*b^13 + a^17*b^14 + a^16*b^15 + a^15*b^16 + a^14*b^17 + a^13*b^18 + a^12*b^19 + a^11*b^20 + a^10*b^21 + a^9*b^22 + a^22*b^8 + a^21*b^9 + a^20*b^10 + a^19*b^11 + a^18*b^12 + a^17*b^13 + a^16*b^14 + a^15*b^15 + a^14*b^16 + a^13*b^17 + a^12*b^18 + a^11*b^19 + a^10*b^20 + a^9*b^21 + a^8*b^22 + a^22*b^7 + a^21*b^8 + a^20*b^9 + a^19*b^10 + a^18*b^11 + a^17*b^12 + a^16*b^13 + a^15*b^14 + a^14*b^15 + a^13*b^16 + a^12*b^17 + a^11*b^18 + a^10*b^19 + a^9*b^20 + a^8*b^21 + a^7*b^22 + a^22*b^6 + a^21*b^7 + a^20*b^8 + a^19*b^9 + a^18*b^10 + a^17*b^11 + a^16*b^12 + a^15*b^13 + a^14*b^14 + a^13*b^15 + a^12*b^16 + a^11*b^17 + a^10*b^18 + a^9*b^19 + a^8*b^20 + a^7*b^21 + a^6*b^22 + a^22*b^5 + a^21*b^6 + a^20*b^7 + a^19*b^8 + a^18*b^9 + a^17*b^10 + a^16*b^11 + a^15*b^12 + a^14*b^13 + a^13*b^14 + a^12*b^15 + a^11*b^16 + a^10*b^17 + a^9*b^18 + a^8*b^19 + a^7*b^20 + a^6*b^21 + a^5*b^22 + a^22*b^4 + a^21*b^5 + a^20*b^6 + a^19*b^7 + a^18*b^8 + a^17*b^9 + a^16*b^10 + a^15*b^11 + a^14*b^12 + a^13*b^13 + a^12*b^14 + a^11*b^15 + a^10*b^16 + a^9*b^17 + a^8*b^18 + a^7*b^19 + a^6*b^20 + a^5*b^21 + a^4*b^22 + a^22*b^3 + a^21*b^4 + a^20*b^5 + a^19*b^6 + a^18*b^7 + a^17*b^8 + a^16*b^9 + a^15*b^10 + a^14*b^11 + a^13*b^12 + a^12*b^13 + a^11*b^14 + a^10*b^15 + a^9*b^16 + a^8*b^17 + a^7*b^18 + a^6*b^19 + a^5*b^20 + a^4*b^21 + a^3*b^22 + a^22*b^2 + a^21*b^3 + a^20*b^4 + a^19*b^5 + a^18*b^6 + a^17*b^7 + a^16*b^8 + a^15*b^9 + a^14*b^10 + a^13*b^11 + a^12*b^12 + a^11*b^13 + a^10*b^14 + a^9*b^15 + a^8*b^16 + a^7*b^17 + a^6*b^18 + a^5*b^19 + a^4*b^20 + a^3*b^21 + a^2*b^22 + a^22*b + a^21*b^2 + a^20*b^3 + a^19*b^4 + a^18*b^5 + a^17*b^6 + a^16*b^7 + a^15*b^8 + a^14*b^9 + a^13*b^10 + a^12*b^11 + a^11*b^12 + a^10*b^13 + a^9*b^14 + a^8*b^15 + a^7*b^16 + a^6*b^17 + a^5*b^18 + a^4*b^19 + a^3*b^20 + a^2*b^21 + a*b^22 + a^21*b + a^20*b^2 + a^19*b^3 + a^18*b^4 + a^17*b^5 + a^16*b^6 + a^15*b^7 + a^14*b^8 + a^13*b^9 + a^12*b^10 + a^11*b^11 + a^10*b^12 + a^9*b^13 + a^8*b^14 + a^7*b^15 + a^6*b^16 + a^5*b^17 + a^4*b^18 + a^3*b^19 + a^2*b^20 + a*b^21 + a^20*b + a^19*b^2 + a^18*b^3 + a^17*b^4 + a^16*b^5 + a^15*b^6 + a^14*b^7 + a^13*b^8 + a^12*b^9 + a^11*b^10 + a^10*b^11 + a^9*b^12 + a^8*b^13 + a^7*b^14 + a^6*b^15 + a^5*b^16 + a^4*b^17 + a^3*b^18 + a^2*b^19 + a*b^20 + a^19*b + a^18*b^2 + a^17*b^3 + a^16*b^4 + a^15*b^5 + a^14*b^6 + a^13*b^7 + a^12*b^8 + a^11*b^9 + a^10*b^10 + a^9*b^11 + a^8*b^12 + a^7*b^13 + a^6*b^14 + a^5*b^15 + a^4*b^16 + a^3*b^17 + a^2*b^18 + a*b^19 + a^18*b + a^17*b^2 + a^16*b^3 + a^15*b^4 + a^14*b^5 + a^13*b^6 + a^12*b^7 + a^11*b^8 + a^10*b^9 + a^9*b^10 + a^8*b^11 + a^7*b^12 + a^6*b^13 + a^5*b^14 + a^4*b^15 + a^3*b^16 + a^2*b^17 + a*b^18 + a^17*b + a^16*b^2 + a^15*b^3 + a^14*b^4 + a^13*b^5 + a^12*b^6 + a^11*b^7 + a^10*b^8 + a^9*b^9 + a^8*b^10 + a^7*b^11 + a^6*b^12 + a^5*b^13 + a^4*b^14 + a^3*b^15 + a^2*b^16 + a*b^17 + a^16*b + a^15*b^2 + a^14*b^3 + a^13*b^4 + a^12*b^5 + a^11*b^6 + a^10*b^7 + a^9*b^8 + a^8*b^9 + a^7*b^10 + a^6*b^11 + a^5*b^12 + a^4*b^13 + a^3*b^14 + a^2*b^15 + a*b^16 + a^15*b + a^14*b^2 + a^13*b^3 + a^12*b^4 + a^11*b^5 + a^10*b^6 + a^9*b^7 + a^8*b^8 + a^7*b^9 + a^6*b^10 + a^5*b^11 + a^4*b^12 + a^3*b^13 + a^2*b^14 + a*b^15 + a^14*b + a^13*b^2 + a^12*b^3 + a^11*b^4 + a^10*b^5 + a^9*b^6 + a^8*b^7 + a^7*b^8 + a^6*b^9 + a^5*b^10 + a^4*b^11 + a^3*b^12 + a^2*b^13 + a*b^14 + a^13*b + a^12*b^2 + a^11*b^3 + a^10*b^4 + a^9*b^5 + a^8*b^6 + a^7*b^7 + a^6*b^8 + a^5*b^9 + a^4*b^10 + a^3*b^11 + a^2*b^12 + a*b^13 + a^12*b + a^11*b^2 + a^10*b^3 + a^9*b^4 + a^8*b^5 + a^7*b^6 + a^6*b^7 + a^5*b^8 + a^4*b^9 + a^3*b^10 + a^2*b^11 + a*b^12 + a^11*b + a^10*b^2 + a^9*b^3 + a^8*b^4 + a^7*b^5 + a^6*b^6 + a^5*b^7 + a^4*b^8 + a^3*b^9 + a^2*b^10 + a*b^11 + a^10*b + a^9*b^2 + a^8*b^3 + a^7*b^4 + a^6*b^5 + a^5*b^6 + a^4*b^7 + a^3*b^8 + a^2*b^9 + a*b^10 + a^9*b + a^8*b^2 + a^7*b^3 + a^6*b^4 + a^5*b^5 + a^4*b^6 + a^3*b^7 + a^2*b^8 + a*b^9 + a^8*b + a^7*b^2 + a^6*b^3 + a^5*b^4 + a^4*b^5 + a^3*b^6 + a^2*b^7 + a*b^8 + a^7*b + a^6*b^2 + a^5*b^3 + a^4*b^4 + a^3*b^5 + a^2*b^6 + a*b^7 + a^6*b + a^5*b^2 + a^4*b^3 + a^3*b^4 + a^2*b^5 + a*b^6 + a^5*b + a^4*b^2 + a^3*b^3 + a^2*b^4 + a*b^5 + a^4*b + a^3*b^2 + a^2*b^3 + a*b^4 + a^3*b + a^2*b^2 + a*b^3 + a^2*b + a*b^2 + a*b Yes, I had wa8, this test has helped me, the mistake was sorted degrees Edited by author 03.11.2013 17:06 var x,n,m,y,i1,i,code:integer; a,k:array[1..100] of integer; c:array[1..100] of string; s:string; t:boolean; begin repeat readln(n); until (n>0) and (n<1001); for i:=1 to n do begin readln(a[i]); if a[i]<=0 Then t:=true; end; i:=2; x:=1; If t=false Then begin For i:=2 to n do begin if a[i-1]=a[i] Then x:=x+1 else begin write(x,' ',a[i-1],' '); x:=1; end; end; if n<>1 THEN write(x,' ',a[i]) ELSE write(x,' ',a[i-1]); end end. Please, help me #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int M, N, t=0, d; cin>>N; vector<int> n(N); for(int i=0; i<N; i++) { cin>>n[i]; } sort(n.begin(), n.end()); n.erase(unique(n.begin(), n.end() ), n.end()); cin>>M; for(int i=0; i<M; i++) { cin>>d; if((d>=n[0])and(d<=n[N-1])) { t+=count(n.begin(),n.end(),d); } } cout<<t; return(0); } var n,k,m,i,i1:longint; w:array[1..1000000] of longint; w1:array[1..100000] of longint; begin readln(n); For i:=1 to n do readln(w[i]); readln(m); For i:=1 to m do readln(w1[i]); For i:=1 to n do begin For i1:=1 to m do begin if w[i]=w1[i1] Then begin k:=k+1; w1[i1]:=0; end; end; end; Writeln(k); end. I have the WA too. HELLLP I used DP , 0.8 sec , but some people only used 0.04 sec and uesd less than 100K memory ! why ? How can they do it ? can anybody tell me ? > I used DP , 0.8 sec , but some people only used 0.04 sec and uesd > less than 100K memory ! why ? How can they do it ? can anybody tell > me ? how? i managed a 0.09 O(n^3) but how do u do n^2?? i might have an N^2 ideea but it n^2 memory...... X[i]: how many black horses are in the first i horses Y[i]: how many white horses are in the first i horses We use Dp. F[i,j] = min { F[i-1,k] + (X[j]-X[k])*(Y[j]-Y[k]) } | K<J The answer is F[K,N]. Suppose F[i,j] get the minimal value when k=k0. Let W[i,j]=k0. You can prove : w[i,j-1]<=w[i,j]<=w[i+1,j] So you can solve this problem in o(n^2). Sorry, could you explain please what's k0? i accepted :D Congratulations! I accepted too : ) It's easy task Edited by author 11.05.2013 17:15 Edited by author 11.05.2013 17:15 #pragma comment(linker, "/STACK:16777216") //cpp stuff #include <stdio.h> #include <math.h> int main() { unsigned long long a[0x20000]; long i=0; while (scanf("%llu", &a[i++]) != EOF); i--; while (i) printf("%.4f\n", sqrt((long double)a[--i])); return 0; } Please give me some test for cheking. what data test 2, because i being error wa 2 Try this testcase: 1000000000 1000000000 -1000000000 The answer is 5. My program uses unsigned int64 in C++, and gets overflow on this case. |
|