Общий форумMy program will not work if inside <blog> tag will be nested <blog>. It does not happen in tests, but I suggest to add notice to the statement that <blog> tag can be only top level and cannot be nested. Alternatively test like this may be added: 2 a <blog> <blog> </blog> b <blog> <friend>b</friend> </blog> </blog> b <blog> </blog> This is wrong test CASE.... it may be 3 a <blog> </blog> b <blog> </blog> c <blog> </blog> Edited by author 16.06.2014 08:57 finally I solved this using DC3 algorithm (a linear suffix array construction algoritm). it's supposed to run in O(n) time. my java solution runs in ~1.17 but my main language is scala and in scala (the escat same algorithm) is above 2 sec. is it possible to solve this with KMP faster? i couldn't find a correct solution. My solution is based on the next idea. When we check the current contestant we should know if there exists such vector x = (x0, x1, x2) that for every i = 1..n - 1 scalr product (v_i,x) > 0. I use simplex-method to solve this problem with such inequalities: (v_0, x) >= EPS (v_1, x) >= EPS ... (v_n-1, x) >= EPS x0 >= EPS x1 >= EPS x2 >= EPS x0 + x1 + x2 <= 1500 BUT I HAVE TLE on test 21. I couldn't improve my simplex-method implementation. Any who solved this problem using algebra, please, give me some hints. Thank you. Try to suppose that x0=1 Edited by author 21.09.2007 23:35 Oh, yeah!!! I've got ACCEPTED. Thank you Razdolbay from SIS. You've really helped me. Classic idea: 3d convex hull. Points inside- No,on the boundary -Yes. But implementation of effective 3d convex hull is'n easy. Having it done we will have effective voronoi diagrams and plenty of difficult timus problems admissible. Edited by author 09.10.2007 16:11 Additional! Simplex method is O(exp(n)) for bad tests. 3d convex hull is O(n*log(n)) in wast case. A got Ac 0.015 using convex hull but and it is important, in D2 and when body defined as halpfspaces intersection. Simply we may consider a:=a/(a+b+c), b:=b/(a+b+c),c:=c/(a+b+c) where a,b,c- length of distances and after use c=1-a-b projecting by the such way the problem from D3 to D2. Edited by author 31.12.2008 15:14 How to implement 3d convex hull in O(n*log(n))? The best idea, which I know is O(n^2)... Having it done we will have effective voronoi diagrams and plenty of difficult timus problems admissible. I have an quick hull algorithm implementation for an arbitrary dimensional space. Can you provide a list of the problems, which is suitable for application of the convex hull algorithm? In simple method errors are added and therefore difficult to use comparing with EPS. On this problem(I have Ac 0.015 using convex hull in D2) I fistly understood that combinatorial methods(intersection line and polygone) have big advanteges before simplex. I used simplex method above BigInteger/BigInteger in java- righly but very slow,simplex above double- impossible to make choice of EPS and got Ac from the first attempt using combinatorial approach. Why, using transformation of coordinates specified in a post svr, and doing the projection specified in the same place, we receive an equivalent problem? Points pass to external surfaces D3 of set in points at external edges D2 of projective set - is it right? Edited by author 24.10.2009 04:03 Of course. I am on line all times. That I said is true but much time is gone. I am Liability on my posts and soon you will have most detailed isue, wait some time, please. Edited by author 24.10.2009 19:59 I hope, I trust and I wait. Answer. This morning I have drinked cofee an remember. 1) h1/ai+h2/bi+h3/ci<h1/aj+h2/bj+h3/cj ~ h1*ai1+h2*bi1+h3*ci1<h1/aj1+h2/bj1+h3/cj1 where ai1=1/ai,bi1=1/bi,ci1=1/ci,aj1=1/aj, bj1=1/bj,cj1=1/cj. So first convertion is a:=1/a,b:=1/b,c:=1/c 2) h1*ai+h2*bi+h3*ci<h1/aj+h2/bj+h3/cj for all j is ~ to (ai-aj)*h1+(bi-bj)*h2+(ci-cj)*h4<0 for all j or Aj*h1+Bj*h1+Cj*h3<0. 3) Let Q=Aj+Bj+Cj(In my solution i accepted that Q!=0 if no then Cj=-Aj-Bj and so on.) Let Aj=Aj/Q;Bj=Bj/Q;Cj=Cj/Q. We have Aj*h1+Bj*h2+Cj*h3<0 or >0 and Aj+Bj+Cj=1. 4) ~ (Aj-Cj)*(h1-h3)+(Bj-Cj)*(h3-h3)< -Cj; 5) Let Qj=Aj-Cj;Sj=Bj-Cl;Rj=-Cj h1-h3=x1;x2=h2-h3 We have that D2 point (x1,x2) belong to internity of convex body satisfying system of inequalities Qj*x1+Sj*x2<Rj or >Rj. This is simmple D2 theory. Edited by author 27.10.2009 08:09 Edited by author 01.01.2010 15:46 Whether probably to write qhull algorithm for space of arbitrary dimension? How much it is difficult? Edited by author 05.01.2010 03:10 I'm using inclu-exclu. Start from B and then add and minus. But always WA#3. Any hints? Thansk, Ade Oops. I exclu. the primes. input 3 4 6 For this input what is the answer?And can you eplain me.I want to be sure that i understood correctly the task. Good problem, thanks to author! 4 5 1 196 6 10 1 4656 15 27 4 0 2 4 1 40 2 4 2 24 2 4 3 24 2 4 20 24 2 4 4 30 2 4 5 30 23 24 5 0 1 4 6 385 3 4 50 66 Edited by author 13.06.2014 14:08 What the main of this problem?I can't understand it.Help,help! #include<bits/stdc++.h> using namespace std; int horse[510],i; long long mem[501][501]; long long count(int index,int left) { if(index==i&&left==0) return 0; if((index==i&&left>0)||(index<i&&left==0)) return 1000000; if(mem[index][left]) return mem[index][left]; int v=0,j=0,k; long long mini=1000001; for(k=index;k<i;k++) { if(horse[k]) v++; else j++; mini=min(mini,v*j+count(k+1,left-1)); } return mem[index][left]=mini; } int main() { int j,k,l; cin>>i>>j; for(k=0;k<i;k++) cin>>horse[k]; cout<<count(0,j)<<endl; return 0; } You may run it on your own computer. Then you'll get the all answers. Then......Got AC!!! I ran the program for 2.5 hours in all!!! Yes, it was interesting to find all simple numbers in range 3 .. 65521 (There is only 6541 simple number in this range!) and calculate answer for each of them using SMART brute-force. It had taken only 17 minutes! And AC program weights about 91501 bytes! How to solve this problem by maths? Read "Introduction to Algorithms", chapter 33 - modular arithmetics, group generators, Lagrange theorem, etc. 17 minutes? What kind of so called "smart brute-force"? You can send to fujieyun@163.com to tell me your way. Thanks. Edited by author 09.09.2005 00:20 How did you reach this time? Ok. I submited it. My worked 27 sec. Vladimir Yakovlev(USU) 91501 bytes > 64000 bytes Where rejudge? P.S. I too got AC with cheating [ 38kb ]. I think 38Kb it's enough, because to solve this problem with cheating you need only one array [1..6541] of word constans. Please, send me your solution my E-mail: xujand000@rambler.ru for n are: 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 and 53 K : 2, 3, 5, 8, 11, 14, 15, 21, 27, 24, 35, 35, 34, 45 and 51 is right? for n are: 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 and 53 K : 2, 3, 5, 8, 11, 14, 15, 21, 27, 24, 35, 35, 34, 45 and 51 is right? Yes, it's right! Why the answer for 41 is 35? if k=35, then doomsday will be 22th attempt. but if k = 39, the repetition will be after 42 sleep. 1. "За один ход можно перевернуть одну фишку и все соседние по горизонтали или вертикали с ней." Instead of "или" should be used "и". ("vertically and horizontally") 2. "Предписания комбинации на переворачивание фишек, попадающих за пределы поля, игнорируются." Hard to understand. Most clear will be: "Если ход попадает в клетку на границе поля, переворачиваются только те фишки, которые находятся в его пределах". Первое - с точки зрения русского языка, в текущем варианте условия все верно. Как клетка может быть соседней одновременно по горизонтали И вертикали??? Второе - имхо, как раз в текущем варианте условия все более понятно. В вашем варианте нужно еще думать - что такое "ход попадает в клетку на границе". Вообще, не вижу смысла придираться к текстам задач уже прошедших соревнований, если текст задачи не вызывает неверное толкование. Тем более с такими спорными замечаниями. "Или" в данном условии можно трактовать как "перевернуть все соседние по горизонтали или перевернуть все соседние по вертикали", то есть можно перевернуть не все, а только по одному из направлений. Это первое место в условии, которое сбивает с толку. Второе добивает. Что конкретно нужно игнорировать: всю комбинацию, или только только те фишки из нее, которые не находятся на доске (то есть, не существуют – как их вообще можно не проигнорировать)? Вот вам неверное толкование. Я не придираюсь к условию, а стараюсь сделать сайт чуточку лучше. Чтобы понять условие, мне пришлось вытащить английскую версию страницы из кэша Google в другом браузере. Edited by author 11.06.2014 22:58 По поводу первого - фраза "ВСЕ соседние [по горизонтали или вертикали] с ней" достаточно однозначно указывает, что переворачиваются ВСЕ клетки, соседние с данной, причем соседство может быть по горизонтали ИЛИ вертикали. На всякий случай для тех, у кого трудности с интерпретацией русского - внизу приведена картинка хода. Ну и на самый последний конец: данная фраза вообще не очень-то и важна для понимания условия, потому что потом описывается другая (расширенная) задача. Оффтоп: если погуглить, фраза "по горизонтали или вертикали" встречается примерно в 10 раз чаще, чем аналог с "и". Так что, если вы решили реформировать русский язык - то почему именно с этой задачи? Второе: "Предписания комбинации на переворачивание фишек, попадающих за пределы поля, игнорируются". Здесь опять русский язык, почувствуйте разницу: не "Комбинация, содержащая фишки, попадающие за пределы поля, игнорируется", а "Предписания комбинации на переворачивание фишек, попадающих за пределы поля, игнорируются". То есть когда реализуемая комбинация предписывает перевернуть фишку за пределами поля - это предписание игнорируются. Чувствуете разницу? То-то нынче снизили минимальный проходной балл на ЕГЭ по русскому языку - народ вообще перестал чувствовать и любить язык, на котором писали Толстой и Достоевский. Умничайте сколько хотите, мне ваши до ваших выпадов дела нет. Если администрация считает, что условие предельно однозначное, то так тому и быть. the same question YES (Just got AC) I don't know how partisan can get AC In fact, sum(cost1+cost2+...) should be strongly greater than n*3 YES! STRONGLY GREATER ONLY!!! If you'll use >=, you get WA#3 or smth like that >_< I wish them publish more EXACT problem situations... >_> It says here: "the money Vadim had paid for him exceeded n rubles" Since I automatically just thought it had to be only greater or equal to N (because that sounds way more logical), I got WA at test #3 and I had no idea why. This is a programming problem, not a reading one - I think there should be more emphasis on the difficulty of *making the solution*, not on understanding the text and looking for small details hidden between hundreds of words. I know the task is very easy, but that doesn't mean making the statement look more complicated will balance things out. Of course, I wouldn't mind a long statement, as long as there is a recap of everything at its end. For example, something like "For a given integer N(1<=N<=2*10^9), integer M(0<=M<=3000) and M integers a[1,2...M] (1<=a[i]<=2*10^6 inclusive), print the index i for which (a[1]+a[2]+...+a[i])/3 > N. If there is no such index, print "Team.GOV!"" if the number of digits is greater than 100, should print "No solution" Thanks! Saved me a lot of time! :) First version give wrong answer on 1. Second version - OK. Why? What does 'system of bricks' (or 'система кирпичей' in russian statement) mean? #include <queue> #include <iostream> #include <set> #include <cstdio> #include <algorithm> #include <string> #include <map> #include <string> #include <sstream> using namespace std; bool k(long double x) { long double t=floor((sqrt(x))); if (t*t==x) { return true; } else return false; } int main() { long double n;
scanf("%lf",&n); long long c=n; if(k(n)) { cout<<1; return 0; }
for(long int i=1;i<=sqrt(n)/2+2100000;i++) { long double q=n-i*i; if(k(q)) { printf("%d",2); return 0; } } for(long int i=sqrt(n);i>=sqrt(n)-2100000;i--) { long double q=n-i*i; if(k(q)) { printf("%d",2); return 0; } } long long q = (long long)n; for ( int i = 0; i <20; i ++) { long long d = 1; for ( int j = 0; j < i;j++) { d*=4; if ( q > n) break; } if ( d > q) break; if( (long long)q % d==0) { long long temp = q/d - 7; if ( temp %8==0) { printf("%d",4); return 0; } } } printf("%d",3); return 0; } I think you want i<=sqrt(n/2) not i<=sqrt(n)/2. What is the solution for n = 10? Dmitriy, remember that the sum of angles of regular polygon is 180(n-2), where n is the number of it's angles. The radius of circle is the half of polygon's diagonal + 1.0. So the answer is 1.0/cos(pi*(n-2)/(2*n))+1.0, exceptions is 1, R will be 1. And don't forget about precision it must be at least 6 digits. If you still are having problems with it look at this: https://github.com/oybek/timus/blob/master/1984.cppThaks) Edited by author 16.12.2013 23:45 Edited by author 16.12.2013 23:45 1/sin(M_PI/n)+1 (except 1 and 2), but the real problem with WA5 is that cout does not work while printf("%.7f\n", a) does. Thanks!!! Java version: double res = N < 3 ? N : 1 / Math.sin(Math.PI / N) + 1; System.out.println(res); var n,r,c,i,k:integer; begin readln(k); write(' '); read(n); writeln; r:=0; for i:=1 to n do begin read(c); write(' '); if r<0 then r:=0; r:=r+c-k; end; if r<0 then writeln('0') else writeln(r); end. Do you know what's the test 29? Edit: got the AC. Edited by author 03.07.2012 14:20 ALSO WA#29, what's the point? Use the Microsoft Visual C compiler or use the "int64_t" type with GCC. My program that used the "unsigned long long" type with GCC was getting WA 29. Exactly the same program, with the Visual C compiler got AC. After changing from "unsigned long long" to "int64_t", I got AC also with GCC. I don't understand why... import java.util.*; public class Test_1874 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner s = new Scanner(System.in); int h, w, n; h = s.nextInt(); w = s.nextInt(); n = s.nextInt(); String[] a = new String[n]; for (int i = 0; i < n; i++) { a[i] = s.nextLine(); if (a[i].isEmpty()) { a[i] = s.nextLine(); } } if (n == 1) { System.out.println("1"); return; } int b, c = 0, d = 0, list = 0, page = 0; for (int i = 0; i < n; i++) { b = (a[i].length() + 1); if (i == 0) { c = a[i + 1].length(); if (b + c == w) { list++; } else if (b + c < w) { d = b + c; c = a[i + 2].length(); if ((d + c) == w) { list++; } else if ((d + c) < w) { } else { list++; } } else { list++; } } else { if ((b + d) == w) { list++; } else if ((b + d) < w) { d = d + b; c = a[i + 1].length(); if ((d + c) == w) { list++; } else if ((d + c) < w) { } else { list++; } } else { list++; } } if (list == h) { page++; list = 0; } else if (i == (n - 1)) { if(list>=1){ page++; }
} } System.out.println(page); } } //********************************************* //FreePascal 2.0.4 var a,b,u:longint; begin readln(a,b); for u:=1 to b do inc(a); writeln(a); end. //********************************************* //Visual C# 2010 using System; public class Sum { private static void Main() { string[] tokens = Console.ReadLine().Split(' '); Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } //********************************************* //Java 1.7 import java.util.Scanner; public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(sc.nextInt() + sc.nextInt()); } } import java.util.*; public class Test_1874 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner s = new Scanner(System.in); int n, k, m; n = s.nextInt(); k = s.nextInt(); long[] a = new long[k]; for (int i = 0; i < k; i++) { a[i] = s.nextInt(); } for (int i = 1; i < k; i++) { if (a[i] < a[i - 1]) { m = (int) a[i]; a[i] = a[i - 1]; a[i - 1] = m; } } m = (int) (n - (n - a[0]) - (n - a[1])); if (m <= 0) { System.out.println("0"); } else { System.out.println(m); } } } |
|