C++ :: Minimum Cost Path Visiting Half The Cells In A Grid?
Mar 11, 2013
I am trying solve this a problem: [URL] .....
In short:
1. Input is an N x N grid with a non-negative integer in each cell.
2. We can move from one cell to any of its adjacent cell in all four directions.
3. The 'cost' needed to move from one cell to another is the positive difference of their values.
4. We have to find the minimum cost such that we can visit atleast half of the cells with that cost;
I am not being able to think of any solution that runs in time O(N2) or better (N2 because of the size of N, any algorithm worse than it will not run within the time limit) for this problem.
So I need a hint on how to solve this problem optimally.
View 2 Replies
ADVERTISEMENT
Mar 21, 2014
I am trying to draw a 2d grid array for a battleships game. I need the grid to have a border around each cell, how to do this. so far my code is:
#include<iostream>
using namespace std;
int main(){
int grid[5][5] = {{0}};
[Code] .....
View 4 Replies
View Related
Apr 25, 2013
For this program i had to create an HTML with the cosine similarities. I got everything, i just need to color in the lowest and highest amount in the table, but I don't know how.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstdio>
using namespace std;
const int ARRAY_OF_ASCII_CODES_SIZE=256;
const int NUMBER_OF_FILES=8;
[Code] .....
View 3 Replies
View Related
Apr 22, 2013
how to compare two "cells" in a 2 dimensional array. Im almost sure it's something with in my logic when checking the cells.
#include<iomanip>
#include<iostream>
using namespace std;
int main()
{//variables
int row_count(0);
[code].....
View 2 Replies
View Related
Apr 9, 2013
how to extract certain cells for an excel file that is continuously updating. I had a look at [URL] since they provide a .h library that is useful for this situation, but could not find any code.
View 7 Replies
View Related
Apr 3, 2014
I'm trying to make a program who increments the value of all cells of an array but when i try to compile i get this error message:
Quote
error: incompatible types when assigning to type "int[9]" from type "int *"
View 4 Replies
View Related
Jan 16, 2014
whats wrong with this code, I'm trying to parse a .js file and replace all the ";" with "; " i.e add a new line after each ";". So I load the file into a char[] buffer then assign a string to this contents of this buffer. Then loop char by char through using an iterator and check for a ";", if found use replace. So int i gets to about 85898 then crashes with unknown error, 'i' should reach about 175653. It does work up till it crashes. And, is this not a simpler way to load a file into a buffer, there is in C.
Code:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
int main()
[code]....
View 8 Replies
View Related
May 9, 2013
how to display the other half of the box's border? where should i put the printf? or is there any other method that you can show me using arrays?
Code:
#include <stdio.h>
#define ROW 15
#define COLUMN 15
void disp_box (char b[ROW][COLUMN])
[Code].....
View 9 Replies
View Related
Nov 11, 2013
For example if we have 101010 First half is 101 which you get by multiplying 101010 * 10 ^-3
now how do you get the second half (010) ??
View 2 Replies
View Related
Mar 9, 2014
How do I round to the nearest half integer?
Example;
0 to 0.2 = 0
0.3 to 0.5 = 0.5
0.6-0.9 = 1
What's the formula for C++?
I found a way to do it in math but I want to know what I'd have to put in C++. It's (x*2+.5)remove decimal numbers and divide by 2. What do I put in place of "remove decimal"?
For ex; x = 8.4 using (x*2+.5)remove decimal then divide by 2.
8.4 * 2 = 16.8
16.8 + .5 = 17.3
17.3 - decimal = 17
17/2 = 8.5
I want to do something like;
cout << " Half number: << (x*2+.5)remove decimal/2 << endl;
What would I have to put in place of "remove decimal"?
View 4 Replies
View Related
May 24, 2014
As you can see, the code below calculates the average, sum, number of items, etc, for a list of numbers in two separate files and compares them with one another.
e.g. we will have a text file of 10 numbers;
45
65
24
26
26
36
35
100
109
433
etc...
The problem is that the code will perform calculations on all the numbers in the txt. or csv. file. This is problematic because if there is any text in the file, e.g. headings, then the calculations will not be performed. For instance, suppose that I only wanted to include rows 5-10 in the calculations, how would I specify this in my C++ code?
#include <iostream>
#include <cmath>
#include <math.h>
[Code]....
View 3 Replies
View Related
Jan 31, 2015
was making a somewhat of a Binary to Hex convertor but only 10/15 cases work and the non working are in the middle; 0010, 0011, 0100, 0101, 0110, 0111;;
// Test Code.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main(void)
{int A;
cout << "Enter the binary starting with the MSB
[code]....
View 5 Replies
View Related
Sep 24, 2013
The output should be something like:
5
45
543
5432
54321
View 2 Replies
View Related
Jan 3, 2015
This is a program to print upper half of the matrix.
#include <iostream>
using namespace std;
int upperhalf(int n, int apu[n][n]) {
cout<<"The upper half of the matrix is :
[Code] ....
the compiler is giving these errors:-
sh-4.2# g++ -o main *.cpp
main.cpp:4:31: error: use of parameter outside fun
ction body before ']' token
int upperhalf(int n, int apu[n][n])
[Code] ....
I dont know where i am wrong.
View 3 Replies
View Related
Jun 26, 2014
I have a question on the wasting of the memory on the use of menus. What is the task: I have mainMenu, subMenu1, subMenu2, subMenu3, ... Entry from mainMenu, and chose 1(or 2, 3,..) to subMenu1. If tasks done, go back to the mainMenu.
The Codes:
void mainMenu(){
//input 1-3 by user
switch(choice) //choice is the input
[Code].....
My problem is: the call for mainMenu() in subMenus looks like a recursion, which means the memory would be reallocated again for the called maniMenu. Is that right?
If so, times of the memory space for mainMenu function are required if going back to mainMenu several times from subMenus. But what i wanna just a choice and I dont want to wast the memory.
View 4 Replies
View Related
Feb 16, 2015
So im trying to create a program that will calculate a shipping cost. I'm stuck on trying to calculate the actual milage and cost. Example being 1400 miles for a 2lb package would be $2 for every 500miles. so it would cost $6. But Im having trouble getting the program to round up the 1400 to 1500 so it charges the correct amount.
I know there would have to be a way to do this without programming all the conditions.
Also the course has not reached loops yet.
Code:
// This program will calculate the shipping charges.// The shipping rates are based on per 500 miles shipped.
// They are not pro-rated, i.e., 600 miles is the same rate as 900 miles or 1000 miles.
#include <stdio.h>
#include <stdlib.h>
[Code]......
View 1 Replies
View Related
Nov 1, 2013
Write a program that uses a function to compute the cost of a pizza with given diameter and the number of toppings. Constant will be the cost per toppings and cost per square inch. It will contain a reputable structure as well.
diameter=17
number of toppings=3
//complier directives
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
[Code].....
View 6 Replies
View Related
Mar 2, 2014
this question would their be a different process if they asked "declare and initialize a pointer to the variable int cost[N][N]" Here's what I have so far
[#include<stdio.h>
int main() {
int a; // Step 1
int *ptr; // Step 2
a = cost; // Step 3
ptr = &a; // Step 4
return(0);
[Code] .....
View 5 Replies
View Related
Apr 15, 2014
Program calculates cost from wholesale to final cost with percentage markup!
#include <iostream>
using namespace std;
int calculate_retial(int,int);
int main () {
int wholesale;
int markup;
int cost;
[Code] ....
View 5 Replies
View Related
Sep 3, 2014
// Purpose: calculate total cost given the tax values
#include <iostream>
#incluse <string>
using namespace std;
int main() {
double purchasePrice, stateTaxAmt, countyTaxAmt, totalCost;
//Display purchase price
[Code] ....
View 2 Replies
View Related
Apr 9, 2013
I need an equation that determines the lowest possible cost for laying power line.
The variables are as follows:
1. The width of a river
2. The distance a factory is downstream from a station on the other side of the river.
3. The cost for laying line underwater.
4. The cost for laying line on land.
All these variables will be user input each use of program.
View 4 Replies
View Related
Feb 20, 2013
I have this program I wrote to calculate cost for the production of open top cylinders and how to translate it into user defined functions. Here are the user defined functions I need to use instruct() get_area() comp_area() and print_area_cost() so the program will be in 4 parts.
Code:
#include <stdio.h>
int main()
{double radius,height,cost,single,all;
float surface_area;
int count;
double pi=3.14159265;
printf("Enter the radius of the base in cm^2:
[Code] ......
View 2 Replies
View Related
Nov 4, 2013
I am currently working on an assignment.
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
char letter;
int count = 0;
double ppl = 0;
double finalCost = ppl * (count - 1);
[Code] ....
I am trying to create a word counter program that asks for the price per letter and then asks for the sentence they are writing. The app should then calculate the number of letters and give the total cost similar to:
You have 40 letters at $3.45 per letter, and your total is $138.00.
Everything compiles fine but when I run it the inputs don't work and it outputs:
You have -1 per letter, and your total cost is $-0.
View 2 Replies
View Related
Nov 3, 2014
There are a few functions for this code and I am not very good with functions yet(we just learned about them last week).
//This program will calculate the cost of using a parking garage
//based on the type of vehicle and the time of parking.
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
using namespace std;
//define rates
[Code] ...
Error List:
Error1error C2100: illegal indirectionc:userscodydesktopgaragecodegaragecodesource.cpp971GarageCode
Error2error C2100: illegal indirectionc:userscodydesktopgaragecodegaragecodesource.cpp1051GarageCode
Error3error C2561: 'main' : function must return a valuec:userscodydesktopgaragecodegaragecodesource.cpp1161GarageCode
[Code] ....
View 2 Replies
View Related
Oct 5, 2012
The point of this is to calculate the total of the monthly costs of these 6 expenses and then to show the annual cost. However, there's just a couple of things that's giving me problems and it's the calcMonCost in my code. The error says that it is more than one instance of overload function and also that an unresolved external symbol. Everything else is fine. What does this mean?
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void calcMonCost (double, double, double, double, double, double &);
void calcAnnCost (double, double, double, double, double, double &);
void getData(double &lnPymnt, double &insure, double &gas, double &oil, double &tires, double &maint);
[Code] .....
View 1 Replies
View Related
Jan 11, 2014
if(rand() % 200 == 0)
{
switch(rand()%8)
[Code]....
How can i introduce a minimum gap sort of thing between these cases?
View 2 Replies
View Related