Общий форум u and v,which is the father node? There's no father node. You can do topsort and choose it yourself. Um... You can't topsort a given tree, because it's an undirected graph. import math def getList(maxNumber): primeLst = [] for num in range(2,15000): if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)): primeLst.append(num) if len(primeLst)==maxNumber: return primeLst lst = [] for x in range(int(input())): lst.append(int(input())) primeNumbers = getList(max(lst)) for x in lst: print(primeNumbers[x-1]) I don't know why my code is error in testcase 2 Can anybody help me out of here ? 'qwerSOMETEXTrewq' isn`t 19 test. I got WA10 and my program was printing TEXT as my if condition was wrong at one place. I believe this is the test case for 10 as i got AC after fixing this. Thanks for that :) Hey, i seemed to have failed at Test 10 > <, with the input as "qwerSOMETEXTrewq", the output i get is qwer, which is right isn't it ? it should be "ETE",because "qwer" and "rewq" are separated I can't understand what i do not correctly. Help me, please. Бутерброд изначально довольно близок к Земле what is 5th test ? Edited by author 07.02.2010 03:04 I also got WA on the 5th test...Who can help me... man-bear-pig 10/20 170/680 3/12 Same answer as for man-bear-pig 1/2 1/4 1/4 Great thanks for this helpful test. Edited by author 02.01.2018 07:25 In Python 3.0: N = int(input()) M = int(input()) result = N*(M+1) print(result) #It produces runtime error In C: #include <stdio.h> int main(void) { short int n, k; scanf("%4hd%4hd", &n, &k); printf("%hd\n", n * (k+1)); return 0; } # It produces wrong answer for test N7 SHORT_MAX, probably, is 32767. Replace short with long or long long. Edited by author 26.11.2013 10:16 scanf("%4hd%4hd", &n, &k); /// you dont need this scanf("%i %i", &n, &k); // like this Can somebody give me this test ?! Please ! I guess all devices are unique. I've passed test 10 when i've passed this:
q a 1 q b 2 q c 3 q d 4 q e 5 q f 6 so what's the output for that test ??? If you're getting WA #10, better try this test where prices aren't already sorted: a 1 6 b 2 4 c 3 5 d 4 3 e 5 1 f 6 2 Correct answer is "5", got AC after this test passed. input#1: 3 a\b\c a\b\c b output#1: a _b __c b input#2: 9 a a\b a\b\c a\b\c a\b\c\d b\f b\f\e b\f\d b\e output#2: a _b __c ___d b _e _f __d __e input#3: 3 a a\b\c\d\e\f a\b\r\t\p output#3: a _b __c ___d ____e _____f __r ___t ____p input#4: 4 a\b b\a a\c\d a\c\e output#4: a _b _c __d __e b _a input#5: 4 a a\b\c\d\e b\f\e\t a\b\p output#5: a _b __c ___d ____e __p b _f __e ___t Edited by author 01.10.2007 23:38 Edited by author 01.10.2007 23:42 Edited by author 01.10.2007 23:46 Yeah, your tests are absolutelly correct... caz my AC solution has the same outputs.... try this test 1 ab\c\d\e my be it'll help... 4 a\baba a\bab a\babab a\bab\ba a bab ba baba babab MR.qo`y yaxshiroq test yoz thank you very much for the tests the output part states that: "The only line of the output must contain the minimal sum followed by the optimal route (one of possible routes with minimal sum)", but I got wrong answer! why? my output for sample input is: 5 e2 e1 d1 d2 e2 e3 I think it's also right. um I think so Yes Right! my AC program outputs "5 e2 e1 d1 d2 e2 e" for sample test :) 5 e2 e1 d1 d2 d3 e3 is another correct answer for the sample input. double res = ...; cout << setprecision(6) << fixed << res; program idiots; var n,i,h:integer; a: array [1..1000] of integer; begin readln(n); for i:=1 to n do read(a[i]); h:=1; for i:=1 to n do begin if a[i]=a[i+1] then h:=h+1; if a[i]<> a[i+1] then write(h,' ',a[i],' '); if a[i]<> a[i+1] then h:=1; end; end. but, I don't understood! for i:=1 to n do begin if a[i]=a[i+1] then h:=h+1; if a[i]<> a[i+1] then write(h,' ',a[i],' '); if a[i]<> a[i+1] then h:=1; end; You must get error in this stroke if a[i]=a[i+1] then h:=h+1; because your for loop is going untill n this must give Indexout of range exception isn't? Nope, its neither c++ nor Java. It`s Pascal. Here you can do a lot of forbidden things without getting runtime error or Exception How to use dynamic programming to solve this problem? I used fibonacci. As far as I understand, this problem is about combinations and not about fibonacci. If there was only the first condition, then for any N we have only 2 possibilities to create the flag. That is, f(1) = 2, f(2) = 2, f(3) = 2, f(4) = 2, ..., f(N) = 2; This is true, because the choice of the first stripe determines the rest of the flag automatically. If you choose the first stripe to be white-colored then you are destined to choose the red stripe to be the second one. And vice versa. Don't make my words a HOLY WISDOM - think about it till you can feel it yourself. Don't read next, until you fully and completely get it. The second condition is here to complicate your life. It doesn't do anything to our function f(x) if x equals to 1 or 2. That is, f(1) and f(2) are still equal to 2. (By the way, I've just noticed that I've pulled the function from under the pillow. Well, in my mind this function returns the amount of different flags that can be created if you need to make it from x stripes. Ok, now we're moving on...) But it allows us to INSERT the blue stripe between the two: white and red stripes. This concept of INSERTION is really the key here. Think about it. If you were supposed to gain anything intellectually from solving this task at all, I bet, it was this very concept. If we have some sequence of 2-colored flag: WRWRWRWRWRWRWR (White and Red), and this sequence contains all the N stripes that we need, then we really don't have any place to INSERT our blue stipe. You think, ok, that's fair, and remove one of the stipes (e.g. the left-most). Now you have the place for your blue stripe ... and you can insert it in many ways: wBrwrwrwrwr or wrBwrwrwrwr or wrwBrwrwrwr ... well, you get the point :) This way, by removing one of the stripes you have created X COMBINATIONS. This word is also important, that is why it is all upper-case :) If you remove ONE MORE stripe (think about removing as n - 1 or better n--), you now have to INSERT 2 blue stripes somewhere in the sequence wrwrwrwrwrwr... E.g. wBrBwrwrwrwrwrwr, or wBrwrwrwrwrwrwBr. Now there should be more COMBINATIONS than in the previous case (figure out yourself, how many :) ). The last point I want to make is that you have to know your limits. That is, you have to understand when to stop removing stipes from the flag and stop INSERTING blue stripes in it. When you get to this point (keeping in mind all the previous points), you will figure this out by yourself easily... Edited by author 20.08.2015 02:16 Edited by author 20.08.2015 02:18 Edited by author 20.08.2015 02:23 Edited by author 20.08.2015 02:23 Edited by author 20.08.2015 02:25 Edited by author 20.08.2015 02:26 Edited by author 20.08.2015 02:27 Edited by author 20.08.2015 02:27 Edited by author 15.10.2016 20:15 Edited by author 15.10.2016 20:16 Edited by author 15.10.2016 20:20 Edited by author 15.10.2016 20:21 Edited by author 15.10.2016 20:21 This is really extremely helpful in reasoning about the problem, thank you Егору зачет! За крутое решение и за знание англ) Please, give me some tests! #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int a,k=-1,fact=1,term=1,i=0; char c; scanf("%d",&a); getchar(); do{ c=getchar(); k++; } while(c==33); if(k>a) fact=-1; while(fact>0){ term*=fact; fact=(a-i*k); i++; }
if(k<=a) printf("%d",term); system("PAUSE"); return 0; } Edited by author 01.07.2012 19:03 #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int a,k=-1,fact=1,term=1,i=0; char c; scanf("%d",&a); getchar(); do{ c=getchar(); k++; } while(c==33); if(k>a) fact=-1; while(fact>0){ term*=fact; fact=(a-i*k); i++; } if(k<=a) printf("%d",term); system("PAUSE"); return 0; } I always get WA on test 4,who can give me the testdata of test4.Help me!Thank you. Triviality(1)=0 Thank's for help! You're completely right! AC now! Thanks.I got AC now. Of course I have same bugs. AC now I also have the same mistake.thanx a lot. Thank you very much!!!!!!! It is a very good advice! Thank you for your advice. I've gotten AC now.I wrote "1" if i=1. а как выглядит второе число? ведь тест - 2 числа, через пробел. Can you tell how look test4? the first is one, and the second is ..? Triviality(1) = 1 Triviality(1)=0 Edited by author 17.09.2015 23:28 Edited by author 17.09.2015 23:28I keep getting WA2, but none of the threads posted here seem to help me: every example i found worked on my program, and i just can't see what's wrong with it. Can someone please tell me if they see anything that doesn't work within my program? Thank you in advance. #define DM 8101 #define DN 901 #include <iostream> #include <set> #include <queue> using namespace std; int n, v, vp, s, sp, cf[DN][DM], dp[DN][DM]; multiset <int> ord;//ordering the elements queue <int> q;//rebuild void formare(int nrc, int car, int sum, int ptr)//no of digits, digit, sum, sumof squares { if (nrc > 100 || (cf[sum][ptr] && cf[sum][ptr] <= nrc)) return; cf[sum][ptr] = nrc; dp[sum][ptr] = car; for (int i = 9; i >= 1; --i) formare(nrc + 1, i, sum + i, ptr + i*i); } void realc(int s, int sp) { if (!s || !sp || !dp[s][sp]) return; q.push(dp[s][sp]); v+=dp[s][sp]; vp+=dp[s][sp]*dp[s][sp]; realc(s - dp[s][sp], sp - dp[s][sp]*dp[s][sp]); } int main() { cin >> n; for (int i = 9; i >= 1; --i) formare(1, i, i, i*i); cf[0][0] = 1; dp[0][0] = 0; while (n--) { cin >> s >> sp; if (s > 900 || sp > 8100) cout << "No solution\n"; else if (s == 0 && sp == 0) cout << "0\n"; else { realc(s, sp); if (q.size() <= 100) { while (!q.empty()) { if (v == s && vp == sp) ord.insert(q.front()); q.pop(); } for (auto i:ord) cout << i; ord.clear(); if (v != s || vp != sp) cout << "No solution"; cout << '\n'; } else { cout << "No solution\n"; while (!q.empty()) q.pop(); } } v = vp = 0; } return 0; } Nevermind, apparently I was calculating the number the wrong way, I found the mistake. What is the test 19? Help please! |
|