Common Board#include <iostream> int main() { int k1,k2; int count=0; int flag=1;
std::cin>>k1>>k2; for(;;) { if(flag==1) { if(count==k1) { std::cout<<"yes"; return 0; } count++; flag=-flag; } if(flag==-1) { if(count==k2) { std::cout<<"yes"; return 0; } count++; flag=-flag; } if(count>k1 && count>k2) { std::cout<<"no"; return 0; } }
} a better way: #include<iostream> using namespace std; int main(){ int lock1,lock2; cin>>lock1>>lock2; if(lock1%2==0||lock2%2==1){ cout<<"yes"; }else{ cout<<"no"; } return 0; } 1st. code is correct, but does not meet the requirements of the problem .. based on the conditions of the problem, such a check should be: if((a>0 && a <= 9999 && a%2 == 0)||(b>=0 && b <=9999 && b%2 ==1)) cout << "yes"; else cout << "no"; 0000 excluded from the search because the code has been entered., + indicated that a strictly four digit string to the test unchecked .. verdict .. flawed testing Edited by author 12.02.2013 17:11 #include <iostream> using namespace std; int main(){ int l,b; cin>>l>>b; l%2==0 || b%2==1 ? cout<<"yes" : cout<<"no"; } Edited by author 29.09.2013 13:22 Edited by author 29.09.2013 13:22 What's the meaning of your code ? and I'm not sure what's the main method to steal the bike by the thief. Could you mind tell me ? Edited by author 05.11.2012 22:48 you can see that thief is testing even code on night 1, 3, 5... and odd code on night 2, 4, 6... So thief can steal the bike if the code is even on night 1, 3, 5... and odd code on night 2, 4, 6... Code may be even on night 1,3,5 only if first lock have even code. Code may be odd on night 2,4,6 only if second lock have odd code. So you have to check only if first lock have even code or second have odd code. I have solved it with Dp in 0.015. Is there anyone fast(DP)? I'd be more interested in your memory strategy. I don't think DP alg will differ much for the same problem Maybe the test data are so simple, and DP is able to accept. But I don't think DP method is right. dp(bug task) and bruteforce (2^n) are both accepted for me it got accepted with brute force Time : 0.015 (I think its the minimal time) C++ using maps and vectors Used DP Want d code? gaston770@gmail.com Less than 15 lines of the algorithm My solution cost monstrously 0.187s using DP... Легко решается с динамическим програмированием. Делишь сумму камней на 2 части, потом запускаешь рюкзак до суммы камней/2, ответом будет являться abs(sum-2*maxx), где sum - сумма камней, а maxx - макс. вес, который мы можем поместить в наш "рюкзак" test case #7 fail. please give it for me! Can anybody tell what is Test 8. Getting WA. #include <stdio.h> #include <iostream> using namespace std; #define MAX 15000 struct Team { int ID; int M; }; void Swap(Team &A, Team &B) { Team temp = A; A = B; B = temp; } void QuickSort(Team A[], int left, int right) { int i, j; if (left >= right) return; int x = ((left + right)/2); i = left; j = right; while(i < j) { while (A[x].M < A[i].M) i++; while (A[j].M < A[x].M) j--; if(i <= j) { Swap(A[i], A[j]); i++; j--; } } QuickSort(A, left, j); QuickSort(A, i, right); } void main() { int N; Team A[MAX]; cin >> N; for (int i = 0; i < N; i++) cin >> A[i].ID >> A[i].M; QuickSort(A, 0, N - 1); for (int i = 0; i < N; i++) cout << A[i].ID << " " << A[i].M << endl; } #include <iostream> #include <string> #include <stdio.h> #include <cmath> using namespace std; int n,k,col=0; int main() {
cin>>n>>k; int bo=0; int z,z1; z=pow(10.0,(n-1)); z1=pow(10.0,n); for(int i=z;i<z1;++i) { for (int v = i; v; v /= 10) { if (((v%10)>=k) || (((v%10)==0) && ((v%100)==0))) {bo=1; v=0;}; } if (!bo) ++col; bo=0; } cout<<col; return 0; } Насколько я понимаю, основание может быть отличным от 10, то есть с основанием, 2, 3, 4, 5, 6, 7, 8, 9. Из-за этого и запись разная, например число 31(осн. 10) = 11111(осн. 2) = 51(осн. 6) = 24(осн.8) = 1F(осн. 16). Вот такие пироги. i have tested it, and it look like working, can you say me is this look like correct, or can you advise me how to fix it?) #include <iostream> using namespace std; int main() { unsigned __int64 n, b, i, r, sum = 0; cin>>n>>b; for (i = 2; i <= n - 1; i++) { r = (n - 1) / i + (n - 1) % i; sum += r * pow(double(b - 1), double(n - i)); } cout<<unsigned __int64(pow(double(b), double(n)) - pow(double(b), double(n - 1)) - sum)<<endl; //system("pause"); } Can anyone help me ? I have WA on test 43 . Thanks for your attention . #include "stdafx.h" #include <iostream> #include <conio.h> using namespace std; void bubbleSort(int array[], int col){ int temp=0; for (int i=1; i<col ; i++){ for (int j=0; j<col-i; j++){ if (array [j]>array [j+1]){ temp=array[j]; array [j]=array [j+1]; array [j+1]=temp; } } } } int _tmain(int argc, _TCHAR* argv[]) { int k; int max; int sum; sum = 0; max = 0; cin >> k; int *p = new int[k-1]; int i; for (i = 0; i < k; i++) { cin >> p[i]; }
bubbleSort(p, k-1); k=k/2+1; for (i=0; i<k; i++) { sum = sum + p[i]/2+1; } cout << sum; _getch(); return 0; } kgxvh8-ov2fjo kgxvh8-ov2fjo(1) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory What's wrong? There is no problem in Visual Studio 12 :( My programm passes all my tests, but WA#3. Please, help. Thanks a lot. How you here have applied Dinamic Prog.? I the ambassador aside graph. Hi, Taras. I use simple method: I read two variables ot and ku. If ot and ku are in the same group, I Output('IMPOSSIBLE'); If they are in the different groups then I Continue else I put one variable into the first group and other into the second group. After that I divide "free" tasks between the groups... I hoped that It would get more than two tests... May be I should try to use graphs... BTW, tell me youre ICQ number, I cann't find you... Edited by author 02.05.2006 13:17 try this test, maybe will help you: 4 6 1 2 2 3 3 4 4 5 6 7 7 8 ANS: 1 3 5 7 2 4 6 8 You can use it. I used it as well. First you must paint the graph with black and white (use BFS) so that two vertices with the same edge are of different colors. After that you have pairs of integers and you have to combine them so that you have N in each round (that's not always possible). how I should combine them ?? Thenks, I have AC Edited by author 27.09.2013 15:34 I think my program is correct, but i've gotten wa 27 three times. Does anyone know what this test iss? Sorry please, i find mistake... Edited by author 24.09.2013 18:26 #include<iostream> #include<math.h> using namespace std; int main() {int t=0; int a,b,c; int d=0; long A[4001]; long B[4001]; long C[4001]; long D[4001]={0}; cin >> a; if(a <1 || a > 4000) exit(0); for(int i=0;i<a;i++) { cin >> A[i]; if(A[i] < 0 || A[i] >1000000000) exit(0); } cin >> b; if(b < 1 || b > 4000) exit(0); for(int i=0;i<b;i++) { cin >> B[i]; if(A[i] < 0 || B[i] >1000000000) exit(0); } cin >> c; if(c < 1 || c > 4000) exit(0); for(int i=0;i<c;i++) { cin >> C[i]; if(A[i] < 0 || C[i] >1000000000) exit(0); } for(int i=0;i<a;i++) for(int j=0;j<b;j++) if(A[i] == B[j]) { D[i]=A[i]; B[j]=0; t++; break; } for(int i=0;i<t;i++) for(int j=0;j<c;j++) if(D[i] == C[j]) { d++; C[j]=0; break; } cout << d; system("pause"); return 0; } program djy; var a:array[1..150,1..150] of integer; lx,ly,link:array[1..150] of integer; flagx,flagy:array[1..150] of boolean; n:longint; procedure init; var i,j:longint; begin readln(n); for i:=1 to n do for j:=1 to n do read(a[i,j]); end; procedure prepare; var i,j,s:longint; begin {for i:=1 to n do begin s:=0; for j:=1 to n do s:=s+a[j,i]; for j:=1 to n do a[j,i]:=a[j,i]-s; end;} fillchar(lx,sizeof(lx),0); fillchar(ly,sizeof(ly),0); for i:=1 to n do for j:=1 to n do if a[i,j]>lx[i] then lx[i]:=a[i,j]; end; function find(i:longint):boolean; var j:longint; begin flagx[i]:=true; for j:=1 to n do if (lx[i]+ly[j]=a[i,j]) and (flagy[j]=false) then begin flagy[j]:=true; if (link[j]=0) or (find(link[j])=true) then begin link[j]:=i; find:=true; exit; end; end; find:=false; end; procedure main; var i,j,k,d:longint; begin fillchar(link,sizeof(link),0); for k:=1 to n do repeat fillchar(flagx,sizeof(flagx),false); fillchar(flagy,sizeof(flagy),false); if find(k)=true then break; d:=maxint; for i:=1 to n do for j:=1 to n do if (flagx[i]=true) and (flagy[j]=false) and (lx[i]+ly[j]-a[i,j]<d) then d:=lx[i]+ly[j]-a[i,j]; for i:=1 to n do if flagx[i]=true then lx[i]:=lx[i]-d; for i:=1 to n do if flagy[j]=true then ly[j]:=ly[j]+d; until false; end; procedure print; var i,j,s:longint; begin s:=0; for i:=1 to n do for j:=1 to n do s:=s+a[i,j]; for i:=1 to n do s:=s-a[link[i],i]; writeln(s); end; begin init; prepare; main; print; end. You gotta use A+B code. I don't remember the correct algorithm but you can find'em in the tutorial. I got AC. Seriously. These days I've noticed that some programmer got stuck on BIG problems like "ships version 2", which may cost up to tens of seconds to judge. However the general limit for submitting a solution is 10 second. So, you see a whole lot page of 'waiting'. Maybe increase the interval for these problems? I think it is bad idea to tighten rules because of one genius (who made about 1000 submissions on the problem in several hours) - better just to ban it. But, since it is easy to register again, a good idea for timus maybe to restrict the number of submissions of one user (or from one IP) during the last 24 hours (at most 100, for example). Edited by author 20.09.2013 02:27 Edited by author 20.09.2013 08:33 Sounds readonable. Let's see what the admin has to say lol truth_table = { 'few': lambda x: x > 0 and x < 5, 'several': lambda x: x > 4 and x < 10, 'pack': lambda x: x > 9 and x < 20, 'lots': lambda x: x > 19 and x < 50, 'horde': lambda x: x > 49 and x < 100, 'throng': lambda x: x > 99 and x < 250, 'swarm': lambda x: x > 249 and x < 500, 'zounds': lambda x: x > 499 and x < 1000, 'legion': lambda x: x > 999 } def translate_count(count): for result, func in truth_table.items(): if func(count): return result translate_count(raw_input(u"Number: ")) Проверку локально проходит, может нужно не так обрабатывать входные параметры? It's strange but it works for Python3 (with corrections for print and input). current_key = int(input().strip()) backup_key = int(input().strip()) for thief_key in range(0, 9999): if current_key == thief_key: print("yes") break if thief_key > current_key or thief_key > backup_key: print("no") break temp_key = backup_key backup_key = current_key current_key = temp_key It passes tests with "0001/0000" -> no and "0002/0001" -> yes. And I traced it, it works right. But they said, that I have wrong answers. Why? P.S. Mistake of course was in the line: if thief_key > current_key or thief_key > backup_key: I should use and instead or. Edited by author 24.09.2013 01:56 #include<iostream> using namespace std; int main() { int a; cin >> a; if(a > 100 || a < 1) exit(0); int b[101]; int c; cin >> c; if(c > 100 || c < 1) exit(0); for(int i=0;i<c;i++) { cin >> b[i]; if(b[i] >= 101 || b[i] <= 0) exit(0); } int d=0; int j=0; int k=0; for(int i=0;i<c;i++) { if(i == c-1) k=b[i]-a; j=0; if(b[i] > a) { j=b[i]-a; b[i+1]+=j; d+=a; } } cout << k; system("pause"); return 0; } |
|