C++ :: 250000 Numbers - List Of Subsets
Mar 7, 2014Given up to 250000 numbers i have to produce a list of subsets(first of one element, then of two etc). Is there an easy way using a bitset<250000> ?
View 1 RepliesGiven up to 250000 numbers i have to produce a list of subsets(first of one element, then of two etc). Is there an easy way using a bitset<250000> ?
View 1 RepliesThe problem is that you have a set of numbers and you need to divide that set into two subsets where the difference between the sums of the subset is minimal.
Example: a set of numbers {1,5,9,3,8}, now the solution is two subsets, one subset with elements {9,3} and the other {8,5,1} the sum of the first one is 13 and the sum of the second is 13 so the difference between the sums is 0. The result shows the difference between the sums.
Another example: a set of numbers where the difference between the subsets cannot be zero, {9 51 308 107 27 91 62 176 28 6}, the minimal difference between the two subsets is 2.
I want to know how the function finds the two subsets, it works great because I've tested it for up to 300 inputs which sum adds up to 100,000.
Code:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
using namespace std;
int BalancedPartition ( int a[] , int n ) {
[Code] ....
I am working on a homework lab in which we have to find all the subsets equal to a given sum from an array of numbers.For example, an array of 7 numbers (1, 3, 4, 6, 7, 10, 25) with a sum of 25 would be (1, 3, 4, 7) and (25)...We are supposed to use dynamic programming to solve this.Now using the code below that we went over in class (Sedgewick's subsetSum), I understand how to this finds the first subset that adds up to the sum given. What's stumping me is how to find multiple subsets.
Code:
main(){
// Get input sequence
int n; // Size of input set
int m; // Target value
int *S; // Input set
int *C; // Cost table
int i,j,potentialSum,leftover;
}
[code]....
In class the teacher said it would be mainly just modifying the code we went over in class.
I have this program for generating subsets, I need to run it with input n=23. It has been running for the past 5 hours, is it normal???
Code:
/*generate subsets */
int subsets(vector < bool > sub, int i)
{
if (i > n) {
return 0;
[Code] .....
I'm a beginner in C programming and I've got a task that can't finish it..I'm supposed to generate and print the subsets of a group that its size I should enter. Pointers are not allowed!!
View 1 Replies View RelatedMy program is almost done all that is left is entering big numbers, the program can add and subtract small numbers but not big numbers because it puts them all in one node, I need the program to store each number in a node.
#include<iostream>
#include<string>
using namespace std;
class Node {
public:
int value;
Node * next;
[Code] .....
This is one part of my program, I need a loop that checks through the input(specifically the agent numbers) and then outputs the agent numbers that aren't in the input, from 1 to 20(because there should only be 20 agent).
My input is :
1 3 250.00
2 0 0
15 1 1000.00
3 4 300.00
12 2 500.00
1 2 300.00
3 4 115.00
21 3 400.00
-1 4 250.00
15 1 200.00
9 5 -150.00
18 2 140.00
13 2 550.00
the first numbers are the agent numbers so 1 , 2 ,15 are agent numbers and out output for agents who didnt participate are : 2 , 5 , 6 , 7, 8, 9, 10 , 11 , 14 , 16 , 17 ,19 20
this is the code ive wrote but its not working.
void not_part() {
ins.open(in_file);
int i=0;
int sum=0;
cout<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl;
cout<<fixed<<showpoint;
[code].....
This is one part of my program, I need a loop that checks through the input(specifically the agent numbers) and then outputs the agent numbers that aren't in the input, from 1 to 20(because there should only be 20 agent).
My input is :
1 3 250.00
2 0 0
15 1 1000.00
3 4 300.00
12 2 500.00
1 2 300.00
3 4 115.00
21 3 400.00
-1 4 250.00
15 1 200.00
9 5 -150.00
18 2 140.00
13 2 550.00
the first numbers are the agent numbers so 1 , 2 ,15 are agent numbers and out output for agents who didnt participate are : 2 , 5 , 6 , 7, 8, 9, 10 , 11 , 14 , 16 , 17 ,19 20
This is the code:
void not_part() {
ins.open(in_file);
int i=0;
int sum=0;
cout<<"AGENTS WHO DID NOT PARTICIPATE IN THE CAMPAIGN"<<endl;
cout<<fixed<<showpoint;
[Code] ......
i have to make a program where a user inputs one number and i have to find the number of a certain amount of number in the program.
for example:
user input: 2349354787839
output: There are two sevens
i know it has the use of loops but i am having trouble finding a way to scan each individual digit in the input to find if it is a seven or not.
Im trying to implement a way to use really big numbers to be able to add, substract and multiply them with the class I made. for example:
huge a = "45646464646455464654656"
huge b = "456464564646544646"
huge c = a+b;
[Code]....
I am writing trying to store a list of numbers into an integer as bits. So far I have this:
n=n & 0x0f
integer = integer<<2
integer = integer | n;
convert(integer));
I want it to store the integers as bits so that I am move them over and store them farther down the row as more numbers are added, but instead each new number is being added to the previous and I'm just getting a larger integer. Is this even a feasible way to store integers within an integer?
Let's say that in a txt file named hot.txt, I have this:
12,23,32
And with ifstream I want to take those number, adding one by one as integers in a linked list.
ifstream myList;
char* p= new char;
cin>>p;
myList.open(p);
if(myList.is_open()) {
char* x =new char;
[Code] ....
I know this part is quite wrong :
myList.get(x,256,','); // dafaq
int num=atoi(x);
list->addOrdered(num);
What I wanted to do is to stop before each comma and take that character and store it in the linked list and continue until the end of the file, but I couldnt.
i have read a lot of about lists but i dont understand this. I know its something like dogs on leash where we have
dog1->dog2->dog3->....
and
Code:
struct DOG
{char* (name of a dog of first leash)
DOG* (next dog ) } I have written something like this but this doesnt work as i wanted Code: #include <iostream>
using namespace std;
struct line {
[Code]....
I wanted to make program where i can type XX numbers , then cout those numbers without changing the order, and my next exercise is to change order in this programme from end to start.
Rewriting a program to convert an array based list to a linked list. The program has a user guess a number [1-100] until the correct answer is guessed. I only want to give hints if a duplicate isn't guessed.
while (aGuess-> != p->guess) doesn't work and I haven't been able to troubleshoot myself.
while (aGuess->guess != p->guess) {
if ( aGuess->guess > a ) {
cout << "That's too high -- try again: ";
} // if guess > a
[Code] ....
I am a beginner and I ALWAYS have the toughest time doing I/O files. It's extremely frustrating. It "seems" it should be so simple. The program should find a code from a list of numbers. These numbers are from 0 - 9, and after each number is a space in the file. Your job is to extract a special code containing only 10 of those numbers. For the number to be part of the code, it should be divisible by 2. After extracting 10 numbers divisible by 2 for the code, write those 10 numbers to the file to form the expected code.
Input file is ("question.txt")
Output should be ("code.txt")
Should this contain a "for loop" or If/else ?
Here's what I did . .
/
// int numbers, total, counter;
ifstream inFile;
inFile.open ("question.txt");
outFile.open ("code.txt");
if (!inFile)
[Code] ....
How to randomly insert certain numbers into a linked list with 10 nodes. Meaning I want to put for example numbers 1 5 10 15 20 25 30 35 40 50 in random locations in the linked list.
View 1 Replies View RelatedTrying to output a .txt file of names emails and phone numbers, but this only outputs the list name: Email.PersonEntry.
private void button1_Click(object sender, EventArgs e) {
DialogResult result;
string fileName;
//Find and Open File
[Code] ....
1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food
2. Modify Food
3. Delete Food
4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
I have a code able to import a file containing words and numbers to a linked list, but I also need to sort this linked list alphabetically. I've done research on this involving bubble sorting, but no explanationcan achieve this objective.
Below is the code that can only put the file into linked list:
Code:
#include<iostream>
#include<conio.h>
#include"U:C++WordClass2WordClass2WordClass.cpp"
#include<fstream>
#include<vector>
#include<string>
using namespace std;
[Code] .....
I am currently confused on how to get the highest and lowest number from a list of 7 numbers for a File Output. Lets say i have 165 19 654 816 654 987 324. How would i get the 987 for the highest and the 19 as the lowest? Those numbers are not fixed numbers, i need to be able to input any combination of numbers and still be able to get the highest and lowest numbers from the list of 7 numbers.
View 1 Replies View RelatedWhat I'm trying to do is make a calculator that takes two large numbers in a linked list then ask the user if they wish to add them or subtract them.
#include<iostream>
#include<string>
using namespace std;
class Node {
public:
int value;
Node * next;
[Code] ....
I am just starting out programming and have an assignment due in the near future. the problem is I cant seem to figure it out. I started it already but got stuck cant seem to figure it out. Here is the assignment.
Create a program that will generate a list of 200 random numbers (ranging from 1-1000) and determine the medium, mode, and average of the list of numbers. Have the program display the original list ant then display the list in ascending and descending order on the screen.
I am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:
3
10110101
11111111
10101010
The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.
I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is, how to say "ok the first line says 3, so now I have to convert the next 3 lines" . I am assuming it is just a simple loop that I am missing....
I need my program to read a list of numbers from and input file, random.txt, and calculate the following statistics on those numbers:
A. The number of numbers in the file.
B. The sum of all the numbers in the file.
C. The average of all the numbers in the file.
D. The largest number in the file.
E. The smallest number in the file.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
[Code]......
This is what I have so far but I'm not sure if it is right. I can't get the input file to open.
From HP / Microsoft (Visual Studio C++) <list>:
Code:
struct _Node
{ // list node
_Genptr _Next; // successor node, or first element if head
_Genptr _Prev; // predecessor node, or last element if head
_Ty _Myval; // the stored value, unused if head
};
The stored value is wasted space for the list head. Is there any advantage to implementing list using the same structure for a list head and node?
Code:
// Write a function called insertEntry() to insert a new entry into a linked list.
Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.
// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.
(Hint: Think about setting up a special structure to point to the beginning of the list.)
#include <stdio.h
struct entry1 {
int value;
struct entry1 *next;
};
[code]...
This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?