Statement is unclear. If you want to solve it you must try all possible interpretations of this statement 'till find the one that the author intended. If you get WA5, check case, where policeman catch the thief until first tram arrive. #include <iostream> using namespace std; const int kmax=105; int K[kmax]; int L,n; int R(int x, int y) { if(x%y==0) return x/y; else return x/y+1; } int main() { cin>>L>>n; for(int i=1;i<=n;i++) cin>>K[i];
if(n==1) { if(L<K[1]) cout<<"YES"; else cout<<"NO"; return 0; }
int t1=R(L, K[1])*K[1], t2=K[1]; if(t1==t2) t1+=K[1];
for(int i=2;i<=n;i++) { t2+=K[i]; if(t1<t2) { cout<<"YES"; return 0; } t1=t2+R(t1-t2,K[i])*K[i]; if(t1==t2) t1+=K[i]; }
cout<<"NO"; return 0; } and #include <iostream> using namespace std; const int kmax=105; int K[kmax]; int L,n; int main() { cin>>L>>n; for(int i=1;i<=n;i++) cin>>K[i];
if(n==1) { if(L<K[1]) cout<<"YES"; else cout<<"NO"; return 0; }
int t1=(L/K[1]+1)*K[1], t2=K[1];
for(int i=2;i<=n;i++) { t2+=K[i]; if(t1<t2) { cout<<"YES"; return 0; } t1=t2+(1+(t1-t2)/K[i])*K[i]; }
cout<<"NO"; return 0; } ????????????????????????????????????????????? Hi I had solved this problem with just 3 shortint... It so easy look other messages in this problem to understand what is happening! All you need is: dec(n,n mod y); where y is that K[i]`s which described in problem. nothing is special for this problem... With best Wishes Aidin_n7@hotmail.com This way is so incredible! Could you explain why it's correct and what does this problem mean? Thanks. Obviously, distance between cop and robber can only decrease. If cop cannot overtake robber at current stage(if L >= k[i]), so new min distance in the best case for policeman will be equal to (minimum amount of trams)*k[i]. And minimum amount of trams is L mod k. For instance, L=7, K=3, so policeman will miss at least 2 trams: robber will reach tram stop, wait at most 3 mins and go away. Policeman will miss next tram, and he should wait another 2 mins before next tram will come. So, new L = 2*K = 6. But minimum amount if trams is [L/k[i]], not L%k[i] Oo What is the output for this two inputs?? 3 2 1 2 and 3 3 1 2 2 Two very helpful tests: test: 3 2 1 2 ans:NO test: 3 3 1 2 2 ans:NO if this test 3 3 1 2 3 ans:YES ??? Old name "Cops and Robbers" could be confusing because of problem 1277 "Cops and Thieves". New name is "Catch the thief!" If L == K, policeman doesn't catch the theif. I got AC when supposed so. Text from statement: "For instance, if L < K1, then it may happen that the policeman reaches the first stop when the robber is still waiting for a tram there." It means that you are right. I can't understand it, either. Edited by author 25.05.2010 08:31 hi,standard input has keyboard. and standard output has monitor. Where do the intervals start from? And why doesn't it matter the legth of the tram travels? I mean, it must matter for the interval of the trams....... Explain PLZ any time the robber come to the i-th stop, he have to wait for ti (time interval) minutes ,a tram will come and the interval starts. most of problems in this contest are very ambigious, i had to guest many times to know what they want. please explain me about 1190 First, 10x about the explanation. I'll try to solve it having that in mind. About 1190-> I had problems with understanding it, too. Maybe you should read the comments on board 1190. Some people helped me there. You should have these in mind : 0) Percents should be non-increasing, not strictly decreasing 1) Names contain no intervals 2) Try both the possiblities-> the maximum one and the minimum one. If the maximum is less than 10000, then NO. If the minimum is more than 10000 than NO again. If the percents are not non-increasing-> NO. Otherwise-> YES. You should get AC with that. and what about the policeman? does he have to wait ti as well? Because, if the counting for him starts with the arrival of the robber at the tram stop, then it DOES matter the length of the route... So, does the policeman have to wait ti minutes as well? Another question-> If the distance (the lag-> L) is 2, and t1 is 2, does the policeman catch the robber 15 4 7 3 13 6 1st stop robber is here at time 0 and he go out when time 0+7 police is here at time 15 the next tram will come at time 21 (trams come at 7,14,21) the length of route doesn't matter the time lag at all because their speed are always equal. so i'll assume that it's 0. 2nd stop robber arrive at 7 robber go 7+3=10 police arrive 21 police go 22 (10,13,16,19,22) 3rd stop robber go 10+13 = 23 police come 22 and arrest the robber here before he can go #include <stdio.h> int main() { int cop,n,ti,rob,i,st,ost,tmp; scanf("%d %d",&cop,&n); for (i=1;i<=n;i++) { scanf("%d",&ti); st=rob; rob+=ti; if (rob>=cop) { printf("YES\n"); return 0; } st=cop-st; ost=st%ti; if (ost==0) ost=ti; cop+=(ti-ost); } printf("NO\n"); return 0; } I tried with if (rob>cop) but I got WA. I tried to compare the leaving times(i mean, compare the time when the cop catches the tram and the time the robber catches the tram, and if they are the same or the cop can catch an earlier tram, then YES... but WA too. What I do is just implementing stepwisely what you told me-> in 'cop' i keep the time of the cop, and in 'rob' the time of the robber... But WA. Help plz? > #include <stdio.h> > > int main() { > int cop,n,ti,rob,i,st,ost,tmp; > scanf("%d %d",&cop,&n); > for (i=1;i<=n;i++) { > scanf("%d",&ti); > st=rob; > rob+=ti; > if (rob>=cop) { > printf("YES\n"); > return 0; > } > st=cop-st; > ost=st%ti; > if (ost==0) ost=ti; > cop+=(ti-ost); > } > printf("NO\n"); > return 0; > } 1.) initialize the variable rob to be 0! 2.) problem statement says "the policeman will have luck to overtake the robber. For instance, if L *****<***** K1, then it may happen that the policeman will reach the first stop, when the robber is still waiting for the tram there." this implies that , if police reach the stop when the robber is leaving , he just have to wait from the next tram. so use condition "rob>cop" and comment "if (ost==0) ost=ti;" and you'll get AC! I don't think the statement is clearly, it may mislead someone like me... just why WA 1? #include<iostream> using namespace std; int main() { int l, n, k; cin>>l>>n; while(n--){ cin>>k; if(l<=k) {cout<<"YES"; return 0;} l-=k; l+=l%k; } cout<<"NO"; return 0; } I have WA#10. Can you help me? here is my code: program _1191; {$APPTYPE CONSOLE} uses SysUtils; var k:array[1..100]of longint; l,n,i,q,z:longint; begin reset(input,'input.txt'); rewrite(output,'ouput.txt'); read(l,n); q:=1; z:=0; for i:=1 to n do begin read(k[i]); z:=z+k[i]; if l<z then begin write('YES'); halt(0); end else while l>z+q*k[i] do inc(q); l:=z+q*k[i]; q:=1; end; write('NO'); end. Edited by author 18.03.2009 19:38 Comma must be put after the word "поехать" in the first sentence of the statement. What is the output for this two inputs?? 3 2 1 2 and 3 2 1 2 2 > What is the output for this two inputs?? > > 3 2 > 1 2 > YES > > and > > 3 2 > 1 2 2 > YES IMHO > What is the output for this two inputs?? > > 3 2 > 1 2 > YES > > and > > 3 2 > 1 2 2 > YES IMHO > What is the output for this two inputs?? > > 3 2 > 1 2 > > > and > > 3 2 > 1 2 2 What is the output for this two inputs?? 3 2 1 2 Answer: NO and 3 2 1 2 2 Answer: NO Edited by author 28.06.2007 19:38Second case is incorrect. It must be 3 3 1 2 2 I tried to submit many times my solution which I think is right but I got WA 1 many times. Then I submitted the following solution: #include <iostream> using namespce std; int main() { cout<<"YES"; return 0; } and I still have WA1, why (as far as I know the first test is the same as the sample test where the right output is YES) Edited by author 30.06.2006 20:18 Yup, you are right, when I submitted the following solution: #include <iostream> using namespce std; int main() { cout<<"NO"; return 0; } I got WA 2, so it seems the problem is in my code :) I've got WA on case 10. plz help me. #include<stdio.h> int main(){ ....int n,k,i,dis; ....scanf("%d%d",&dis,&n); ....for(i = 0;i < n;i++){ ........scanf("%d",&k); ........if(dis != k) dis -= k; ........if(dis < 0){printf("YES"); return 0;} ........if(dis % k != 0) dis += k - dis%k; ....} ....printf("NO"); ....return 0; } Edited by author 02.05.2006 23:21 Change (dis != k) to (dis % k != 0) and you'll get AC. Good luck ;) Thank you very much!! Now I got AC. It would be the best if you email pipm@mail2000.ru Program acm_1191; {Cops And Robbers} Var i,j,k :integer; L,N :integer; A :array [1..100] of integer; Begin ReadLN(L,N); For i:=1 to N do Read(A[i]); For i:=1 to N do Begin {Checking I-th stop} If A[i]>=l then Begin Writeln('YES'); Halt(0); End; {CAUGHT} j:=200*A[i]-l; l:=l+(j mod A[i]); {Cop waiting} l:=l-A[i]; {Robber waiting} End; Writeln('NO'); End. |
|