Common BoardThe cook must cook the one steak during 2 minutes (each side during 1 minute). Right? In example n = 3, k = 2, then: * at first step he cook 2 stake during 2 minutes; * at second step he cook 1 stake during 2 minutes; Answer = 2 + 2 (minutes), but in example 3? If try to send solution based on above logic, checker answered with mistake. Probably checking occurs on this way (all test passed): answer == (k >= n) ? 2 : n * 2 / k + ((n*2 % k == 0) ? 0 : 1) but, more correctly (in my opinion) variant: answer == (k >= n) ? 2 : n * 2 / k + ((n % k == 0) ? 0 : 1) Your solution to n=3, k=2 is not optimal. Hint: examine different orderings, trying to keep the frying pan as full as possible all the time. In your solution, you have the frying pan half empty twice. STL map rulz for this probl Edited by author 14.02.2008 20:29 Edited by author 14.02.2008 20:29 I think this problem can be solved easy without STL ;) Yes but STL map<string,int> is really great for string counting problems like this, and leads to short, clear solutions. if you have only one experiments "X satisfied" then the answer is always X if you have only one experiments "X hungry" then the answer is always 10 If n == 0 ? What is the anwaer? Somebody already answered this in the discussion, it's 10 read the text! The text is inadequately worded, it does not specify the process for shoeing the right feet after the left feet are filled. The solver must assume that the process for filling the right feet is the same as for filling the left feet. All solutions now get WA1 / WA13, even those, which have been accepted earlier. It's a judge error or just a rejudge coming? Edited by author 22.09.2012 17:21 Sorry, we have broken test #13. It's fixed now. Solutions are rejudged. check this tests for "Not a floating point number" - 1 -. 1 -.e0 1 -.1e 1 #123 1 --123 1 -1.e6 1 And last one (when I fixed this, I got Accepted): -e20 1 Of course this is not an exhaustive list of possible bugs. Good luck, guys! does anyone knows test 3? thank you! import java.util.Scanner; public class MEGA { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int capacity = sc.nextInt(); int minutes = sc.nextInt(); int stoppedcars = 0; for (int i=1; i<=minutes; i++) { int thisminutecars = sc.nextInt(); if (thisminutecars > capacity) stoppedcars = thisminutecars - capacity; if (thisminutecars < capacity) stoppedcars = stoppedcars - (capacity - thisminutecars); } if (stoppedcars < 0) stoppedcars = 0; System.out.println(stoppedcars);
} } Edited by author 17.09.2012 17:51 Step through in the debugger and see if the changes to stoppedcars makes sense to you. Do you properly handle cars left over from previous minutes? I wrote an iterative primes generator using a 2-3-5 wheel for candidate generation and a priority queue for storing composite sequences. I feel silly seeing all the ACs for trial division. But at least now I know about wheel generators and iterative prime generation :). program ural1078(input,output); type node=record x,y:longint;num:longint;end; var n,i,j,max,maxi:longint; f:array[1..500]of longint; c:array[1..500]of longint; l:array[1..500]of longint; a:array[1..500]of node; procedure sort(l,r:longint); var i,j:longint;k,temp:node; begin i:=l;j:=r;k:=a[(l+r)div 2]; repeat while a[i].x>k.x do inc(i); while k.x>a[j].x do dec(j); if i<=j then begin temp:=a[i]; a[i]:=a[j]; a[j]:=temp; inc(i);dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure print(x:longint); begin if x=-1 then exit; print(c[x]); write(a[x].num,' '); end; begin readln(n); //if n=0 then writeln(0); for i:=1 to n do with a[i] do begin readln(x,y);num:=i; end; sort(1,n); fillchar(c,sizeof(c),255); for i:=1 to n do begin f[i]:=1;l[i]:=0; for j:=i-1 downto 1 do if (a[i].x<a[j].x)and(a[j].y<a[i].y) //Take Care!!! then begin if f[j]+1>f[i] then begin f[i]:=f[j]+1; c[i]:=j; end; end; end; for i:=1 to n do if f[i]>max then begin maxi:=i;max:=f[i]; end; writeln(max); print(maxi); end. I've solved 1079,but this problem...Is any trick there? Edited by author 01.09.2007 22:19 I think, the only trick here - to have creative brains :) I thihk that unhelpful to wait when creativeness come to us. That it should try to solve as can. For exampple, let n to be strong number if a[n]>max(0<=i<=n-1) a[i]. It is evidence that having strong numbers precalculated and if their number rather small then the problem will be solved easily. This is list of strong numbers in 1000: 3 1 1 5 1 0 1 9 1 0 0 1 11 1 0 1 1 19 1 0 0 1 1 21 1 0 1 0 1 35 1 0 0 0 1 1 37 1 0 0 1 0 1 43 1 0 1 0 1 1 69 1 0 0 0 1 0 1 73 1 0 0 1 0 0 1 75 1 0 0 1 0 1 1 83 1 0 1 0 0 1 1 85 1 0 1 0 1 0 1 139 1 0 0 0 1 0 1 1 147 1 0 0 1 0 0 1 1 149 1 0 0 1 0 1 0 1 165 1 0 1 0 0 1 0 1 171 1 0 1 0 1 0 1 1 277 1 0 0 0 1 0 1 0 1 293 1 0 0 1 0 0 1 0 1 299 1 0 0 1 0 1 0 1 1 331 1 0 1 0 0 1 0 1 1 339 1 0 1 0 1 0 0 1 1 341 1 0 1 0 1 0 1 0 1 555 1 0 0 0 1 0 1 0 1 1 587 1 0 0 1 0 0 1 0 1 1 595 1 0 0 1 0 1 0 0 1 1 597 1 0 0 1 0 1 0 1 0 1 661 1 0 1 0 0 1 0 1 0 1 683 1 0 1 0 1 0 1 0 1 1 If you can find algo for their generation you will winner. Now I can't. But it,s evident for me that for their binary expansions fulfil next lows: 1) numbers of 0 and 1 are equal or with difference 1; 2) 1 and 0 alternates exept for last two 1. I can generate such number sets combinatorically ang strong numbers will be among them. By the way, number of strong numbers really very small/ For example, until 200000 thei number is 114. Edited by author 20.09.2007 12:08 I also noticed this feature (and even some more strong), but it didn't help me to solve the problem... Thank you for your help!I'll think about it.Now with your help I've idea.Ostalnoe,po-moemu,delo tehniki. Edited by author 20.09.2007 18:42 It's quite easy to see the pattern. It's a bit different for odd and even number of digits (excluding leading zeroes), but there IS a pattern, and it's quite simple to program. If you still can't find the pattern inside base-2 representation (I could do that), write it base-4 - it's more evident there and easier to code. Even if you cannot find strict pattern, you may find some weaker pattern which includes all of strong indices and probably some more. Of course, this will lead to O(log^2(N)) solution because you will have to test each of such indexes as you don't know which of them is actually a strong one, but still it should be AC. My algo generates strong indices ONLY, and it does so only for N/2..N interval. The biggest goes to the answer. N<65536 are brute-forced special cases (too few digits). Yes I found the pattern in binary and got AC (0.078, 140KB) (no precompute), for strong indices only, and only generate them starting with 2^(floor(log2(n))). The pattern holds lower than 65536 so you can set the brute force threshold lower for faster execution time. (I have a special case for finding the maximum if it occurs below my starting point). This has been a fascinating problem to solve, thank you to the authors. Edited by author 20.09.2012 23:38 I submited several times and i got WA at test #8. I really appreciate if you would be so kind by giving me test #8. Thank you. Edited by author 30.09.2005 16:11 Edited by author 30.09.2005 16:11 it help you 5 1 1 2 2 3 2 4 4 5 Good luck P.S. I think you program Wrong. Guy who create test 99% very funny. The answer is "First player loses". That's why each terrorist chooses the best move. It's tricky TestCase. Thankx, it help you 5 1 1 2 2 3 2 4 4 5 Good luck P.S. I think you program Wrong. Guy who create test 99% very funny. I have changed my code several times...This one is always wrong. One time it's correct , but other testcases are all wrong. Finally after I add more 30 lines, I got AC . My code is very ugly Hello, I often want to brag about my accomplishments at acm.timus.ru, I want to show how many problems I have solved and that I'm one of the most geeky participant of Timus. I very much like the way projecteuler encourages boasting, it has a profile with level and number of problems solved. In the end, such a feature would benefit everyone: Timus users can boast, Timus itself gets more visibility and new participants. # include <iostream> # include <cstdio> using namespace std; const int Maxn = 130012; int n, ans1, ans2, L1, L2, x, p[Maxn], q1, q2; int GCD (int a, int b){
if (b > a) return GCD(b, a); else if (b == 0) return a; else return GCD(b, a % b); } int main () { freopen ("1.txt", "r", stdin); freopen ("2.txt", "w", stdout); cin>>n; for (int i = 1; i <= n; i++){ cin>>x; p[x] = i; } q1 = 0; q2 = n + 1; ans1 = 0; ans2 = 0;
for (int i = 1; i <= Maxn; i++){ if (p[i] > 0) { q1 ++; q2 --; L1 = p[i] - q1; if (L1 < 0) L1 = -L1; L2 = p[i] - q2; if (L2 < 0) L2 = -L2; if (L1 > 0) if (ans1 > 0) ans1 = GCD(ans1, L1); else ans1 = L1; if (L2 > 0) if (ans2 > 0) ans2 = GCD(ans2, L2); else ans2 = L2;
}
} if (ans1 == 0) ans1 = n - 1; else ans1 --; if (ans2 == 0) ans2 = n - 1; else ans2 --; if (ans1 > ans2) cout<<ans1; else cout<<ans2; return 0; } Edited by author 19.09.2012 17:23 1) число может быть с ведущими нулями 2) выводить надо с ведущими нулями(если они есть) короче вот тест 1) 0 000000000002 2) 2 02 020000000089 AC code? Put here.. I hope nobody will put. Forum is not good place to post right solutions ;) You can write your email here... Btw, and did you try to solve|submit it yourself? Money? Put here... +7 926 153 72 30 my solution : for (i = 1; i<=n; i++) printf("%d ",i); for (i = n; i > 1; i--) printf("%d ",i); had ac... but it's wrong!! Edited by author 18.09.2012 18:57 Edited by author 18.09.2012 18:57 it is not necessary, it was comparing the real numbers find out such x that 2^x < n < 2^(x+1) 2^x means 2*2*...*2 x times x=log(n)/log(2);//c++ the maximum value of a[i] i=1,2,...,2^x is max=f(x); where f(x) is the fibonacci sequence f(0)=1 f(1)=1 f(n)=f(n-2)+f(n-1) so i just have to look if there is a larger number from 2^x to n it is easy to find out the value of a[i] without knowing a[1]...a[i-1] if l=2*k and r=2*p m=(l+r)/2 a[m]=a[l]+a[r]; it is rather easy to prove that a[2^x]=1; a[2^(x+1)]=1; so you just have to do a binary search for i from 2^x to 2^(x+1) calculating the values for the left and right border this is the function that does exactly that //c++ int b(long l,long r,long i,int v1,int v2) { long m=(l+r)/2; if (i==m) return (v1+v2); if (i<m) return j(l,m,i,v1,v1+v2); return j(m,r,i,v1+v2,v2); } I DON'T UNDERSTAND WHY, BUT WHEN I USE MATH.H I GET COMPILATION ERROR good luck !!! You have to use math instead of math.h ;-) Manastireanu, thank you for your ideas, they pushed me to more deeply study the sequence. A few comments: > if l=2*k and r=2*p, m=(l+r)/2, a[m]=a[l]+a[r]; This is not true for all k and p, e.g., k=4 and p=7. It is true starting with l=2^x and r = 2^(x+1), m=(l+r)/2 and then recursing through more (l,r) with (l, m) and (m, r). There are many interesting properties of this sequence, I encourage everyone to study it and to discover the patterns which will help solve this problem without "brute force", and will help with Maximum2 |
|