The Curious Cat
googling the error directed me to irrelevent results
Anonymous
A hint is sufficient 😅 I want to finish the thing on my own
n <= 9. So we expect at least exponential complexity. Brute force (factorial complexity (n * n!)) is good enough. You can try dynamic programming.
Kaddy
n <= 9. So we expect at least exponential complexity. Brute force (factorial complexity (n * n!)) is good enough. You can try dynamic programming.
I have been told that the ideal time complexity is O(n^2 * 2^n) and that's what I'm aiming for Although brute force works well, I'm looking to optimize it
Kaddy
Yeah. Try dynamic programming.
Anything in particular I should look for?
Anonymous
https://gist.github.com/4a0189d3ce69026a630e5f9807d6c8da would this be correct for a copy/move constructor dealing with memory allocation?
Anonymous
Anything in particular I should look for?
Bitmasking dynamic programming. You can google it.
Anonymous
Anything in particular I should look for?
You can also see https://www.geeksforgeeks.org/bitmasking-and-dynamic-programming-set-1-count-ways-to-assign-unique-cap-to-every-person/
Kaddy
Oh interesting, I'll check this out. Thanks a lot
Kaddy
BTW this problem is in a way a modification of the Travelling Salesman Problem 😃
Pavel
https://gist.github.com/4a0189d3ce69026a630e5f9807d6c8da would this be correct for a copy/move constructor dealing with memory allocation?
Copy function looks correct to me. The move operations concern me: First - where is your destructor? Second - in your move constructor you swap with uninitialized values, you probably want to null them in the declaration (to make sure they are always not garbage), and = default your default constructor.
Kamal Kumar
if (s.contains(val) && val == (int) s.toArray()[s.size() - 1])
Kamal Kumar
if (s.contains(val) && val == (int) s.toArray()[s.size() - 1])
why we are checking condition after && to check whether an element exist in hashset or not
The Curious Cat
Why is ">c99 -Wall..." returning "invalid argument `all' to -W" in macos terminal ?
using "gcc -Wall..." is not giving the same error but "c99 "is showing error on -Wall
Sandeep
For(auto x: A)... A is an array ..
Sandeep
What are the pre requisite for this to work properly
Pavel
What are the pre requisite for this to work properly
It depends on definition of "properly". It won't compile if the elements of the array are not copyable. You probably don't want a loop like this if elements of the array are expensive to copy (need const auto& or auto&& instead).
Pavel
Or array means C-style array?
Sandeep
The array is passed to a function
Pavel
The array is passed to a function
Can you provide the code?
Sandeep
vector<Long Long> findMissing (Long Long A[], Long Long B[],int N, int M) unordered_map<int, int> sandy; vector<Long Long> ans; for (auto x:A) { sandy[x]++; } for (auto y:B) { if(!sandy[y]) { ans.push_back(y); } } return ans; } };
Pavel
vector<Long Long> findMissing (Long Long A[], Long Long B[],int N, int M) unordered_map<int, int> sandy; vector<Long Long> ans; for (auto x:A) { sandy[x]++; } for (auto y:B) { if(!sandy[y]) { ans.push_back(y); } } return ans; } };
Ok, in this case A can't be used in ranged for loop directly because it doesn't have begin() and end() methods, what you can do is wrap it in std::span (if you use C++20).
Anonymous
https://gist.github.com/7ca07290c4eb4b74721e12c97655a712 how is this any different from what new does?
Ammar
https://gist.github.com/7ca07290c4eb4b74721e12c97655a712 how is this any different from what new does?
I haven't tested it, but questions from me. This expression data[i].T();. What function to be called? A function named T? Or the templated object's constructor? How is the semantic rule for that?
Pavel
https://gist.github.com/7ca07290c4eb4b74721e12c97655a712 how is this any different from what new does?
I'm not sure if this work as you expect data[i].T(); You probably need placement new here, something like new (data[i]) T();
Pavel
Also I'm not sure about whether will this code satisfy alignment rules for any structures (not an expert in this topic)
Pavel
Does this new expression require to be delete'ed?
Depends on whether it normal new or placement new. For placement new you can do it in this order malloc placement new // have a normal object here explicit destructor call free
Ammar
templated object's constructor
I don't find it works that way though.
Ammar
<source>: In instantiation of 'void doInit() [with T = Test]': <source>:31:14: required from here <source>:21:25: error: 'class Test' has no member named 'T' 21 | data[i].T(); | ~~~~~~~~^ https://godbolt.org/z/e1nxnKWoM
Anonymous
ok
Vitrag
#include<iostream> using namespace std; int main() {  int eid; char ename[100];  float basicSalary, hra, da, i_tax, net_salary;  cout<<"\n Enter Employee Id : ";  cin>>eid;  cout<<"\n Enter Employee Name : ";  cin>>ename;  cout<<"\n Enter Basic Salary : ";  cin>>basicSalary;  hra = 800;  da = 0.25 * basicSalary;  i_tax = 0.15 * basicSalary;  net_salary = basicSalary + da + hra - i_tax;           cout<<"\n ----------------------- ";  cout<<"\n Employee Id    : "<<eid;  cout<<"\n Employee Name  : "<<ename;  cout<<"\n Basic Salary   : "<<basicSalary; cout<<"\n HRA            : "<<hra;  cout<<"\n DA             : "<<da; cout<<"\n I-Tax          : "<<i_tax;  cout<<"\n Net Salary     : "<<net_salary;                  return 0; }
Vitrag
What's your concern?
its been compiling since 2 hrs.
Vitrag
???
Ammar
its been compiling since 2 hrs.
What do you mean? What compiler do you use?
Ammar
It compiles just fine on Godbolt. https://godbolt.org/z/8zaM9MYr3
Vitrag
It compiles just fine on Godbolt. https://godbolt.org/z/8zaM9MYr3
https://play.google.com/store/apps/details?id=com.kvassyu.coding.cpp
Vitrag
ii use this
Ammar
https://play.google.com/store/apps/details?id=com.kvassyu.coding.cpp
Use widely used compiler. Your code is totally fine with respect to "can be compiled".
Ammar
which compiler i must use then for android
For Android, I recommend you to install Termux, then install clang inside the Termux. So you can have full control over your compiler flags and command line. It's great.
Ammar
How to install clang inside it
apt-get update -y; apt-get install clang;
Kaddy
Yup 😁
Ahh I gave that problem a lot of thought. Can't figure it out. Can you help me a little more 😭
Grigory
Hello. I am doing a small project in c++ for storing (editing) records. I would like a bit of a general advice on how to handle optional fields. For example an optional string or integer field that may not be initialized. How would I express it in a type safe way, so that I must check if the field is present before using it?
Kaddy
Where you cannot figure it out?
I mean I thought about it along the lines of DP and the g4g thing but can't figure out an algo for the problem which I sent 😣
Anonymous
You just need to write a recursive brute force algorithm with bitmasking mind. Then cache it to get O(2^n * n * n) time complexity. You have a set of n integers 1, 2, 3, .., n initially. The basic idea is 1. First, you pick a integer and remove it from the set. 2. repeat step 1 until the set get empty. Obviously, you have n! possibility of choice. The recursive solution is to emulate the process. Each step, you execute this function int cheapest_permutation(int set, int prev); where set is the set of the remain integers, prev is the integer you picked last time. In the function, you picked a integer i from set, try to minimize cheapest_permutation(set ^ (1 << i), i) + A[prev][i] where 1 <= i <= n and set & (1 << i) == 1.
Anonymous
I mean I thought about it along the lines of DP and the g4g thing but can't figure out an algo for the problem which I sent 😣
If you think it is difficult to do bit tricking. you can use a bool container to denote the set. Remember to avoid copy the container otherwise you will get greater time complexity.
Anshul
class Node { public: int data; Node *prev; Node *next; Node(int data) { this->data=data; prev=NULL; next=NULL; } }; whats the problem with this code, it says NULL wasn't declared in this scope. i have underlined the error line
Anshul
for this line "next=NULL;" it doesn't show any error, then why it shows error for "prev=NULL;"
Anonymous
your problem is you said something null you must do that in class
Anshul
?
Anshul
thanks
Anshul
it worked now
Anonymous
it worked now
or, since you are using C++, use nullptr
Anonymous
further, i would suggest using std::unique_ptr instead of a normal pointer since no two lists should own the exact same node
mito
can auto recognize custom data types in C++ ?
Anonymous
What are these
https://docs.microsoft.com/en-us/cpp/cpp/smart-pointers-modern-cpp
Anonymous
can auto recognize custom data types in C++ ?
depends. struct lol { int i = 0; }; lol fn() { return {}; } int main() { // auto var = { 5 }; // doesn't work auto var = lol{5}; // works auto var = fn(); // works }