Common BoardI cannot understand why the answer is win 5 and lose 1.I think it should be win 3 and lose 3. Sample 1: we count turns of both players. Sample 2: the first player can't win and he wants to minimize the number of turns. So he makes suicide. here is my c++ code: #include <iostream.h> int main() { int n,i,j,x[501],z[501],aux,max,V[501],L[501],k,poz; cin>>n; for(i=1;i<=501;i++) z[i]=i; for(i=1;i<=n;i++) cin>>x[i]>>V[i]; if(n>1) { for(i=1;i<=n-1;i++) for(j=i+1;j<=n;j++) if(x[i]<x[j]) { aux=x[i]; x[i]=x[j]; x[j]=aux; aux=V[i]; V[i]=V[j]; V[j]=aux; aux=z[i]; z[i]=z[j]; z[j]=aux; } } L[n]=1; for (k=n-1;k>=1;k--) { max=0; for (i=k+1;i<=n;i++) if ((V[i]>V[k])&&(L[i]>max)) max=L[i]; L[k]=max+1; } max=L[1]; poz=1; for (k=1;k<=n;k++) if (L[k]>max) { max=L[k]; poz=k; } cout<<max<<endl; cout<<z[poz]<<" "; for (i=poz+1;i<=n;i++) if ((V[i]>V[poz])&&(L[i]==max-1)) { cout<<z[i]<<" "; max--; } return 0; } I failed in #8 as well... Look at this: We assume, that one segment is inside another, if the two segments are different, the first one is fully contained in the second one, and their endpoints do not coincide. Pay attention to this: and their endpoints do not coincide. It means 3 4 and 4 4 coincide too! Here is my brutforce: #include <stdio.h> #include <iostream.h> #include <math.h> //typedef enum {true,false} bool; bool z[20]; long int a[20]; long int min,v1,v2,k,n,j,l,i; void incr() { int in; for (in = 0; in< 20 ; in++ ) { if (z[in]==false){z[in]=true;break;} else z[in]=false; return; } } int main(){ for (l=0;l<20;l++) z[l]=1; cin>>n; // long int i; for (i=0;i<n;i++) cin>>a[i]; min=100000; for (i=0;i<=1048575;i++) { incr(); v1=0;v2=0; for (j=0;j<20;j++) { if (z[j]) v1=v1+a[j]; else v2=v2+a[j]; if (fabs((double)(v1-v2))<min) min=fabs((double)(v1-v2));
} } cout<<(long int)min<<endl; return 0; } Your brute-force) function void incr() is wrong. try test: 5 3 2000 4 5 6 and this with other order: 5 2000 3 4 5 6 my brute-function is: int minn = 2000000000; void solve(int first, int h1) { ___if(first == n && minn > abs(sum - h1 - h1) ) ______minn = abs(sum - h1 - h1); ___for(int i = first; i < n; i++) ______solve( i + 1, h1 + a[i] ); } Good Luck!;) Edited by author 10.07.2008 12:55 I think just not use double. I think just not use double. Or change your code: cout << (long int)(min + 1e-6) << endl; You should output empty string. Thx in advance! first player loses <- answer. It means that you have problem with second variant. use this simple test(it helped me): 3 3 3 2 2 1 first player loses 1700, 1800, 1900 are not leap years; year Y is leap if Y mod 4 = 0 if Y mod 400 = 0 but if Y mod 100 = 0 and Y mod 400 <> 0 then the year is not leap yeah thx i know those years are not leap ones. i was just a little confused with the january 1st 1600. my solution got AC thx anyway In the Julian calendar every year that is divisible by 4 is leap. in Gregorian if year is century must be divisible by 400 to be leap. it is so because in every 400 years by julian 3 exess days(to be more certain 1 in 128 years). we began to use gregorian calendar after 1900 year so you see every year before 1918 if year is divisible by 4 then it is leap. Who can help me? Why I got WA#6 This is my code # include <iostream> using namespace std; int main () { int n,i,j,k; int x[10002],y[10002],h[10002]; cin>>n; for(i=1;i<=n;i++) { cin>>x[i]>>y[i]; h[i]=i; } for(i=1;i<n;i++) for(j=i+1;j<=n;j++) { if((x[j]<x[i]) || (x[j]==x[i] && y[j]>y[i])) { k=x[i];x[i]=x[j];x[j]=k; k=y[i];y[i]=y[j];y[j]=k; k=h[i];h[i]=h[j];h[j]=k; } } for(i=1;i<=(n/2)+1;i+=2) cout<<h[i]<<" "<<h[i+1]<<endl; return 0; } problem in output if you use for(...;i+=2) you have to use for(...;i<=n;...) //like this for(i=1;i<=n;i+=2) cout<<h[i]<<" "<<h[i+1]<<endl; using System; using System.Collections.Generic; using System.Text; using System.IO; namespace Timus1081 { class Program { static void Main(string[] args) { new Program().Run(Console.In, Console.Out); //new Program().Run(new StreamReader(@"d:\a.txt"), Console.Out); //Console.ReadLine(); } private void Run(System.IO.TextReader textReader, System.IO.TextWriter textWriter) { string[] ss = textReader.ReadToEnd().Split(); //string ss = input.Split('\n'); List<double> bs = new List<double>(); for (int i = 0; i < ss.Length; i++) { if (ss[i].Trim().Length > 0) { //string[] s1 = ss[i].Trim().Split(' '); //for (int j = 0; j < s1.Length; j++) { try { bs.Add(Math.Sqrt(Double.Parse(ss[i]))); } catch (Exception ex) { } } } }
for (int i = bs.Count - 1; i >= 0; i--) textWriter.WriteLine(bs[i].ToString("F4")); } } } The method is something like DP + greedy... yeah! 0.078s 2406 KB Is this greedy right? : 1. Make Tanya a root. 2. Every employee call to his children in descending order of c[i], where c[i] is the number of descendants of the ith vertex. I got WA on test 10. Edited by author 26.10.2006 17:17 Your idea about making Tanya a root is very good. I've used it and got AC. (Thank you! :-)) But second point of your idea is definitely wrong. Analyse the following test and you'll get your AC: 14 2 9 0 3 4 0 5 6 0 7 8 0 0 0 0 0 10 0 11 0 12 0 13 0 14 0 0 1 Answer 6, My Algo give. I use Greedy Heap + BFS. WA10. First idea - Tanya Root, second Idea - when we count i- root time we use best times of his sons in the descending order. I think it correct but mistake&! /....bigint class...//// .................... bigint a,b,c,temp; a = 2; b = 3; c = a*b; if(n == 1) { cout << '2'; return 0; } cout << "2\n3\n"; for(int i = 3; i <= n; i++) { temp = a*b; c = temp + 1; cout << c << endl; a = c; b = temp; } ................................ //////////////////////////////// ubig ubig :: operator * (ubig p) { if (min (n, p.n) < 100) return simple_mul (p); else return karatsuba_mul (p); } ubig ubig :: simple_mul (ubig p) { int i, j; ubig s; for (i = 0; i < n; ++ i) { ubig row; for (j = 0; j < a[i]; ++ j) row = row + p; row = row << i; s = s + row; } while (s.a.size () > 1 && s.a.back () == 0) s.a.pop_back (); s.n = s.a.size (); return s; } ubig ubig :: karatsuba_mul (ubig p) { int k = max (n, p.n) / 2; ubig a = (*this).last (k); ubig b = (*this) >> k; ubig c = p.last (k); ubig d = p >> k;
ubig ac = a * c; ubig bd = b * d; ubig abcd = (a + b) * (c + d);
ubig res = ((abcd - ac - bd) << k) + (bd << 2 * k) + ac; return res; } I get TL1. I dont understand :-(. My wrong is big constant in simple mul. Now I get AC! :-) Edited by author 25.06.2008 12:19 Well,I find an error in my code. After fix it I get AC. I suspect it is just a large testdate. My prog that easily gets TLE on my tests got AC on timus. Bad. New tests were sent on your mail... It seems we must output the shortest way of changing,but in the problem says: If there are several solutions, you can output any one. isn't it wrong? sorry for my english. "Help the new driver to find a SHORTEST sequence of changes that will enable him to get a plate with the number of his route" В стРоках с нечетным номером ходы белых, в строках с четным номером – черных. Edited by author 08.07.2008 03:39 May be it's posiible to add a filter for search? Such as a county of coder. Very interesting to watch coders from one country together. Vladimir Yakovlev (USU) Maybe... 8 Jul 2008 03:34 WA6. What's wrong? Give some test's. In my solution I used Deixtra algo. Why Dijkstra? Simple dfs for topsort and then dp. I think this problem could not be solved with dijkstra. Simple dfs for topsort and then dp or simple BFS :) i used FLOYD's algo and have TLE15. i used Djkstra's algo and i have WA10.. pls, can you give me some tests or what's bug in my program? {$APPTYPE CONSOLE} uses SysUtils; var a:array [1..1000,1..1000] of longint; mas:array [1..1000] of longint; used:array [1..1000] of boolean; i,n,m,t,f:longint; procedure djkstra(st:longint); var cur,i:longint; begin fillchar(mas,sizeof(mas),255); fillchar(used,sizeof(used),0); cur:=st; mas[cur]:=0; repeat used[cur]:=true; for i:=1 to n do if (a[cur,i]<>0) and (mas[i]<mas[cur]+a[cur,i]) then mas[i]:=mas[cur]+a[cur,i]; cur:=0; for i:=1 to n do if not used[i] and (mas[i]<>-1)and ((cur=0)or (mas[cur]>mas[i])) then cur:=i; until cur=0; end; begin read(n,m); for i:=1 to m do begin read(t,f); read(a[t,f]); end; read(t,f); djkstra(t); if mas[f]<>-1 then write(mas[f]) else write('No solution'); halt(0); end. and what to do if there is cycle? Edited by author 16.04.2008 21:52 Edited by author 16.04.2008 21:56 Edited by author 16.04.2008 22:55 i've changed djkstra like this <code>procedure djkstra(x:longint); var cur,i:longint; begin fillchar(v,sizeof(v),-1); fillchar(used,sizeof(used),0); v[x]:=0; cur:=x; repeat used[cur]:=true; for i:=1 to n do if (a[cur,i]<>0) and ((v[i]=-1)or (v[i]<v[cur]+a[cur,i])) then begin v[i]:=v[cur]+a[cur,i]; used[i]:=false; end; cur:=0; for i:=1 to n do if not used[i] and (v[i]<>-1)and((cur=0)or (v[cur]<v[i])) then cur:=i; until cur =0; end;</code> and it's tle#15((( does the problem require only finding average that i have done still WA1. can please someone give me some test cases?? Edited by author 08.07.2008 11:04 Edited by author 08.07.2008 11:05 |
|