Common BoardI am failing test#1 var minked,j,i,k,n : byte; tsum,sum: longint; BEGIN readln(n); readln(k); sum:=0; if (n mod 2=0) then minked:=(n div 2) else minked:=(n div 2)+1; for i:=minked to n do begin tsum:=1; for j:=1 to i do begin tsum:=tsum*(k-1); end; sum:=sum+tsum; end; writeln(sum); END. Lual.ru var i,j,k,m,n,ans:Longint; procedure search(m,p,plus:Longint); begin if m=n+1 then begin ans:=ans+plus;exit;end; if p<>0 then search(m+1,0,plus); search(m+1,1,plus*(k-1)); end; begin read(n,k); search(1,0,1); writeln(ans); end. dfs纯暴力.. My multitest has fallen at this test. I got AC when deleted it. Please, clear it from some trash in the end. Thank you! I change "while(scanf("%d",&n)!=EOF)" to "scanf("%d",&n)" and got AC. I think there is something wrong with the ninth data. Edited by author 23.04.2009 05:04 try this test: input: a1 h8 a3 h6 a5 h4 a7 h2 b2 g7 b4 g5 b6 g3 b8 g1 c1 f8 c3 f6 c5 f4 c7 f2 d2 e7 d4 e5 d6 e3 d8 e1 output: Draw first my code write 31. program ural1334; const dx:array[1..8]of shortint=(-1,-1,-1,0,1,1,1,0); dy:array[1..8]of shortint=(-1,0,1,1,1,0,-1,-1); var a:array[0..9,0..9]of byte; i,x,y,d:byte; c:char; begin fillchar(a,sizeof(a),2); for i:=1 to 32 do begin readln(c,y); x:=ord(c)-96; for d:=1 to 8 do if a[x+dx[d],y+dy[d]]+i and 1=1 then begin writeln(i); halt; end; a[x,y]:=i and 1; end; writeln('Draw'); end. #include <iostream> using namespace std; void main() { int flag[100][100]; int flag1[100], N, j, flag2[100]; do { cin >> N; } while (N < 0 || N > 100);
for (int i = 1; i <= N; i++) { do { cin >> j; flag[i][j + 1] = 1; } while (j != 0); } flag1[1] = 1; for (int i = 1; i <= N; i++) { for (j = i + 1; j <= N; j++) { if (flag[i][j] == 1) { if (flag1[j] != 1 && flag1[j] != 2) { flag1[j] = 3 - flag1[i]; } } } } int i = 0; for (j = 1; j <= N; j++) { if (flag1[j] == 1) { flag2[i] = j; i++; } } for (j = 0; j < i; j++) { cout << flag1[i]; } } I have debugged, but finally I can't find why my code gives wrong answers. Anyone help me, plz. I considered some constructions and got AC. But full analysis of the problem seems equals to scintific reserch. For this problem all timus correspondents very need in short, proven and full consideration but this is just mathematic vork. I know only: L-R==4; F==2*k- it's absolutely clear. Case F==0 possible only if 1) L=4;R=0 2) R=2*k,L=R+4;k>=2. I think but failed to prove that cases F==0,L==6;R==2 impossible also as if F==0,R=2*k+1;L=R+4; Cases when F=2*k>0 ,L=R+4,R>0 all possible, simple and depend on regular constructions. Resume:On olimpiads often impossible to have full foundations for your algorithms. I agree that proving the correctness of your solution is a bit time-consuming for this task. Nevertheless, in the end the proof isn't that complicated, so I'll post it here in case someone finds it interesting. Suppose that we managed to position the plates (s straight segments and t turns) on the plane so that the line segments on them form a closed path. Let's introduce a coordinate system so that each plate can be described by a pair of integers (X, Y) giving the coordinates of its lower left corner. Let's start at any point in our closed path and traverse the entire path until we get back to the point where we started. At each point where we enter a new plate, let's look at the coordinates (X, Y) of the plate we're entering, and let's record a triple (x, y, d), where x = X mod 2, y = Y mod 2, and d is the direction we're facing at this particular point (one of N, W, S, E). If we know the triple (x, y, d) at the time we entered a plate, and if we know whether that plate is a left turn, a right turn, or a straight one, we can easily determine the triple that we'll get at the time we leave this plate and enter the next one. Thus for example, from 00N, a left turn takes you into 10W, a right turn takes you into 10E, and a straight segment takes you into 01N. If we keep computing possible transitions, we end up with a kind of state transition diagram with 16 possible states. I can't draw the diagram nicely here, but we can approximate it by arranging the states into a 4*4 grid: 00N 00S 01N 01S 10W 10E 00W 00E 11S 11N 10S 10N 01E 01W 11E 11W The transitions between states are very systematic: (1) A straight segment changes the state so that you remain in the same row, but move from the first column to the third (or vice versa), or from the second column to the fourth (or vice versa). (2) If you are in the left half of the grid (first two columns), a left turn moves you one row down (or from the fourth row back to the first one) but leaves you in the same column. A right turn moves you one row down as well, but it also switches you from the first to the second column and vice versa. (3) If you are in the right half of the grid (third and fourth column), a right turn moves you one row up (or from the first row into the fourth row) and leaves you in the same column. A left turn moves you one row up as well, but it also switches you from the third to the fourth column and vice versa. Of course, if our path is truly closed, we will finish in the same state where we started. We can assume without loss of generality that this state is 00N -- if it wasn't, we could always move and rotate the entire path (i.e. all the plates) a little bit. From (1) it follows that every straight segment moves us from the left half of the grid to the right one or vice versa. Since we started on the left half (in 00N) and have to finish there as well, it follows that the number of straight segments, i.e. s, must be even. From (2) and (3) it follows that every turn moves us from an odd row to an even row or vice versa. Since we started in the first row (in 00N) and must finish in the same row, it follows that the number of turns, i.e. t, must be even. We can also notice that a turn will always change the direction (the third character in our state) while a straight segment will leave it unchanged. For the path to be closed, we must be facing each of the four possible directions at some point, so we require at least four turns; thus t has to be >= 4. Now let's consider the special case when s = 0, i.e. there are no straight lines. Only the first two columns of our state grid are reachable (from 00N) in that case, and each turn we take moves us from the current row to the next row below it. Since we started in the first row and must finish in the first row as well, it follows that in this case t must be a multiple of 4. So, to summarize what we've seen so far: - s and t must be even - t must be >= 4 - if s = 0, then t must be a multiple of 4. Nearly all (s, t) that meet these constraints can be solved if we start by manually constructing solutions for cases where s = 0 and t = 4 or 16; and also for cases where s = 2 and t = 6 or 8 or 10. It is also easy to extend these paths by inserting 2 straight segments at a time, or by inserting 8 turns at a time. The only case which remains unsolved by these constructions is s = 0, t = 8. It turns out that no closed path exists with 8 turns and 0 straight segments, but I don't have an elegant proof of this (it is however easy to verify it with a program, using recursion). My solution is geometrical, it passes all of my tests, except of one, where one side has a length of 0. But I got WA on test #2, so: 1) Can a polygon have a side with length of 0? 2) Can somebody give me any tests for this problem? 1) I'm pretty sure it can't, since otherwise my AC solution has a big chance to divide by zero. 2) 3 0 0 3 0 0 3 answer: 1.9308 Yeah, this is a pretty simple test but it actually helped me to overcome that WA #2. @Chitanda Eru, but 1.9308 aint correct. UPD: it is. Edited by author 30.09.2013 02:21 but N — the number of polygon vertices (4 ≤ N ≤ 50) test: 0 3 0 0 0 0 33 answer: 1 4 Please, what is test 9? Can't find my mistake. Edited by author 23.08.2011 23:02 я так понимаю, тест 9 выглядит как 1 N. Но тогда вопрос в 4 тесте. Как он выглядит? оч-но, что первое число =1, а второе неизвестно. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<cmath> using namespace std; #define N 1000000 #define LL long long #define lowbit(x) x&(-x) LL re[N+10]; void add(int x,int d) { while(x) { re[x]+=d; x-=lowbit(x); } } LL getsum(int x) { LL s = 0; while(x<=N) { s+=re[x]; x+=lowbit(x); } return s; } int main() { int num; LL sum=0; double k; char s[20]; while(scanf("%s",s)!=EOF) { if(s[0]=='Q') break; else if(s[0]=='B') { scanf("%lf",&k); int kk = floorl(k*100.0+0.5); add(kk,1); } else if(s[0]=='D') { scanf("%lf",&k); int kk = floorl(k*100.0+0.5); add(kk,-1); } else { scanf("%lf %d",&k,&num); int kk = floorl(k*100.0+0.5); LL ss = getsum(kk); if(ss>=num) sum+=num; else sum+=ss; } } printf("%.2lf\n",(double)sum/100.0); return 0; } help!! I've got AC with program that returns 2552 for input 2433. Edited by author 28.09.2013 04:09 Edited by author 28.09.2013 04:09 Your test was added. Thank you. Всем привет! Помогите плиз, никак не могу пройти тест номер 6. Какие числа не подбираю, у меня все работает. А вот что-то там хитрое в этом тесте, если не составит труда, помогите. Вот код: [cpp] #include <cmath> #include <cstdio> int main(int argc, char* argv[]) { double tmp[32]; char i = 0; while (i < 32 && std::scanf("%lf", &tmp[i]) != EOF) { ++i; } for (--i; i >= 0; --i) { std::printf("%.4lf\n", sqrt(tmp[i])); } return 0; } [/cpp] You are probably joking =) Why did you decide that there can be at most 32 numbers in the input??? Wow, it's my mistake. Okey, so I can do working code, but tell my please, how does first place in top work? Only 760Kb of memory and 0.015s of working, it's amazing! My previus version was (0.421s/5244Kb) Thanks in advance 1) If N==a^2, that is if N is a full square, the answer is 1 2) Try N = a^2 + b^2. Brute force, but "clever" brute force. This is the most expensive part of the algo 3) N is NOT a sum of 3 squares <=> N=(8k+7)*4^m This is a fast step, about O(log(N)) 4) Lagrange theorem states: each number may be presented as a sum of 4 squares: N = a^2 + b^2 + c^2 + d^2 So if the upper three cases fails, the answer will be 4. Nice algorithm! Thank you, melkiy. But you can find N = a^2 + b^2 without brute-force. I considered this case by facrotizing N to primes and using Ferma-Euler theorem. How to apply Ferma-Euler theorem to this problem ? No brute force. Moreover, we don't need to find the sum of squares, we need just answer. find factorization of N = L*m^2, where L is not divisible by p^2 for p is prime. if L==1 then answer = 1 if L has no prime divisors of the form 4*t+3 then answer = 2 (Fermat) if N != (8*t+7)*4^k then answer = 3 (Legendre) else answer = 4 Thank, every body. +1 Got AC. Edited by author 22.01.2013 20:14 If L has prime divisors of the form 4*t+3,the answer may be 2,too. How to explain this question? Fermat's theorem says that if N=a^2+b^2, then L hasn't prime divisors of the form 4t+3, and back. A simpler to calculate approach is just to check if the prime decomposition contains no ODD powers of primes that can be expressed as 4*t+3, in which case the answer is two. Why WA 24? ... Give me some tests, please. What is algo? =) simple DP: int leftPos[char][pos] position of char which is left or equal of pos int lastPos[mask] : for substring s[lastPos[mask]..s.length()-1] we can get all name of sportman with char which is in mask. =) Не могу разобраться в чем ошибка. using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); string[] d = Console.ReadLine().Split(' '); int x = 0; int n = int.Parse(s[0])*int.Parse(s[1]); for (int i = 0 ; i < int.Parse(s[1]) ; i++) { x = x + int.Parse(d[i]); } if (x > n) { x = x - n; } else x = 0; Console.WriteLine(x); } } } Вопрос снят. Ошибку нашел. #include <iostream> int main() { int k1,k2; int count=0; int flag=1;
std::cin>>k1>>k2; for(;;) { if(flag==1) { if(count==k1) { std::cout<<"yes"; return 0; } count++; flag=-flag; } if(flag==-1) { if(count==k2) { std::cout<<"yes"; return 0; } count++; flag=-flag; } if(count>k1 && count>k2) { std::cout<<"no"; return 0; } }
} a better way: #include<iostream> using namespace std; int main(){ int lock1,lock2; cin>>lock1>>lock2; if(lock1%2==0||lock2%2==1){ cout<<"yes"; }else{ cout<<"no"; } return 0; } 1st. code is correct, but does not meet the requirements of the problem .. based on the conditions of the problem, such a check should be: if((a>0 && a <= 9999 && a%2 == 0)||(b>=0 && b <=9999 && b%2 ==1)) cout << "yes"; else cout << "no"; 0000 excluded from the search because the code has been entered., + indicated that a strictly four digit string to the test unchecked .. verdict .. flawed testing Edited by author 12.02.2013 17:11 #include <iostream> using namespace std; int main(){ int l,b; cin>>l>>b; l%2==0 || b%2==1 ? cout<<"yes" : cout<<"no"; } Edited by author 29.09.2013 13:22 Edited by author 29.09.2013 13:22 What's the meaning of your code ? and I'm not sure what's the main method to steal the bike by the thief. Could you mind tell me ? Edited by author 05.11.2012 22:48 you can see that thief is testing even code on night 1, 3, 5... and odd code on night 2, 4, 6... So thief can steal the bike if the code is even on night 1, 3, 5... and odd code on night 2, 4, 6... Code may be even on night 1,3,5 only if first lock have even code. Code may be odd on night 2,4,6 only if second lock have odd code. So you have to check only if first lock have even code or second have odd code. I have solved it with Dp in 0.015. Is there anyone fast(DP)? I'd be more interested in your memory strategy. I don't think DP alg will differ much for the same problem Maybe the test data are so simple, and DP is able to accept. But I don't think DP method is right. dp(bug task) and bruteforce (2^n) are both accepted for me it got accepted with brute force Time : 0.015 (I think its the minimal time) C++ using maps and vectors Used DP Want d code? gaston770@gmail.com Less than 15 lines of the algorithm My solution cost monstrously 0.187s using DP... Легко решается с динамическим програмированием. Делишь сумму камней на 2 части, потом запускаешь рюкзак до суммы камней/2, ответом будет являться abs(sum-2*maxx), где sum - сумма камней, а maxx - макс. вес, который мы можем поместить в наш "рюкзак" |
|