| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| Overrated | Hououin`~`Kyouma | 1061. Диспетчер буферов | 12 июн 2024 00:47 | 1 |
|
| why my recursive solution is giving WA??? | Suparna | 1079. Максимум | 11 июн 2024 21:50 | 2 |
int main() { long int n,res; while(1){ scanf("%ld",&n); if(n!=0){ if(n%2==0){ res=function(n-1); printf("%ld\n",res); } else{ res=function(n); printf("%ld\n",res); } } else{ return 0; } } //gives right ans in codeblocks but here gives WA....Why?? return 0; } long int function(long int n){ if(n==1){ return 1; } if(n%2==0){ return 1; } else if(n%2==1){ return function(n/2)+function(n/2+1); } } you have to print the maximux number of n range.but in recursive formula it alawys give the n th value . n th value and maximum value of n range is not same |
| How to apply DP??? | Saikot | 1005. Куча камней | 11 июн 2024 13:19 | 2 |
Can somebody tell me how to implement dp for this probelm? dp cant be applied to every problem Can somebody tell me how to implement dp for this probelm? |
| WA19 | andreyDagger`~ | 1845. Целочисленный комплексный определитель | 11 июн 2024 01:58 | 1 |
WA19 andreyDagger`~ 11 июн 2024 01:58 2 0 0 1 0 1 0 0 0 5 0 Possible answer: -1 0 |
| intuition | classenemy | 1009. K-ичные числа | 10 июн 2024 21:04 | 1 |
When N=0, no number is there, or 0 is there. a[0]=1 When N=1, there are k such numbers, or 1..k-1. a[1]=k-1 When N=2, there are k^2-k such numbers. a[2]=>k^2-k =>(k-1)k =>(k-1)(k-1+1) =>(k-1)(k-1)+(k-1)*1 =>(k-1)a[1] + (k-1)*a[0] which can be used for all subsequent digits |
| Precalculate is not needed | Pearl | 1044. Счастливые билеты. Easy! | 3 июн 2024 00:51 | 2 |
#include <iostream> using namespace std; int sumDigit(int n) { int sum = 0; while (n) { sum += n % 10; n /= 10; } return sum; } int main() { int n; cin >> n; if (n % 2 == 1) { cout << 0; } else { // We need to choose at most 4 digits, so the largest digit sum is 9*4 int count[9*4 + 1] = {0}; int halfN = n / 2; int maxNum = 9; for (int i = 1; i < halfN; ++i) { maxNum *= 10; maxNum += 9; } // Count the ways to create a particular sum for (int i = 0; i <= maxNum; ++i) ++count[sumDigit(i)]; // Now, for each number i whose digit sum are s, there are // count[s] numbers (including i itself) have the sum s. // So we have count[s] ways to choose the second half. int result = 0; for (int i = 0; i <= maxNum; ++i) result += count[sumDigit(i)]; cout << result; } return 0; } thanks a lot.It was really helpful |
| Read input until the end in C/C++ | Hristo Nikolaev (B&W) | 1226. йынтарбО кодяроп | 1 июн 2024 22:02 | 2 |
Reading the entire input char by char can be done quickly this way: while ((input = (char)getchar())) { if (input == EOF) { break; } The canonical way is: while ((input = std::getc()) != EOF) { ... } |
| The Power of C# | Hikmat Ahmedov | 1723. Книга Сандро | 1 июн 2024 21:15 | 7 |
/* ALGORITHM: In any substring that is encountered the most, at least one letter of that substring should be encountered the same time as the substring. So, we just need to find the most encountered symbol in the string. */ using System; using System.Linq; class Program { static void Main() { Console.WriteLine((from u in Console.ReadLine().ToArray() group u by u into gg orderby gg.Count() descending select gg.Key).ToList()[0]); } } Power of Python :) from collections import Counter print(Counter(input().strip()).most_common(1)[0][0]) Power of C/C++ int main() { //shitcode_fiveloops } // AC :) #include <The Power of me!> int main() { ThePowerOfMe.makeItAC(); } ...AC!:) Edited by author 25.04.2014 16:46 I think that one line could be enough. Console.WriteLine(input.GroupBy(c => c).OrderByDescending(g => g.Count()).First().Key); // the power of C++ :) #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { string s; cin >> s;
vector<int> v(30, 0); for (int i=0; i<s.size(); ++i) { ++v[s[i]-'a']; } auto c = distance(v.begin(), max_element(v.begin(), v.end())); cout << (char)('a'+c); return 0; } Slightly shorter C++ version of Raphael: #include <algorithm> #include <cstdio> int main() { size_t v[26]{}; char c; while ((c = std::getc(stdin)) != EOF) ++v[c - 'a']; std::putc(static_cast<char>('a' + std::distance(v, std::max_element(v, v + 26))), stdin); return 0; } Edited by author 01.06.2024 21:37 |
| Some hints | Sayem | 1014. Произведение цифр | 1 июн 2024 18:47 | 3 |
The authors should've mentioned these in the question. Like if q is 0 then you should print 10 but if it is any number between 1 to 9 then you should print that number only, i.e. 2 for 2, 4 for 4 not 14 for 4. Thanks, that saved me a lot of time. I was printing 0 for 0. Which makes sense in my opinion. thanks to you .It was really helpful |
| TEST | anotherworld | 1887. Карта постоянного пассажира | 31 май 2024 19:20 | 1 |
TEST anotherworld 31 май 2024 19:20 13 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ans: 31.513956103964 |
| compiler error | rvess | 1774. Парикмахер армии магов | 30 май 2024 21:13 | 1 |
|
| What is test 7? | So Sui Ming | 2123. Рюкзак | 29 май 2024 19:03 | 2 |
WA on test 7. I've used uint64_t in array and sum, and int64_t in result. Corner case of sum = 0 is taken care of. Regards, So Sui Ming even signed long long should work fine. try to find error in your solution |
| Why "Wrong Answer" | Tanjila Hossain | 1083. Факториалы!!! | 29 май 2024 14:49 | 2 |
what is wrong with my program? I used Python code below: n = input() list = n.split() n = int(list[0]) k = len(list[1]) if (n < k): p = k else: p = n
i=2 num = n - k if (n>=1 and n<=10) and (k>=1 and k<=20) and (num > 0): if((n%k) == 0): while(num>k): p = p*num num = n-i*k i=i+1 p = p*k else: while(num>(n%k)): p = p*num num = n-i*k i=i+1 p = p*(n%k) print(p) Edited by author 17.06.2022 20:39 Don't confuse it, (n mod k) or k are not the final factors!! skip these lines p = p*k and p = p*(n%k) |
| hint | -`~ | 1379. Транспортировка кружек | 28 май 2024 23:12 | 1 |
hint -`~ 28 май 2024 23:12 binsearch + dijkstra works but with naive dijkstra |
| test 2 isnt test 2 | -`~ | 1155. Дуоны | 27 май 2024 00:35 | 1 |
|
| Great task | Hououin`~`Kyouma | 1358. Провода | 26 май 2024 21:19 | 3 |
It would be interesting to solve such a problem on an arbitrary graph (not a tree) or to say that there is no solution for such a graph. it is well known problem. but its hard to implement. You should find a clique of size 5 or complete bipartite subgraph with size (3, 3). There is no solution if and only if there exist such subgraph or topologicaly equal to that(other vertex can adjust 2 dif. vertexes of such subgraph). I took lectures about that a long time ago. Can't find source now. Edited by author 26.05.2024 21:22 |
| No subject | Vlad | 1086. Криптография | 26 май 2024 06:12 | 1 |
Edited by author 26.05.2024 06:13 |
| Some things to look after | classenemy | 2115. День знаний | 25 май 2024 21:49 | 1 |
These are some of the things I had to overcome: 1)Testing on something like: 6 5 5 1 1 2 2 and 6 5 5 1 1 1 2 2)There cant be 2 out of place pairs in the ascending/descending order 3)Swapping elements across all pairs Hope this helps someone. |
| My solution (RUS/ENG) (Accepted) | Vladislav_Kucherenko | 1348. Пусти козла в огород 2 | 25 май 2024 21:16 | 1 |
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int x1, y1, x2, y2, x0, y0, l; cin >> x1 >> y1 >> x2 >> y2; cin >> x0 >> y0 >> l; cout << fixed << setprecision(2); // <|ENG: Set 2 symbols after dot |> <|RUS: stavim 2 simvola dlia tochki |> //<|ENG: get all sides |> //<|RUS: poluchaem vse storonui |> double firstEdge = sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2)); double secondEdge = sqrt(pow(x2 - x0, 2) + pow(y2 - y0, 2)); double field = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); double ans2 = max(firstEdge, secondEdge) - l; // <|ENG: Second answer - max length |> <|RUS: Vtoroi otvet = prosto maximum do krainih tochek |> double ans1; //<|ENG: get the squares of the sides|> //<|RUS: Vosvodim v kvadrat storonui |> double a = firstEdge * firstEdge; double b = secondEdge * secondEdge; double c = field * field; //<|ENG: checking if there are obtuse angles on the side that is the pineapple field |> //<|RUS: Proverka est li typie ygli vosle toi storoni kotoraiy iavliaetsia polem c ananasami |> if (a+c < b || b+c < a) { ans1 = min(firstEdge, secondEdge) - l; } else { //<|ENG: get half the perimeter of triangle|> //<|RUS: poluchaem poly perimetr treygolnika |> double p = (firstEdge + secondEdge + field) / 2; //<|ENG: get square of triangle|> //<|RUS: poluchaem ploshad treygolnika |> double S = sqrt(p * (p - firstEdge) * (p - secondEdge) * (p - field)); //<|ENG: If the area is zero and the field with pineapples does not exist (test: 2 2 2 2 3 3 1)|> //<|RUS: Esli ploshad ravna 0 i polia c ananasami kak bu net (test: 2 2 2 2 3 3 1)|> if (S == 0 && field == 0) { ans1 = min(firstEdge, secondEdge) - l; } //<|ENG: If the area is zero and more than one side is not zero (test: -5 0 5 0 1 0 1)|> //<|RUS: Esli ploshad ravna 0 i ni odna storona ne ravna 0 (test: -5 0 5 0 1 0 1)|> else if (S == 0 && firstEdge != 0 && secondEdge != 0 && field != 0) { ans1 = 0; } else { //<|ENG: Default. We just look for the height using the formula|> //<|RUS: Obichni slychai. Prosto po formule S = a*h/2 (test: -5 0 5 0 1 0 1)|> double d = 2 * S / field; ans1 = d - l; } } //<|ENG: If, after subtracting the rope, the length becomes negative, then do 0|> //<|RUS: Esli sle vichetania verevki otvet stal menihe nylia to delayem 0|> ans1 = ans1 < 0 ? 0 : ans1; ans2 = ans2 < 0 ? 0 : ans2; //<|ENG: Next just cout "round(ans1 * 100) / 100" and "round(ans2 * 100) / 100"|> //<|RUS: Teper prosto vivedi "round(ans1 * 100) / 100" i "round(ans2 * 100) / 100"|> //!!!!!!!!!!!!!!!!!!! //cout << round(ans1 * 100) / 100 << endl; //cout << round(ans2 * 100) / 100; return 0; //<|ENG: Thanks a lot for your time here!|> //<|RUS: Spasibo chto pochitali i uia vam pomog (navernoe)|> // :) } |
| Hint: think if sum even or odd | denxxjkee | 1924. Четыре чертёнка | 25 май 2024 20:42 | 1 |
|