Common Boardhow can i see my current accepted submission rank???? http://acm.timus.ru/rating.aspx?space=1&num=1106Non language-specific rating; from there, you can select a language for a language-specific rating. However, it doesn't appear you have this task submitted, at least not from the account you've posted this message. Edited by author 10.11.2016 09:24 #include<iostream> using namespace std; int n,i,k,t,j; string a[10000],b[10000],c[10000],d[10000]; int main(){ a[1]="Alice"; a[4]="Phil"; a[7]="Phoebus"; a[2]="Ariel"; a[5]="Peter"; a[8]="Ralph"; a[3]="Aurora"; a[6]="Olaf"; a[9]="Robin";
b[1]="Bambi"; b[4]="Mulan"; b[7]="Silver"; b[2]="Belle"; b[5]="Mowgli"; b[8]="Simba"; b[3]="Bolt"; b[6]="Mickey"; b[9]="Stitch";
c[1]="Dumbo"; c[4]="Kuzko"; c[7]="Tarzan"; c[2]="Genie"; c[5]="Kida"; c[8]="Tiana"; c[3]="Jiminy"; c[6]="Kenai"; c[9]="Winnie"; cin>>n; for(i=1; i<=n; i++) cin>>d[i]; for(i=1; i<=n; i++) { for(j=1; j<=9; j++) if(d[i]==a[j]){ if(t==0) k+=0; if(t==1) k+=1; if(t==2) k+=1; if(t==3) k+=2; t=1; break; } for(j=1; j<=9; j++) if(d[i]==b[j]){ if(t==0) k+=0; if(t==1) k+=1; if(t==2) k+=1; if(t==3) k+=1; t=2; break; } for(j=1; j<=9; j++) if(d[i]==c[j]) { if(t==0) k+=0; if(t==1) k+=2; if(t==2) k+=1; if(t==3) k+=1; t=3; break; } } cout<<k; } what's wrong with this code: #include <iostream> #include <vector> #include <list> using namespace std; int ar[102][102],viz[102]; int n; list <int> a; int dfs(int s) { viz[s] = 1; for (int i=1;i<=n;i++) { if (ar[i][s] && !viz[i]) {dfs(i); }//a.push_back(i);} } return 0; } int main() { cin >> n; int z; for (int i=1;i<=n;) { cin >> z; if (z == 0) i++; else ar[i][z] = 1; } dfs(1); for (int i=1;i<=n;i++) if(!viz[i]) a.push_back(i); cout << a.size() << endl; for (int n : a) { cout << n << " "; } return 0; } maybe i didn't understand problem properly,some help? Here is my solution and used test cases. I don't understand why I always get WA. 8-( Test 1. 5 4 2 0 1 2: NO Test 2.5 4 2 0 1 5: YES Test 3. 5 4 2 0 3 5: YES Test 4. 5 4 2 0 3 4: YES Test 5. 5 5 2 0 3 4 5: YES Test 6. 5 5 2 0 2 4 5: YES Test 7. 5 6 2 1 2 4 5 0: NO Test 8. 5 4 1 2 2 3: YES Test 9. 5 5 1 2 3 4 3: YES Test 10. 5 5 1 1 0 3 4: NO Test 11. 5 3 0 0 1: NO Test 12. 5 3 0 1 1: NO Test 13. 5 3 1 2 2: YES Test 14. 5 3 1 1 2: YES Test 15. 5 3 4 4 5: NO Test 16. 5 3 3 4 4: YES Test 17. 5 3 4 5 5: NO Test 18. 5 3 3 4 5: YES Test 19. 2 2 1 1: YES Test 20. 2 2 2 2: NO Source code: [code deleted] Edited by moderator 13.02.2007 20:57 If the num of cards is lower than m i think that the asnwer should be NO 2.5 4 2 0 1 5 YES? Edited by author 19.01.2007 12:34 I'm not very good in C, and i don't undrstand your source) But my idea is very simple. Store in array number of repeats, increment a[0] and a[n] (because it's only one card with this numbers) and find in array sequence 2 1 1 .. 1 1 2 that's all) Edited by author 22.04.2009 22:45 Is test 9 right? i think so.i think that test#9 may be wrong.or i made mistake while reading the problem... tell the truth,i don't really understand the problem .. I don't understand Test 5. 5 5 2 0 3 4 5: YES Why? first 5 so take 5 or 6 second 5 so take 5 or 6 so take 5 and 6 ... last 5 so take 5 or 6 again, but 5 and 6 were taken, so NO help me, please for the 1st and the 2nd 5 means n and m without meaning the number which was took. here are test right Edited by author 31.12.2012 02:08 Edited by author 31.12.2012 02:08 Edited by author 31.12.2012 02:08 there are n * m possible sums. to find a solution, we can try to create such vectors such that all n * m sums are different. Suppose the 1st vector is 1 2 3 ... n Then the first element of next vector is taken to be n + 1(we require all unique). Now we need to find the next element while making all n*p sums different, where p is the size of the 2nd vector. n+1 1 2 3 ... n initially all sums(n+2 to 2n+1) are distinct. Now we need to add new element such that smallest possible new sum is greater than the previous sum i.e. if new element is p p+1>2n+1 or p >= 2n + 1 in general p+1>prev+n p>=prev+n what is wrong here? for (int i =0; i< 15;++i) { int p = primes[i]; if ( c % p == 0) { unsigned long long M = c / p; unsigned long long M_inv = inverse[i][ M % p ] ; unsigned long long h = M_inv * m[ i ]; // r = (r + h * M ) % c unsigned long long high_M = (M >> 32 ) & 0xFFFFFFFFULL; unsigned long long low_M = ( M & 0xFFFFFFFFULL); // h * M= h * (high_M * 2^32 + low_M) unsigned long long high_h = high_M * h; unsigned long long e = (high_h >> 32) & 0xFFFFFFFFULL; unsigned long long f = (high_h & 0xFFFFFFFFULL); // high_h = e*2^32 + f // h*M = h*(high_M*2^32 + low_M) = high_h * 2^32 + low_M * h = // = (e*2^32 + f)*2^32 + low_M * h = e*2^64 + f*2^32 + low_M * h e = (e << 48) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 1 ) % c; e = (e + (f << 32) ) % c; e = (e + low_M * h ) % c;
r = (r + e ) % c; } } You have to divide the participants into equal teams (rounded) For example, for "15 10" test - (1, 1, 1, 1, 1, 2, 2, 2, 2, 2) Good luck :) Well I don't understand this topic CLEARLY but I can trace some steps towards the final solution. Let's fix a possible team distribution i.e. number of teams Then, we need to find the best possible distribution to maximize the product For eg for 4 teams a1,a2,a3,a4 will be the team distribution a1+a2+a3+a4=n now we need to maximize the function f(a1,a2,a3,a4)=a1a2+a1a3+a1a4+a2a3+a2a4+a3a4 under the constraint a1+a2+a3+a4=n, which can be done using lagrangian multiplier. g(a1,a2,a3,a4)=f(a1,a2,a3,a4)+p(n-a1-a2-a3-a4) lets take derivative of the function g at a1 g'(a1) = a2+a3+a4 -p g'(a2) = a1+a3+a4 -p g'(a3) = a1+a2+a4 - p g'(a4) = a1+a2+a3 - p Equate all of them to zero a1+a2+a3=a2+a3+a4=a1+a3+a4=a1+a2+a4=p from 1st and second we find a1=a4 from 2nd and 3rd a2=a1 similarly we find a1=a2=a3=a4, all a's must be equal so a1+a2+a3+a4=n a1=n/4 In general a1=n/p, where p is the number of teams. When p is not divisible, we need to make all of them as equal as possible by distributing n % p. I don't understand lagrangian multiplier by heart(I have not tried to). But the tool works here. We can try bruteforcing all possible team numbers from 2 to k and find which is best. Edited by author 07.11.2016 22:51 int n = in.nextInt(); int l = 0; if (n > 24) { out.print("Glupenky Pierre"); } else { for (int i = 1; i <= n; i++) { if (i / 5 == 0) l = 0; if (i / 5 == 1) l = 1; if (i / 5 == 2) l = 8; if (i / 5 == 3) l = 6; if (i / 5 == 4) l = 9; if (i % 5 == 0) l = l * 10; if (i % 5 == 1) l = l * 10 + 1; if (i % 5 == 2) l = l * 10 + 8; if (i % 5 == 3) l = l * 10 + 6; if (i % 5 == 4) l = l * 10 + 9; if (l/10==0) out.print("0"); out.print(l); out.print(" "); } } Edited by author 07.11.2016 22:26 Edited by author 07.11.2016 22:27 There is my code: Program t1134; Const MaxN=1000; Var Card : array[1..MaxN]of boolean; Numb : array[1..MaxN]of integer; Use : array[1..MaxN]of boolean; M,N,i,j : integer; ex : boolean; begin Read(N,M); if (M>N)or(m=0) then begin writeln('NO'); halt(0); end; for i:=1 to N do Card[i]:=false; for i:=1 to M do Use[i]:=false; for i:=1 to M do begin read(Numb[i]); if (Numb[i]<0)or(Numb[i]>n) then begin writeln('NO'); halt(0); end; end; for i:=1 to M do if Numb[i]=0 then begin Use[i]:=true; if Card[1] then begin writeln('NO'); halt(0); end; Card[1]:=true; end else if Numb[i]=n then begin Use[i]:=true; if Card[n] then begin writeln('NO'); halt(0); end; Card[n]:=true; end; for i:=1 to m-1 do if not(use[i]) then for j:=i+1 to m do if not(use[j]) then if numb[i]=numb[j] then begin if (card[numb[i]])or(card[numb[j]-1]) then begin writeln('NO'); halt(0); end; card[numb[i]-1]:=true; card[numb[i]]:=true; use[i]:=true; use[j]:=true; end; repeat ex:=true; for i:=1 to m do if not(use[i]) then if (card[numb[i]])or(card[numb[i]-1]) then begin if (card[numb[i]])and(card[numb[i]-1]) then begin writeln('NO'); halt(0); end; if card[numb[i]] then begin card[numb[i]-1]:=true; use[i]:=true; end else begin card[numb[i]-1]:=true; use[i]:=true; end; end; until ex; Writeln('YES'); end. 3 3 2 2 3 Maybe you forgot something, because the output of your program for this test case is 'YES'; hope this will help Good luck! > 3 3 > 2 2 3 > Maybe you forgot something, because the output of your program for > this test case is 'YES'; > hope this will help > Good luck! > i suppose the answer should be NO for that 2 2 means the 2nd and the 3rd had been taken, so the third number 3 is uncorrect 3 3 2 2 3 Maybe you forgot something, because the output of your program for this test case is 'YES'; hope this will help Good luck! does anyone knows test 6? У задачи отклеилось описание на русском? Хоть и шарю по английскому, всё равно неприятно тратить несколько минут на перевод... Edited by author 20.02.2016 16:49 Если шаришь, скорость восприятия текста не может отличаться в разы. Для многих старых задач, по-видимому, русскоязычного условия в природе не существовало (1043 с того же контеста и тоже без русской версии). Когда-то и меня заботила мысль, а что же делать, когда дорешаю все переведённые задачи с тимуса. Но английский выучился быстрее :D i see N%3 solution everywhere but does anyone have any explanation as to why the guy who has mod-3 no of stones should lose. Some logical or mathematical reason would be much appreciated. Let's see that for every number k which is an integer power of 2, k mod 3 = 1, or 2. (To be exact - table of (k mod 3) for {1,2,4,8,16,32,64... is: {1,2,1,2,1,2,1,2,1,2,... So, you can see that it is impossible to get from (mod 3 = 0) position to another (mod 3 = 0) position in one move. Let n (number of remaining stones) = 3. The first player can make x=1 or x=2 move, but now the second player can counter by making 3-x move and win. So n=3 is a losing position. We have proven that it is impossible to get from one number of stones divisible by 3 to another number of stones divisible by 3 in one move. We can now prove, by the rule of mathematical induction, that every position with n divisible by 3 is a losing position. Let's look - if the first player begins from position with 3*x stones, after any move the opponent can counter by '1' or '2' move and create another position with lesser number of stones, also divisible by 3. In the second case, when first player begins from position with number of stones not divisible by 3 (so n%3=1 or n%3=2), _he_ can now make a '1' or '2' move which will create a (mod 3 = 0) position (which was proven to be losing) for his opponent. Thus, due to arbitrarity of n, any (n mod 3 != 0) position can create a losing position for the second player in one move, so it is a winning position for the first player. Consider these. number of leave stones 1 win 2 win ---- because we can choose 1 or 2 3 lose sure ---- because if you choose 1 number of leave stones == 2 or if you choose 2 number of leave stones == 1 each player will be the winner. 4, 5 win, choose 1, 2 sure each player will be take 1 or 2 sure you will be the winner. 6 lose 7, 8 win .... we can assume if N mod 3 == 0 sure that person will be lose, otherwise we can choose the minimum of first number of stones = N mod 3 so each player will be the loser.
Also we can consider a Grandy function for n from 1 to .... g[0] = 0 g[1] = 1 g[2] = mex{0, g[1]} = 2 g[3] = mex{g[1], g[2]} = 0 g[4] = mex{0, g[2], g[3]} = 1 g[5] = mex{g[4], g[3], g[1]} = 2 ...... g[n] = n%3 More strictly can be proved using mathematical induction why should i declare 128*1024 size of memory for 256KB described in the problem? my code goes here: #include<iostream> #include <cstdio> #include <cmath> double buf[128 * 1024]; int main() { int i = 0; unsigned long long n; while (scanf("%llu", &n) != EOF) { buf[i ++] = (double)sqrt(n * 1.0); } for (; --i >= 0; ) { printf("%.4lf\n", buf[i]); } return 0; } // why 128*1024 ? Because 256kb means there's at most 128kb of digits and 128kb of spaces? Here the array size is 128*1024 and it is double. So doesn't the array hold 128*1024*8 KB of memory(8 bytes for each element) ? Well you don't necessarily need double, you may use long long int for keeping numbers. Of course, it's 8 bytes either way, but you just don't know whether your numbers are going to be a few huge ones, or a ton of 1-digit ones, so you just have to be on a safe side. Hello, I've not found a topic about this test. Does anyone know what is it? I'm just searching from the half of the string to find where can be the center of a palindom. Thank you The follwing is my pgm. Could some give a test case not satisfied here? var s1,i:integer; f:boolean; a2,b2,a1,b1,a,b:real; begin f:=false; read(a); read(b); a1:=a/100; b1:=b/100; if b<>0 then i:=trunc(1/b1); a2:=a1*(i); b2:=b1*(i); while not f do begin if (((trunc(b2)<>trunc(a2)))and (frac(b2)<>0) then f:=true; a2:=a2+a1; b2:=b2+b1; i:=i+1; end; i:=i-1; writeln(i);
end. Got ac by using double not float by accepting the input, so wired. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> const long long mod=1000000007; const int nmax=200; int n,m,t,p; long long v[nmax],fact[nmax],step[nmax]; bool used[nmax]; bool a[nmax][nmax]; long long ans; void DFS(int v) { for(int j=1;j<=n;j++) { if(a[v][j] && !used[j]) { t++; used[j]=true; DFS(j); } } } bool FindCycle(int v,int pr) { bool f=false; for(int j=1;j<=n;j++) { if(a[v][j] && j!=pr) { if(used[j]) return true; else { used[j]=true; t++; f=f | FindCycle(j,v); } } } return f; } void main() { scanf("%d%d\n",&n,&m);
if(n<=2) { printf("1"); return; }
fact[0]=1; for(int i=1;i<=n;i++) fact[i]=fact[i-1]*((long long)i) % mod;
for(int i=1;i<=n;i++) step[i]=0;
for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) a[i][j]=false; }
for(int i=1;i<=m;i++) { scanf("%d\n",&t); if(!a[i][t]) { a[i][t]=a[t][i]=true; step[i]++; step[t]++;
} }
p=1; while(p<=n && step[p]<=2) p++; if(p<=n) { printf("0"); return; }
for(int i=1;i<=n;i++) used[i]=false;
for(int i=1;i<=n;i++) { if(!used[i]) { used[i]=true; t=1; if(FindCycle(i,-1)) { if(t<n) { printf("0"); return; } if(t==n) { printf("2"); return; } }
} }
for(int i=1;i<=n;i++) used[i]=false; p=0; ans=1; for(int i=1;i<=n;i++) { if(!used[i]) { p++; t=1; used[i]=true; DFS(i); if(t>1) t=2; ans*=((long long)t) % mod; } } ans=ans*fact[p-1] % mod; while(ans<0) ans+=mod; printf("%lld",ans); } Test #9 is the first test with N = 100, and it's also the first with M = 100. I've generated 2k+ random tests with those parameters but got no difference between programs, so i guess it should be a quite specific test. Anyways, the right answer to that one is 950M ± 10M, and yours is 580M ± 10M. В-общем,я в своём репертуаре. ТОТ ЖЕ ГОВНОКОД, но на ПАСКАЛЕ, дал АС! P.S. Glad to see you, Jane Soboleva!!! Oh, i guess it was something syntax-specific then, like in a certain place there goes a wrong order of operations or something like that... P.S. Glad to see you, Jane Soboleva!!! <3 a a b a a answer: 1 Input doesn't contain two equal words Sorry... It test is incorrect. If you have WA4 java. Put 10^7 instead of 10^6 |
|