Common BoardTry this test: a Your output should be: aa Good luck! Thank you! You is good man! Can someone give 5<sup>th</sup> test? I got WA5; is the first sample correct? isn't a test from picture? and then there is not river basin with area 16 in the table. it is correct. Edited by author 30.03.2011 00:29 AC using convex polygon algo from e-maxx.ru. I don't know where i was wrong... Edited by author 15.05.2012 22:52 This is the first test where the convex_hull fails if it uses integer as a result of vector product. String symbols = "`~!№*@#$%^&*()-_=+\\|[{]};:'\",<.>/?в„– \n\r\t"; ;) 6 7 1 2 3 2 3 3 3 4 4 1 4 4 4 5 5 2 6 3 6 5 3 Hi All, Just want to share my experience solving this problem. I did it like this let the i be the number of bricks available and j be the height of the last step. S[i][j] = sum(S[i-j][:j]) + (1 if (i-j) < j else 0) So basically all i am doing is the number of stairs with i bricks and height j is also the same number of stairs with i-j bricks and max height of j - 1(hence the array stops at index j) and one more if i - j bricks are less than height j. There might be more slick solution avaiable, but this worked for me :) Edited by author 21.04.2018 01:11 Can you give some tests? The stars coordinates aren't natural numbers? Why precision of 10^-5 is needed? Should the algorithm ignore cases when scalar product of normal vector of the plane and "star"-vector is negative (the angle between vectors will be 90<x<270 so star's rays won't reach solar battery of esp. this plane)? Integer output also works, but you need int64_t. Note that it is not enough for normal/star angle to be less than pi/2, you also need to have correct normal -- the one that is opposite to the fourth vertex. To find the shortest path from point O to lines AB and CD (in that order) one needs to consider three possibilities, namely projection from O to CD (if it intersects AB); projection on CD of the reflection of O thru AB (if it intersects AB); intersection of AB and CD. #include <bits/stdc++.h> using namespace std; int query(int l, int r, vector<int> bucket, vector<int> v) { int n = v.size(); int bkt_sz = sqrt(n); int bkts = bucket.size();
int lb = l/bkt_sz; int rb = r/bkt_sz; int lbp = l%bkt_sz; int rbp = r%bkt_sz;
int retval = -1;
if (lb == rb) { for (int i=lb*bkt_sz+lbp; i <= lb*bkt_sz+rbp; i++) retval = max(retval, v[i]); return retval; }
for (int i=lb+1; i < rb; i++) retval = max(retval, bucket[i]);
for (int i=lb*bkt_sz+lbp; i<n; i++) { if (i >= (lb+1)*bkt_sz) break; retval = max(retval, v[i]); }
for (int i=rb*bkt_sz; i <= rb*bkt_sz+rbp; i++) { retval = max(retval, v[i]); }
return retval; } int main() {
int k; cin >> k;
vector<int> v;
while (true) { int a; cin >> a; if (a == -1) break; v.push_back(a); }
int n = v.size(); int bkt_sz = sqrt(n);
vector<int> bucket;
int count = bkt_sz; int max_value = -1; for (int i=0; i<n; i++) { if (count == 0) { count = bkt_sz; bucket.push_back(max_value); max_value = -1; } count -= 1; max_value = max(max_value, v[i]); }
bucket.push_back(max_value);
for (int i=0; i+k-1 < n; i++) { cout << query(i, i+k-1, bucket, v) << endl; }
} Edited by author 19.04.2018 22:19 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { class Program { static void Main(string[] args) { int x; x = Convert.ToInt32 (Console.ReadLine()); if ((x > 1 & x <= 4) { Console.WriteLine("few"); } if (x > 5 & x<= 9) { Console.WriteLine("several"); } if (x > 10 & x <= 19) { Console.WriteLine("pack"); } if (x > 20 & x <= 49) { Console.WriteLine("lots"); } if (x > 50 & x <= 99) { Console.WriteLine("horde"); } if (x > 100 & x <= 249) { Console.WriteLine("throng"); } if (x > 250 & x <= 499) { Console.WriteLine("swarm"); } if (x > 500 & x <= 499) { Console.WriteLine("zounds"); } if (x > 1000) { Console.WriteLine("legion"); } } } } Да что тут не так? Edited by author 18.04.2018 23:36 Edited by author 18.04.2018 23:37 У вас везде > вместо >=. Ну и тут отдельная ошибка if (x > 500 & x <= 499) there is O(n*m) D&C algorithm... similar with ural 1674 and ural 1596 it is just extend of fermat point, the angle is 2*pi/3 if it is fermat point in this problem three angles are acos((c1*c1-c2*c2-c3*c3)/(2*c2*c3)),acos((c2*c2-c1*c1-c3*c3)/(2*c1*c3) and acos((c3*c3-c1*c1-c2*c2)/(2*c1*c2)) how to get it ,just let two partial derivative to be zero,and square and add two equtation we can get it ,it is easy I can find three angles, but not optimal point. Three angles allow us to assume that the point depends of some angle (phi) and we must find min F(phi). How you solve in O(1)? Give me hint if we get three angles assume optimal point is O,and triangle is ABC, then let angle OAB==theta, we can get some equations using sine theorem and divide two sine theorem euations we can solve tan(theta) then problem is solved Thanks. I forgott sin theorem. Now i have WA2 (I search point in A1A2A3) Triangle A1A2A3 and optimal point is X. XA1A3=phi, XA2A3=alfa12-phi-A3 cos(alfa12)=(c3*c3-c1*c1-c2*c2)/(2c1*c2) ... A3X/sin(phi) = A1A3/sin(alfa13) A3X/sin(alfa12-phi-A3) = A2A3/sin(alfa23) => A1A3/sin(alfa13) sin(phi) = A2A3/sin(alfa23) * [sin(alfa12-A3) cos(phi) - cos(alfa12-A3) sin(phi)] tan(phi/2) = t a*2t/(1+t*t) = b * (c*(1-t*t)/(1+t*t) - d*2t/(1+t*t)) => phi = 2atan(t) ans res=XA1*c1+XA2*c2+XA3*c3 In the second test the optimal point on the side of the triangle? Can there be a test where A1=A2 or A1=A3 or A2=A3? Edited by author 18.04.2018 11:18 wa on test case 2 is probably because there are two or three same points you must to consider deleted Edited by author 18.04.2018 11:51 Hi! Your program on test 1 0 0 100 100 200 200 30 45 78 gives 15273.50647362942600000000 but right answer 14849.242404917499000 (optimal point is A3: A1A3*c1+A2A3*c2). Is the optimal point always inside the triangle or on the side? Yes,admin please add this tests, and make some more similar tests... there are two points A[i]>=alpha[i] in this test ,so must compare these points and get min... Edited by author 03.04.2018 07:41 Edited by author 03.04.2018 07:44 Edited by author 16.04.2018 19:00 Optimal point is O. 1) O=A or O=B or O=C 2) We have triangle ABC with 0<A,B,C<pi; We know cos(AOB), cos(AOC), cos(BOC). Let z1=(c3*c3-c1*c1-c2*c2)/(2*c1*c2), z2=(c2*c2-c1*c1-c3*c3)/(2*c1*c3), z3=(c3*c3-c1*c1-c2*c2)/(2*c1*c2). If |z1|>1 or |z2| >1 or |z3|>1 => optimal point is A or B or C Let |zi|<=1, i=1..3 teta=AOB. Theorem sin: BO/sin(teta) = AB/sin(AOB) = AO/sin(teta+AOB) = k1 and CO/sin(A-teta) = AC/sin(AOC) = k2. =>AO=k1*sin(teta+AOB), BO=k1*sin(teta), CO=k2*sin(A-teta). (*) We want find min{f(teta)=c1*AO+c2*BO+c3*CO} on 0<teta<A. Derivative f: cos(teta)*[c1*k1*cos(AOB)+c2*k1-c3*k2*cos(A)]+sin(teta)*[-c1*k1*sin(AOB)-c3*k2*sin(A)]=0 or cos(teta)*a+sin(teta)*b=0, cos(teta)=+=sqrt(sqr(b)/(sqr(a)+sqr(b)). Then we check 0<teta<A and update ans. Where is mistake? I think mistake is (*) but I can't understand why. P.S. We can use Theorem cos with BOC and get equation with teta, but this equation is big and not obviously that we find solution. P.S. Your code not help me. Edited by author 16.04.2018 19:08 Does your result O point satisfy cos(AOB)==z1 cos(AOC)==z2 cos(BOC)==z3 ? if it is satisfy I think you can AC Now AC. (*) is wrong because F(teta) not function!!! P.S. All the time I incorrectly have considered the case when the point is lying on one of the sides of the triangle (in this case sin(AOB) or sin(AOC) or sin(BOC)=0). I add this and AC: if(fabs(sin(AOB))<eps && fabs(sin(AOC))<eps || fabs(sin(BOC))<eps) return inf; if(fabs(sin(AOB))<eps) {
CO=AC*sin(A)/sin(AOC); AO=AC*sin(A+AOC)/sin(AOC); BO=BC*sin(C-(pi-A-AOC))/sin(BOC); return c1*AO+c2*BO+c3*CO; } if(fabs(AOC)<eps) { BO=AB*sin(A)/sin(AOB); AO=AB*sin(A+AOB)/sin(AOB); CO=BC*sin(B-(pi-A-AOB))/sin(BOC); return c1*AO+c2*BO+c3*CO; }
P.S. Delete your code, but keep the hints. Edited by moderator 23.08.2020 01:12 Did you try some big prime number? Like 777777773. there is a line which isn't token "end" and has no ':' character and there is only one nonempty token.. I use OLE test it must be wrong test... it is not include in the description so admin please fix problem description or delete this test problem description is incorrect there are far more than 2000 lines, and one token is far more than 50 characters.... Unfortunately, std::string in C++ class is very slow... Class string (VS c++) is good for this problem. But if you write like "res+=char+res" You will get TL. Right: "res+=char", "reverse(res.begin(), res.end())" use N = 100001 instead N = 100000 Solution is a sum( [ sqrt(2*i*R - i^2) ], i = 1,2,...,R), where [ x ] - round to up. But, I always GOT TL on 17 test). if we notice f(i)==sqrt(2*i*R-i*i); and f(i+1)-f(i) always >=sqrt(R) we can change to count howmany i satisfy c==sqrt(2*i*R-i*i) then answer+=ways*c then this problem will be solved in O(sqrt(R)) thank you for your hint my fault but increment of f(i) seems to be monotonic decreasing and increment <=sqrt(2*r) so we can binary search and divide them to sqrt(2*r) segment with same increment and add each segment using sum of arithmetic series my fault but increment of f(i) seems to be monotonic decreasing and increment <=sqrt(2*r) so we can binary search and divide them to sqrt(2*r) segment with same increment and add each segment using sum of arithmetic series Consider 2D problem in polar coordinates: intersect disk with given radius R and center in the origin with triangle with vertexes in origin, (R1,0), and (R2,phi). Solve it using quadratic equation... Combine the algebraic sum of solutions to get the final result. Edited by author 12.04.2018 22:45 |
|