| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| Solution of the program | oybek | 1079. Максимум | 7 июн 2015 08:41 | 2 |
I decided to write post my solution and comment it, may be it will be useful for someone. So, you have recursively defined sequence. Of course first idea is to write recursive function. But, we need to find max element from 1 to n and if you will call function for every n in order to find maximum element, such algorithm will cost O(n^2). Another way is to store results gotten before in special array and compare gotten result with max of them. I hope I helped you at least as it. And here is accepted solution in C++: #include <iostream> #define max(a, b) ((a) < (b) ? (b): (a)) int last = 1; int mem[100000]; int max[100000]; int F(int n) { for (int i = last+1; i <= n; ++i) { if (i%2) mem[i] = mem[i/2]+mem[i/2+1]; else mem[i] = mem[i/2]; max[i] = max(mem[i], max[i-1]); } return max[n]; } int main() { mem[0] = 0; mem[1] = 1; max[0] = 0; max[1] = 1; int n; while (1) { std::cin >> n; if (!n) break;
std::cout << F(n) << std::endl; } return 0; } well done, bro.... :) here's another way... >> -------------------------------------------------------------------------------------- #include <iostream> using namespace std; int arr[100000]; int find_max(int n) { int maximum = 0; for(int i = 0; i <= n; i++) if(maximum < arr[i]) maximum = arr[i]; return maximum; } int main() { int n[11], i, idx; arr[0] = 0; arr[1] = 1; for(idx = 2; idx < 100000; idx++) { if(idx & 1) { // when idx is odd. i = (idx-1) / 2; arr[idx] = arr[i] + arr[i+1]; } else { // when idx is even. i = idx / 2; arr[idx] = arr[i]; } } i = 0; while(cin >> n[i], n[i++] != 0); i--; idx = i; for(i = 0; i < idx; i++) { cout << find_max(n[i]) << '\n'; } return 0; } ------------------------------------------------------------------------------------- Edited by author 07.06.2015 08:42 |
| Please help me to find the error | Md. Asif Imrul | 1000. A+B Problem | 6 июн 2015 16:58 | 3 |
I want to submit the solution in C language. What language I should choose from the option and what is the error in following coding:- #include <stdio.h> int main() { double a,b; scanf("%lf %lf",&a,&b); printf("%lf",a+b); return 0; } Edited by author 31.03.2015 20:19 Use integral type (int, long, long long) or set precision in output format string printf("%0.0lf",a+b); |
| WA16 | Malak | 2015. Женя переезжает из общежития | 6 июн 2015 15:53 | 1 |
WA16 Malak 6 июн 2015 15:53 Try this test: 1 0 0 0 1 1 1 0 Answer: You should rent the apartment #1 alone. |
| Язык(Фортран) | craft1k | | 6 июн 2015 14:25 | 1 |
Есть ли возможность сдавать задачи на языке Фортран |
| The problem description is very unclear: here is a clarification | Otrebus | 1121. Филиалы | 5 июн 2015 16:23 | 1 |
Each crossroads in the input is the binary OR of its branches, so a 5 (binary 101) at some crossroads in the input means there are branches 4 (100) and 1 (001) there. As for the output, for each crossroads where there are no branches (each 0, let's call this crossroads P), repeat this: Find the Manhattan (vertical+horizontal) distance to the closest branch from C. In the description, this closest distance is 2. Next, find all branches that lie on this exact distance from C. In the description, these are branches with number 16, 8, and 4. The output at location P should reflect all types of branches at distance 2 by ORing these numbers together, and in the description we get 28 (binary 10000 | 1000 | 100). |
| What Wrong? | WEE YING KIT | 1068. Сумма | 5 июн 2015 15:13 | 1 |
import java.util.Scanner; import java.io.*; public class HelloWorld { public static void main(String args[]) {
int a = 0; int total = 0; Scanner input = new Scanner(System.in); a = input.nextInt(); total = convertFunc(a); System.out.println(total); }
public static int convertFunc(int n){
int sum = 0; if(n > 0 && n <= 10000 ) { for(int i = 1 ; i <= n ; i++ ) { sum += i; } } else { for(int i = 1 ; i >= n ; i--) { sum += i; } } return sum; } } |
| 1001. Обратный корень(Wrong answer) Java | Сергей | 1001. Обратный корень | 5 июн 2015 12:49 | 2 |
import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.Scanner; public class Task1001 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); ArrayList<Long> list = new ArrayList<Long>(); for (int i = 0; i < 4 ; i++) { long a = scanner.nextLong(); if (a >= 0 && a <= 10E18) list.add(a); } DecimalFormatSymbols symbol = new DecimalFormatSymbols(); symbol.setDecimalSeparator('.'); DecimalFormat f = new DecimalFormat("#,##0.0000", symbol); for (int i = list.size(); i > 0 ; i--) { double c = (Math.sqrt(list.get(i - 1))); System.out.println((f.format(c))); } } } I need help please!!! Edited by author 04.04.2015 17:02 Well, maybe because you are checking it only for 4 Long values, It's working only for 4 exact values, not less, not more. Edited by author 05.06.2015 13:04 |
| Don't understand 1316 | danil123 | 1316. Биржа | 4 июн 2015 16:40 | 1 |
Problem was solved. Edited by author 04.06.2015 18:02 |
| Why wa 4? | bayram | 1658. Сумма цифр | 4 июн 2015 14:37 | 3 |
Make sure s1 and s2 are within the limits of the problem. ER, thank you! Thanks to author for challenging task. |
| WA4 | HusanKabulov | 1709. Пингвин-Авиа | 4 июн 2015 11:31 | 4 |
WA4 HusanKabulov 5 окт 2009 04:55 Please give me some tests Re: WA4 Oleg Strekalovsky [Retired] 16 окт 2009 21:26 I don't use any graphs algorithms,but only DFS. If you try to solve this problem like me do: 1) break(remove) all cycles 2)Store elements of graph,witch belong to different component's of graph. 3) Connect one of them with others. (one - to every). Not every to every!!! Test 6 1000000 1000000 010000 100000 000100 001000 000001 000010 Edited by author 16.10.2009 21:29 Is this one of the solutions to the above given test? 2000000 00a0a0 000000 a00000 000000 a00000 000000 Re: WA4 amomorning 4 июн 2015 11:31 |
| It is very easy, here is my solution | Dima_Philippov | 1581. Работа в команде | 4 июн 2015 09:13 | 3 |
var a, b : array[1..1000] of integer; n, i, k : integer; begin readln(n); for i := 1 to n do begin read(a[i]); end; i := 2; k := 1; while i <= n + 2 do begin if a[i] = a[i - 1] then begin k := k + 1; i := i + 1; end else begin write(k,' ',a[i - 1],' '); i := i + 1; k := 1; end; end; end. Please explain, why my cod has WT7 and your not) var a:array[1..1000] of integer; i,n,k:integer; Begin readln(n); for i:=1 to n do begin read(a[i]); end; k:=1; i:=2; while i<=n+2 do begin if a[i]=a[i-1] then begin i:=i+1; k:=k+1; end else begin write(k,' ',a[i-1],' '); i:=i+1; k:=1; end; end; End. Edited by author 26.11.2012 23:44 Edited by author 26.11.2012 23:44 #include <bits/stdc++.h> using namespace std; #define maxx 500 #define pb push_back #define pii pair<int,int> queue<int>qu; vector<pii>vpii[maxx]; #define inf 0x7fffffff int X[]={+2,+2,-2,-2,+1,-1,-1,+1}; int Y[]={-1,+1,-1,+1,+2,+2,-2,-2}; int main() { int n,u; cin>>n; vector<int>v; for(int i=0;i<n;i++) { cin>>u; v.pb(u); } int cnt=1,l; for(int i=0;i<v.size();i++) { if(v[i]==v[i+1]) { cnt++; l=v[i+1]; } else{ l=v[i]; cout<<cnt<<" "<<l<<" "; cnt=1; } } return 0; } |
| hint for c++ for those who got wa | TwoEightNine | 1348. Пусти козла в огород 2 | 4 июн 2015 00:19 | 2 |
you need to write answer with two digits after point, so don't use cout! use printf("%.2f\n", ); and don't forget #include <cstdio> i've been finding this mistake for 2 days!! or u can use cout<<setprecision(2)<<fixed<<; |
| WA #3 | Elias | 2034. Корованы | 3 июн 2015 23:30 | 1 |
WA #3 Elias 3 июн 2015 23:30 Does someone have any idea what's test 3? |
| Что тут не правильно? | Mesxi | 1820. Уральские бифштексы | 3 июн 2015 12:00 | 1 |
i understand problem !!! Edited by author 03.06.2015 12:14 |
| в условии ошибка | Иван | 1820. Уральские бифштексы | 3 июн 2015 02:21 | 5 |
если жарить 3 бифштекса на сковороде, где умещается всего 2, то потребуется не 3, а 4 минуты, поскольку последний бифштекс на 2 части не разделить и не положить на сковороду одновременно обоими сторонами хотя нет, в три минуты тоже можно пожарить и разрезать ничего не надо Edited by author 13.05.2014 01:30 Нумеруме бифштексы оригинально 1, 2 ,3. Жарим 1 и 2. Жарим вторую половину 1 и 3. Жарим вторые половины 2 и 3. Вуаля - вы программист! Так вот оказывается как котлеты надо жарить.... |
| Please help me. Why WE? | dood | 1230. Интроспективная программа | 3 июн 2015 00:29 | 1 |
java public class MainClass { public static void main(String[] args) { System.out.println("A=\"'\";B='A=\"\";B=;?$(B,0,4)+A+$(B,4,4)+A+B+A+$(B,8,37)';?$(B,0,4)+A+$(B,4,4)+A+B+A+$(B,8,37)"); } } |
| Help!WA#18 | Amandosov | 1348. Пусти козла в огород 2 | 2 июн 2015 23:31 | 3 |
This is my code #include <iostream> #include <stdio.h> #include <math.h> using namespace std; long n,x[201],y[201]; int main() {double xa,xb,xc,ya,yb,yc,l,a,b,c,x,h; cin>>xa>>ya>>xb>>yb>>xc>>yc>>l; b=sqrt((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya)); a=sqrt((xc-xb)*(xc-xb)+(yc-yb)*(yc-yb)); c=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); if(c!=0){ x=(c*c+b*b-a*a)/(2.0*c); h=sqrt(b*b-x*x); if(b!=0&&a!=0){ if((b*b+c*c-a*a)/(2.0*b*c)<=0) h=b; if((a*a+c*c-b*b)/(2.0*a*c)<=0) h=a;}
if(h<=l) h=0; else h=h-l;} else h=a; printf("%0.2f\n",h);
if(a>=b) {if(a<=l) h=0; else h=a-l;} else {if(b<=l) h=0; else h=b-l;} printf("%0.2f\n",h);
return 0; }
Please give me some test Попробуйте 2 2 2 2 3 3 1 Ответ: 0.41 0.41 My program gives the correct output for the test you gave, but still getting wrong answer on test#18. Any suggestions? |
| [removed] | dangminhhieu78 | 1107. Складская задача | 2 июн 2015 21:42 | 1 |
Edited by author 11.06.2015 18:48 Edited by author 11.06.2015 18:48 |
| test data for WA 2 ? | Tom | 1090. Теперь ты в армии | 2 июн 2015 12:10 | 4 |
pls give me some test data, dont know what s wrong with code. greetings. PLEASE NOTE what N and K represent;N represents colums and k represents rows. My code was wrong because of this;Hope you can get help. Thanks!!! I made such mistake :( |
| Why "wrong answer" (1001 - Ruby) | neverhood2015 | 1001. Обратный корень | 2 июн 2015 10:30 | 2 |
My code: a = readlines a = a.join a = a.split(/\s+/) a.reverse! a.map!{|elem|elem.to_i} a.map!{|elem|(elem**0.5).round(4)} puts a I've tried code from FAQ page: tokens = [] while string = gets do string.split().each do |token| tokens << token end end tokens.reverse.each do |token| puts (token.to_i ** 0.5).round(4) end Both variants return right results in my terminal, but in both cases i've got "wrong answer" here. Why? There was a problem with Ruby solutions judging. The solution from FAQ gets AC now. |