Common BoardLet's consider some cases: 1) the first part of the answer is a min number of goals needed to have a chance to advance next round. That means that the second team will score 0 goals in second game, and how many goals needed to be scored to complete the condition?? 2) the second part - max number of goals to be scored in such case, that the opposite team still will have a change to win. That means we must suppose second team to have scored 30 goals in second round. in each case we must calculate number of our scores to make the summarized scores equal for 2 rounds. But then we check the condition if the numbers of goals scored on the away fields of each team are equal - then the answer is OK, every team has a chance to advance. In first case we must take ++value of number if quantity of scored goals on away team is less (that means no chance), in second - value-- of number if quantity of scored goals on away team is greater(cause that leaves no chance for opposite team to win) is that enough to solve?? why wa2??? program ural; var n,m,i,k,j,r,p:byte; a:array[1..100]of byte; b:array[1..100,1..100]of byte; d:array[1..100]of integer; z,t:integer; label 1; begin readln(n,m); for i:=1 to m do begin read(k); for j:=1 to k do read(a[j]); for j:=1 to k do for r:=1 to k do if j<>r then begin b[a[j],a[r]]:=1; b[a[r],a[j]]:=1; end; end; readln(m); for i:=1 to m do begin readln(d[i],a[i],p); if p=1 then d[i]:=101 else d[i]:=d[i] div 4; end; for i:=1 to n do for j:=1 to n-1 do if i<>j then for r:=j+1 to n do if r<>i then if(b[j,i]>0)and(b[i,r]>0)then begin t:=b[j,i]+b[i,r]; if(b[j,r]=0)or(t<b[j,r])then begin b[j,r]:=t; b[r,j]:=t; end; end; z:=255; for i:=1 to n do begin t:=0; for j:=1 to m do if a[j]<>i then if(b[a[j],i]>0)and(b[a[j],i]<=d[j])then begin if d[i]<>101 then inc(t,b[a[j],i]); end else goto 1; if t<z then begin k:=i; z:=t; end; 1: end; if z=255 then writeln(0) else writeln(k,' ',z*4); end. I can only say, that answer to the test 2 is 4 12. Program like this: begin write('4 12'); end. gives WA#4. I don't know, what is your WA2, but my WA2 is people who spend his money, when they have month ticket. Try this: 4 3 2 1 2 2 2 3 2 3 4 3 27 1 1 15 4 0 45 4 0 Answer is 4 0. I hope, it helps. Sorry for my bad english. You are right Thnx a lot Edited by author 02.11.2010 23:03 The Machinegunners played away game, scored 0 goals, and conceded 0 goals. The Machinegunners played away game, scored 15 goals, and conceded 15 goals. ans 0 30 0 30 Edited by author 02.11.2010 20:39 Please, write somebody full answer for N = 994009. My AC program outputs: 88733 78763 72781 70787 66799 60817 58823 52841 46859 42871 40877 36889 30907 28913 22931 18943 16949 12961 10967 48853 24925 26919 31904 997 LCM = 1438976816627817242848511727497751141600 can anybody give me another sample?what is the mean of "Output limit exceeded"? This test: 900660121 My solution printed 30011 30011 30011 510187 570209 690253 870319 930341 1110407 1230451 1290473 1410517 1470539 1590583 1770649 1830671 2010737 2130781 2190803 2370869 2430891 2490913 2670979 2911067 3031111 3091133 3211177 3271199 3391243 3631331 3751375 3811397 3841408 3931441 4111507 4171529 4471639 4531661 4711727 4891793 5011837 5071859 5191903 5371969 5431991 5732101 5792123 5912167 5972189 6332321 6692453 6812497 6872519 6992563 7172629 7232651 7532761 7712827 7892893 8072959 8132981 8313047 8433091 8493113 8793223 9213377 9333421 9393443 9513487 9933641 10113707 10413817 10473839 10593883 10773949 11014037 11194103 11374169 11494213 11674279 11914367 12034411 12274499 12574609 12634631 12934741 12994763 13174829 13294873 13474939 13715027 13835071 13895093 14015137 14375269 14615357 14735401 14975489 15095533 15275599 15695753 16235951 16416017 16716127 16896193 17076259 But I think that first two 30011 is better to substitute for 60022. Or where am I "stuping"? =) Both answers are correct. How? In the first case we don't have additional multiplier 2 in LCM, but in the second case we do! In first case you have even number 3841408 So both answers will have the same lcm. OMG, thank you! But now I don't understand how my code works... =) BTW, it seems that your output is wrong. LCM = 1145572696929554701079627087188585278224797526867219882418294936208691318014731501909363309122622626756133318658525035985652955558442865786706238900113218934286831376065925560824507193167414120672919107758638356289823952045129094359452304000 but it is possible to get bigger lcm. В обоих случаях из примера бутерброд за время падения не совершает ни 1 полного оборота, соответственно он падает в обоих случаях маслом вниз. Скорость вращения - 1/4 оборота в секунду. Время падения 1 раз = 0,9. Количество оборотов 1 раз = 0,2258. Время падения 2 раз = 1,01. Количество оборотов 2 раз = 0,2524. В обоих случаях бутерброд НЕ совершает ни 1 полного оборота и должен упасть как и был, маслом вниз. Почему же ответы для 1 примера - "маслом вниз", а для 2 примера - "хлебом вниз"? во втором случае он совершает оборот за 1.005 с и 0,25 оборота в секунду т.е. за 1 секунду он повернется на 90 градусов и будет хлебом вниз Спасибо, разобрался =) Интересная задача. #include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> using namespace std; void recursive_print(){ double A; char ch; if ((ch = getchar()) != EOF){ cin >> A; recursive_print(); cout << endl << setiosflags(ios::showpoint | ios::fixed) << setprecision(4) << sqrt(A); } } int main(){ recursive_print(); } test: 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 3 White a1-a2 h8-h7 a2-a4 ans: Correct Correct Correct 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n,k,mh=0,otg=999; string s; vector<int>v; cin>>k; for(int i=1;i<=k;i++) { cin>>n; cin>>s; if(s=="hungry") { if(n>mh) mh=n; } else v.push_back(n); } if(v.size()) { for(int i=0;i<v.size();i++) { if(v[i]>mh&&v[i]<otg) otg=v[i]; } if(otg==999) cout<<"Inconsistent"<<endl; else cout<<otg<<endl; } else cout<<"10"<<endl; return 0; } Edited by author 02.11.2010 12:52 Edited by author 02.11.2010 12:52 Which method can be used in this problem? Really dynamic programming? Give me this test if you can please... :) O(N log N) is possible. O(N log N) is possible. Of course, but not in 0.062 s. :) In this problem the most time-consuming thing is output. So your 0.062 it is only fast output. PS: Btw, O(nlogn) - 0.046 sec ;) PS: Btw, O(nlogn) - 0.046 sec ;) Hmm... 0.046 also is not 0.062 :) But it is fact: my solution is so simple. More simple than Interval Tree? =) Anyway you've intersted me. So if you don't mind, please, send your solution to sk1@hotbox.ru I plan to create a site collecting articles, ebooks, problems, and so on about algorithms. I've also uploaded my (too small) solutions to Timus problems, containing 1521. If you have any resources and want to share, please take a minute. It benefits our problem-solving community! Here is the URL: Merry Christmas to all ! Regards, Minh Duc Edited by moderator 29.12.2006 09:26 How to speed it up? My O(N*logN*logN) solution takes ~0.7 sec. to get AC... Vedernikoff Sergey: I don't know what your algo is but mine has O(NlogN) like most of the others. I used Index tree (also known as Dynamic Order Statistics or as Burunduk said - Interval tree - this must be the same). I am interested in the O(N^3/2) solution. Could someone explain it here? Edited by author 15.01.2007 07:20 Let's exchange with our progs. My is O(N^3/2). Just 316Kb memory is needed for it. Send it on my e-mail or post your Kiril, my e-mail is cheater_no1@abv.bg Check your mail my email: onlyforme_@ok.kz My mail is hulakov@gmail.com Vedernikoff Sergey: I don't know what your algo is but mine has O(NlogN) like most of the others. Edited by author 15.01.2007 07:20 My solution has O(N*logN*LogN). Main idea - find k-th order statistics in array, where a[i]=1, if i-th soldier was in circle else a[i]=0 (use binary search and Fenwick tree). I don't know how to find k-th order statistics only by Fenwick by O(LgN) Edited by author 21.07.2010 18:09can anybody explain me n ^ 3/2 algo? I have solved it using Binary Search Tree #include <iostream> using namespace std; int main() { long int a, i=0, n, k1=0, k2=0; cin>>n; while( i < n ) { cin>>a; if( k1 < k2 ) k1 += a; else k2 += a; i++; } if( k1 >= k2 ) cout<<k1-k2<<endl; else cout<<k2-k1<<endl; return 0; } I need help because in the test 6 I have a crash and I do not understand why? And I'm sure that the algorithm to this problem is correct, Thanks.. What is the answer for this tests? The Machinegunners played away game, scored 1 goals, and conceded 2 goals. The Machinegunners played home game, scored 0 goals, and conceded 1 goals. The Machinegunners played away game, scored 1 goals, and conceded 1 goals. Correct anwers are: 1 30 1 30 0 30 Для второго варианта почему мин = 1? При таком исходе получится, что нужно проводить жребий. У каждой команды будет по 1 очку, причем по одному на чужом поле... Can they look though each other? "and the points they see are strictly inside the planet" => So the answer is "there is no such testcases" What is the answer for: The Machinegunners played away game, scored 30 goals, and conceded 0 goals. ? If they loose 0 : 30, they advance to the next round anyway, am I right? I was wrong and answer is 0 0 I have Wa #8 many times, I don't know what's wrong!!! Can anybody check my code or give me a hint? There is my code, I still have WA #8: #include <iostream> #include <cstdio> #include <cmath> using namespace std; int main() { double x1, x2, y1, y2, Right = -1e9, Left = 1e9, Up = -1e9, Down = 1e9; double x3, y3, x0, y0, n, m; int N = 0; while (cin >> x1 >> y1 >> x2 >> y2) { N ++; x0 = (x1 + x2) / 2.0; y0 = (y1 + y2) / 2.0; n = x1 - x0; m = y1 - y0; x3 = m + x0; y3 = -n + y0; Left = min(Left, min(x1, min(x2, x3))); Right = max(Right, max(x1, max(x2, x3))); Up = max(Up, max(y1, max(y2, y3))); Down = min(Down, min(y1, min(y2, y3))); } if (N == 0) printf("%0.4f %0.4f", 0, 0); else printf("%0.4f %0.4f", fabs(Right - Left), fabs(Up - Down)); return 0; } Try empty input. If you use Java - don't use Scanner. His hasNextDouble()/hasNextInt(), nextDouble()/nextInt() are too slow for large input. Use StreamTokenizer. Edited by author 31.10.2010 23:46 can u give me some tests.. plz Maybe you forget that L and h in cm. But g = 9.81 in m/s^2. You must use same metrics. 400 10 15 butter 1 895 100 bread 1 894 100 butter You should add this to get AC: if (ans < 0) ans = 0; if (ans > 30) ans = 30; |
|