| Show all threads Hide all threads Show all messages Hide all messages |
| test 8 c# help please | Alexander_Real_Under | 1493. One Step from Happiness | 18 Jun 2024 20:27 | 1 |
my code using System; using System.Diagnostics; using System.Drawing; using System.Globalization; namespace Program; public static class Program {
public static void Main() { int number = Convert.ToInt32(Console.ReadLine()); string number_plus = Convert.ToString(number + 1); string number_minus = Convert.ToString(number - 1); char[] massiv_plus = number_plus.ToCharArray(); char[] massiv_minus = number_minus.ToCharArray(); string str_minus; string str_plus; while (massiv_minus.Length < 6) { str_minus = String.Join("", massiv_minus.Reverse()); str_minus += '0'; massiv_minus = str_minus.ToCharArray(); massiv_minus.Reverse(); } while (massiv_plus.Length < 6) { str_plus = String.Join("", massiv_plus.Reverse()); str_plus += '0'; massiv_plus = str_plus.ToCharArray(); massiv_plus.Reverse(); } int a1_plus = Convert.ToInt32(massiv_plus[0]); int a2_plus = Convert.ToInt32(massiv_plus[1]); int a3_plus = Convert.ToInt32(massiv_plus[2]); int b1_plus = Convert.ToInt32(massiv_plus[3]); int b2_plus = Convert.ToInt32(massiv_plus[4]); int b3_plus = Convert.ToInt32(massiv_plus[5]); int a1_minus = Convert.ToInt32(massiv_minus[0]); int a2_minus = Convert.ToInt32(massiv_minus[1]); int a3_minus = Convert.ToInt32(massiv_minus[2]); int b1_minus = Convert.ToInt32(massiv_minus[3]); int b2_minus = Convert.ToInt32(massiv_minus[4]); int b3_minus = Convert.ToInt32(massiv_minus[5]); if ((Math.Abs(a1_plus + a2_plus + a3_plus) == Math.Abs(b1_plus + b2_plus + b3_plus)) || Math.Abs(a1_minus + a2_minus + a3_minus) == Math.Abs(b1_minus + b2_minus + b3_minus)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } |
| Hint | InstouT94 | 2126. Partition into Teams | 17 Jun 2024 14:22 | 1 |
Hint InstouT94 17 Jun 2024 14:22 Lucas theorem, O(p * log(n)). |
| To admins 2 | andreyDagger`~ | 1163. Chapaev | 15 Jun 2024 04:18 | 1 |
|
| To admins | andreyDagger`~ | 1163. Chapaev | 15 Jun 2024 03:47 | 1 |
Admins, please add this to statement: "The coordinates are given with no more than 6 digits after a decimal point |
| Overrated | Hououin`~`Kyouma | 1061. Buffer Manager | 12 Jun 2024 00:47 | 1 |
|
| why my recursive solution is giving WA??? | Suparna | 1079. Maximum | 11 Jun 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. Stone Pile | 11 Jun 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. Integer-valued Complex Determinant | 11 Jun 2024 01:58 | 1 |
WA19 andreyDagger`~ 11 Jun 2024 01:58 2 0 0 1 0 1 0 0 0 5 0 Possible answer: -1 0 |
| intuition | classenemy | 1009. K-based Numbers | 10 Jun 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. Lucky Tickets. Easy! | 3 Jun 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. esreveR redrO | 1 Jun 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. Sandro's Book | 1 Jun 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. Product of Digits | 1 Jun 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. Frequent Flyer Card | 31 May 2024 19:20 | 1 |
TEST anotherworld 31 May 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. Barber of the Army of Mages | 30 May 2024 21:13 | 1 |
|
| What is test 7? | So Sui Ming | 2123. Knapsack | 29 May 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. Factorials!!! | 29 May 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. Cups Transportation | 28 May 2024 23:12 | 1 |
hint -`~ 28 May 2024 23:12 binsearch + dijkstra works but with naive dijkstra |
| test 2 isnt test 2 | -`~ | 1155. Troubleduons | 27 May 2024 00:35 | 1 |
|
| Great task | Hououin`~`Kyouma | 1358. Cables | 26 May 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 |