Страница 1 My mail: ttxxli@163.com program ex; const maxn=2000; maxm=50; zero=1e-15; var g: Array[0..maxn, 1..maxm] of extended; cost: Array[1..maxn] of longint; from: Array[1..maxn] of longint; n, m: longint; ans: longint; num: Array[1..maxm] of longint; tot: longint; kk: Array[1..maxn] of longint; procedure init; var i, j: longint; begin read(n, m); for i:=1 to n do for j:=1 to m do read(g[i, j]); for i:=1 to n do begin read(cost[i]); from[i]:=i; end; end; procedure qsort(l, r: longint); var i, j: longint; x, y: longint; t: longint; begin i:=l; j:=r; x:=cost[(l+r) shr 1]; y:=from[(l+r) shr 1]; while i<=j do begin while (cost[i]<x)or(cost[i]=x)and(from[i]<y) do inc(i); while (cost[j]>x)or(cost[j]=x)and(from[j]>y) do dec(j); if i<=j then begin g[0]:=g[i]; g[i]:=g[j]; g[j]:=g[0]; t:=cost[i]; cost[i]:=cost[j]; cost[j]:=t; t:=from[i]; from[i]:=from[j]; from[j]:=t; inc(i); dec(j); end; end; if j>l then qsort(l, j); if i<r then qsort(i, t); end; function can(x: longint): boolean; var i, j: longint; len1, len2: extended; sum: extended; co: extended; tt: extended; temp: Array[1..maxn] of extended; begin for i:=1 to tot do begin sum:=0; len1:=0; len2:=0; for j:=1 to m do begin sum:=sum+g[x, j]*g[i, j]; len1:=len1+g[x, j]*g[x, j]; len2:=len2+g[kk[i], j]*g[kk[i], j]; end; len1:=sqrt(len1); len2:=sqrt(len2); if abs(len1)<=zero then exit(false); co:=sum/len1/len2; tt:=len1*co; for j:=1 to m do temp[j]:=g[kk[i], j]*tt/len2; for j:=1 to m do g[x, j]:=g[x, j]-temp[j]; end; for j:=1 to m do if abs(g[x, j])>zero then exit(true); exit(false); end; procedure solve; var i: longint; begin qsort(1, n); tot:=1; num[1]:=from[1]; ans:=ans+cost[1]; kk[1]:=1; for i:=2 to n do if can(i) then begin inc(tot); kk[tot]:=i; num[tot]:=from[i]; ans:=ans+cost[i]; if tot=m then exit; end; end; procedure print; var i, j: longint; t: longint; begin if tot<m then writeln(0) else begin writeln(ans); for i:=1 to m do for j:=i+1 to m do if num[i]>num[j] then begin t:=num[i]; num[i]:=num[j]; num[j]:=t; end; for i:=1 to m do writeln(num[i]); end; end; begin init; solve; print; end. Lukyanov Alexandr [Yaroslavl SU] WA4 [3] // Задача 1041. Никифор 6 авг 2007 19:50 Who can take test me? i use sort(price, position)+gaus. try test: 11 10 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Out: 10 1 2 3 4 5 6 7 8 9 10 Edited by author 17.07.2010 23:05 Is it has this tase case? It's pretty hard to solve T_T test: 3 2 0 1 2 0 1 0 10 10 10 answer: 20 1 2 lexicographic means input order, not coordinates. for (int z = i+1; z < n; z++) { __int64 r = (((__int64)a[j][z])*a[d][i] - ((__int64)a[j][i])*a[d][z]); a[j][z] = mod(r); } a[j][i] = 0; for (int z = i; z < n; z++) { __int64 r = (((__int64)a[j][z])*a[d][i] - ((__int64)a[j][i])*a[d][z]); a[j][z] = mod(r); } first get AC, but second WA9 by the way, mod(0) == 0 const int P = (1<<30)-17; int mod(__int64 x) { int r = x % P; if (r < 0) r += P; return r; } Edited by author 05.05.2007 18:49 n = 2 i = d = 0 j = 1 a: 1 1 1 1 First result: 1 1 0 0 Second result: 1 1 0 1 Who have the test case? MAIL ME: sunzheng.david@163.com I've got AC. The tests are very difficult. REMEMBER: The epsilon should be very small!!! I made eps=1e-10 and got ACed I was beaten by newtesrmakers having gauss solution in __int64- overflow. Rewrited the same program in my long arithm. 300- digits- MLE 200-digits-not enough. 270- digits- AC. Some new tests and the problem will become unsolvable. You can use gauss over prime modular ring instead of long arithmetics Just select lucky module =) Thanks Godz my ID at Valladolid is prime! :D Great idea) I used ortogonalization over prime module) Thanks. My solution (Gauss too) has O(m*n^2) complexity, but it seems many people make it better. If anyone can explain fast method, it would be great (klukva2[at]mail[dot]ru). Thanks! Edited by author 15.02.2007 01:08 Why is greedy algo get's WA on test 9? Because better use integer- Gauss solution without heuristics. My algorithm uses Gauss algo as a part, but also gets WA on test 9. I think this problem is similar to minimal spanning tree problem, which is solved by Kruskal's algo, but here we should use Gauss to check linear independence. So, greedy (in fact) algo could get AC. May be you know counter-example? I'm using Gauss method with precision about 50 digits (BigDecimal) and still get WA? Can you give me some test, where it doesn't works You should make Gauss under ring of integers when we make matrix diagonal but don,t make ones on it I did exactly what you mean but i think, that there should be an overflow when you several times will use Gauss algo. Now i have WA9, can you give me any tricky test? Silly mistake, AC now. Edited by author 22.01.2007 18:54 I suppose that test #9 isn't correct, because we can use Kruskal's algo if we'll consider weights of vectors as wi - 1 / ((INF) ^ ni), where wi is weight of i-th vector ans ni is its number. It's easy to see that in this case Kruskal's algo gives us an optimal solution. 2Admins: Can you please check the test? i get WA#9 too. i don't know what is wrong is my programme. I am also get wa on Test #9,can anybody give me any hints? thx Edited by author 22.03.2007 13:52 I've solved this problem and got WA after rejudge. And I have one question: does the word "lexicographic" mean it's usual meaning for sets (e.g. set A lexicographically smaller than set B if there exists some i that i-th element is in A, but no in B, and for all j < i j-th element is both in A and B). Or it means something else? Yes, "lexicographic" has its usual meaning. in 12 3 .... 12 linearly independent vectors 1 1 ... 1 1 out 3 1 10 11 Yes? Firstly, there are no linearly independent vectors 12 in three-dimensinal. :-) Secondly, I think right answer is 3 1 2 3 New tricky tests were added and TL was decreased to 1 sec. 233 authors lost AC. You may add as many new tests as you want, but you must not change the TL. When I solved the problem 4 years ago my program was fast enough and now it is TLE. How could I imagine someone will decide to decrease the TL? Why should I solve the problem which had been already solved? Why then did you decrease the TL for problem 1421 once upon a time? :) Probably you wanted only more optimized solutions (or solutions with better complexity) to get AC? Aren't you guys all moderators ? Why there is a misunderstanding then ? As I know you're all from the same university right ? or am I wrong ? Nevermind !!! You want to us to fight and argue in persons and not on forums? Unfortunately, that's impossible (we live in different cities :)). Oh, I'm frozen in terror. :) I agree with admins. If TLE changed then they have created modern approach during problem invistigation or new times- new cars. computers become much more faster since 2000 year, so TL may be decreased in many problems from first volume TL for this problem was 5 seconds originally. It was decreased to 2 seconds in 2003 since judging system moved to faster PC. Finally, TL was decreased to 1 second because PC was upgraded again in 2005. I argee, we should change TL in 2005, but it's better late than never. To Dmitry: Old TL was 2 sec, but your solution works more then 2 sec on 15 test and has WA on the tests > 15. So your solution was incorrect, but tests were weak. Good luck in writing new solution! ;) Any hint about the "tricky tests" ? I think I need help, thx Omg.. My solution had silly mistake in Gauss method ('*' instead of '/'). And this solution got AC before rejudging. i'm shocked... that's OK. my original solution use "i" instead of "buy[i]" and got AC... I won't find this error if there's no rejudging. I am not a mathematician, but I love such tasks. Study mathematics and it will be solved easily :) Great thanks to author. How to do this problem?If anybody knows,please email xujand000@rambler.ru I've done lots of problems.if anyone help me,in return for it,I'll help him too i kind of don't have a good ideea for solving this problem What's wrong with my program? Could any one give me something hint or testdata? Thanks. [code was deleted] Edited by moderator 22.04.2004 00:51 The problem is that if vector x is linear independent with vectors a and b separately, that doesnt mean that x is linear independent with vectors a, b. Example: a = 1 5 3 b = 3 1 2 x = 4 6 5 = a+b (it is linear dependent with vectors a and b) > [code was deleted] > Edited by moderator 22.04.2004 00:52 subj. Vectors x1,... xn are linery dependent iff there exist numbers a1,...an such that a1^2 + ... + an^2 ! = 0 and a1*x1+a2*x2 .... + an*xn = 0 Vectors are independent otherwise. as your explanation 0 0 3 is a linery independed vector,isn't it? Can I consider it like this: Vectors x1,... xn are linery dependent iff for any two vectors (xi,xj) in {x1,x2...xn}, there doesn't exist a real number K that x[i,l]*K=x[j,l] (l=1,2...n). Please help me. Thanks very much! x1=(1;0;0) x2=(0;1;1) x3=(1;1;1) Vectors v1,v2,...,vn are linearly independent iff for any vi, you CAN'T find a set of real numbers (a1,a2,...,a(i-1),a(i+1),...,an) such that vi=a1*v1+a2*v2+...+a(i-1)*v(i-1)+a(i+1)*v(i+1)+...+an*vn. That means for any n-dimensional vector v, you CAN find a set of real numbers (a1,a2...an) such that v=a1*v1+a2*v2+...+an*vn. Thanks. 71222119 mailto : trungduck@yahoo.com > Thanks. > 71222119 > mailto : trungduck@yahoo.com ///////////////////////// (0,0,0) will never be independent to any vector |
|