C++ :: Maximum Numbers Of Elements That Can Be Eliminated From A Set Of Sets?
Nov 17, 2014
I have come across a problem lately. You are given a set of n sets with m variables.. for instance {a,b,c,d}, {b,c,d}, {b,c}, {c,e,f}, {e,f}. And you want to eliminate elements from these sets with the restriction that you can only eliminate one item from each set and each item can only be eliminated from one set (i.e. if you've eliminated b from set {a,b,c,d}, then you cannot eliminate it from {b,c,d}). The problem is writing an algorithm which determines the maximum number of elements you can eliminate. And I'm hopelessly stuck... of course, you could backtrack it and determine this number but I feel it could be done more efficiently..
View 2 Replies
ADVERTISEMENT
Sep 10, 2013
Supposing you have a 3 or more overlapping arrays (arrays having elements in common), and you wish to select 2 or more of the arrays with the maximum number of elements but less overlap as compared to the rest of the overlapping arrays.
Eg. A[4],B[6],C[5]. A+B contains 10 elements but say the overlapping element is 3, meaning it has 7 unique element.
Also B+C=11 elements , but supposing it has 5 overlaps, it would mean it has only 6 unique elements. A+B+C=15. Supposing the overlaps are 11 then it means the unique elements are 4. Ect. So per the example, the best array options with most unique element would be A+B .
View 4 Replies
View Related
Jan 25, 2014
I'm new to C++ and I'm trying to solve the question but there is just something wrong somewhere.
#include <iostream>
using namespace std;
int main() {
int largest;
int a;
int b;
int c;
cout<< "Enter first value";
[Code] ....
View 1 Replies
View Related
Dec 6, 2013
I need to write a program that not only calculates the minimum and maximum, but also calculates the average and the difference between the largest and the smallest.
Here's the code:
#include <iostream.h>
#include <conio.h>
#inlcude <math.h>
#include <windows.h>
[Code].....
I know the problem is the "sdt::cin" but I don't know what else to do
View 1 Replies
View Related
Aug 5, 2014
user enter four number and the output will be the greatestt number among these
View 1 Replies
View Related
Oct 25, 2014
The question is: Write a program that reads 3 integer numbers, then finds and prints the: Mean - Maximum & Second Minimum.
#include <iostream>
using namespace std;
int main () {
double a, b, c;
cout<< "Please enter three values"<<endl;
[Code] .....
View 6 Replies
View Related
Jan 22, 2013
I want to finding maximum and minimum values of 10 numbers using for loop and the program work wrong !!
#include <iostream>
using namespace std;
int main() {
int x;
int max = -999999999;
int min= 999999999;
[Code] ....
View 2 Replies
View Related
Feb 9, 2014
I can't compile this code as I am at work and the computers are security protected, So i''l have to wait until i get home to test this, but I am pretty sure I am wrong. The problem is I have to create two vectors with 10 elements and input random numbers into it, then pick one of the elements of the second vector at random and append it to an element from the first vector at random. This has to be done 10 times and the I am assuming i have to print the 10 results. This is what I have:
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
vector<int> random (10);
[Code] ....
View 11 Replies
View Related
Jan 10, 2013
I have to complete a project that i want to read float numbers from keyboard and store them into an array of 10 elements.! Every time that a number stored into array i want to compare with previous one if they have +-10 difference .. I want to keep only 10 elements into my array so every time that i give value a[0] replace a[1], a[1] replace a[2],a[2] replace a[3]. . . .and a[10] deleted.. So when all elements of the array are similar with +-10 values print out the array.!
View 1 Replies
View Related
Oct 18, 2014
How can I declare a set of strings that i want to be ordered by a boolean function Comp? Like the one you would write in
sort(v.begin(), v.end(), comp);
I tried
set<string, Comp> S;
but it doesn't work
And the same question for priority queues, can you specify the function you want your elements to be sorted by?
View 4 Replies
View Related
Apr 18, 2014
I have a vector of sets in which I wish to remove a set from the vector, if it contains a certain value, is there any way of doing this?
for(int j = 0; j <= clauseVector.size(); ++j){
if(clauseVector[j].find(find) != clauseVector[j].end())
std::cout << "FOUND: " << propagator << "
";
}
}
This is what I have been using to find the element, but is there a way to remove the set that contains the element?
If needed I can include the full code
View 11 Replies
View Related
Nov 5, 2013
Night now I'm working on part of a function that scans in two sets of coordinates. Is there a way I can scan both sets of coordinates in with the same scanf?
ex. scanf("%d%d%d%d," &destroyer_1, &destroyer_2, &destroyer_3, &destroyer_4)
but that didn't work...
Code:
printf("What are the first coordinates for destroyer:
");
scanf_s("%d%d", &destroyer_1, &destroyer_2);
gameboard[destroyer_1][destroyer_2] = 'd';
printf("What are the second coordinates for destroyer:
[Code] .....
View 5 Replies
View Related
Apr 24, 2013
Ok so I am currently trying to add and subtract two sets of integer arrays. When I run my program, the program does not subtract the numbers from the first set with the numbers from the second set. Could anyone here take a look at my code and help me figure out what the problem is?
#include <iostream>
#include "SafeArray.h"
using namespace std;
[Code].....
View 1 Replies
View Related
Jan 5, 2014
I have two std::sets S1 and S2 which I need to merge.
I know that the largest element of S1 is less than the smallest element of S2.
the additional information about S1 and S2 should enable me to do the insertion of each element in costant time instead of log(N).
what is the fastest way to calculate the union of the two sets?
View 6 Replies
View Related
Apr 18, 2014
I have a vector of sets, which I am removing any element which contains a certain value. For example, if I was looking for 2:
[0] 1 2 3
[1] 4 5 6
After the program was run, I would be left with just [0]4 5 6.
This is the code I have been using
auto iter = std::remove_if( clauseVector.begin(), clauseVector.end(),[propagator] ( const std::set<int>& i ){
return i.find(propagator) != i.end() ; } ) ;
clauseVector.erase( iter, clauseVector.end() ) ;
I want to know, is there any way I can tweak this code so that it only removes one part of the set rather than the whole thing. For example with above example, I would be left with
[0] 1 3
[1] 4 5 6
View 4 Replies
View Related
May 30, 2013
So I'm attempting to write a program that will parse through a large file (genome sequences) and I'm basically wondering what options I should consider if I wanted to either:
a) store the entire genome in memory and then parse through it
b) parse through a file in small portions
If I go with "a", should I just read a file into a vector and then parse through it? And if I go with "b" would I just use an input/output stream?
View 5 Replies
View Related
Jul 3, 2012
I've recently started to learn C++ and I'm using codeblocks as my IDE, but I keep getting problems with AVG free edition picking up random pieces of code as Trojans ?! I've put an example of some code that sets it off below, and the error message I get. Is there anyway I can set AVG not to trigger with any codeblocks coding I've done? I guess I could tell AVG not to trigger for that folder, if that's even possible?
Code:
#include <iostream>
using namespace std;
class MyClass{
public:
void coolSaying(){
cout << "BUST A MOVE!!" << endl;
[Code] ....
Error I get:
File name: h:DesktopC++ projectsclasses and objects 1 inDebugclasses and projects 1.exe
Threat name: Trojan horse Agent3.BMSZ
Detected on open.
View 14 Replies
View Related
Feb 17, 2014
The program is to find intersection,union and difference of two sets. The program take the input correctly but after it crashes with the message that some exe is not working...
Code:
#include<iostream>
using namespace std;
void Input(int *A, int*B, int size1, int size2)
//input function {
[Code] ....
View 3 Replies
View Related
Nov 14, 2013
I'm currently writing a program and a portion of it needs to have a function that computes the result of a formula for two sets of inputs. It then has to calculate and display the difference between the two results.
I have code that takes the input from the user and converts it to the type that I need. In this case we are talking about latitudes and longitudes that will be converted to degrees, then to xyz coordinates.
View 1 Replies
View Related
Sep 20, 2013
I have this code that determines the amount of people that can fit on some trains in different train combination scenarios. Here is the code:
#include<stdio.h>
#include<stdlib.h>
int main(void) {
int total_track, max_train_length, num_people, num_trains, tl;
printf("What is the total length of track, in feet?
[Code] ....
I need to now "pick the winner," or the highest value for num_people computed. How would I go about this and why?
View 6 Replies
View Related
Jul 26, 2014
Suppose that a map is defined thus: map<sttring, int> mymap;
I wanna find k maximum values. Is there a way to find the maximum value in an efficient manner? Or else, How can I sort them and then find the k first elements?
View 1 Replies
View Related
May 23, 2013
Is there a maximum capacity for stdin ?
View 2 Replies
View Related
Mar 12, 2014
I got a code written in Java. But, I gave up writing code in Java. The program written is supposed to find the maximum subsequence sum. It's originally like this.
Code:
private static int maxSumRec (int [] a, int left, int right)
{
if(left == right)
if(a[left > 0])
return arr[left];
[Code] .....
I turned it into C, add some elements (to generate random numbers and change some variables' names), and becomes like this
Code:
int maxSumRec (val, left, right)
{
int x;
long int arr[val];
srand ( time(NULL) );
for(x=0; x<val; x++)
[Code] .....
It fails to compile. What have I done wrong? And I keep wondering why in the original code there is left and right variables and their values are never assigned. My c compiler (I use codeblocks) keeps telling me that. Idk why. My friend who keeps it in Java says it is fine but he cannot explain how his program works. What *is* left and right actually?
View 8 Replies
View Related
Jan 4, 2015
I wrote a program to find the minimum and the maximum values from a vector. It works fine. What I'm trying to do is show the positions of said values and it's not working quite right. When I insert 4 elements: 2 0 1 3 it says:
"The min and max are 0 and 3
The position of the min is: 01
The position of the max is: 03"
What am I doing wrong? Here is the code:
Code:
#include <stdio.h>
#include <conio.h>
int main() {
int A[10], i, j, n, min, max, C[10], k=0, D[10], l=0;
printf("Insert no. of elements in vector A
[code]....
View 6 Replies
View Related
Oct 29, 2014
Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.
In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
[Code].....
View 10 Replies
View Related
Sep 10, 2013
I am working on a couple C++ projectsfor my class. On one of my projects I get this error "identifier not found" for maximumValue. here is the code that I have done. I have got almost all the code from my text book..
// Three numbers.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
// demonstrate maximum int value
int int1, int2, int3;
[Code] .....
View 5 Replies
View Related