Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:46:39+00:00 2026-05-23T02:46:39+00:00

I am using a simple function (y(x)), and I want to generate an x

  • 0

I am using a simple function (y(x)), and I want to generate an x value from a certain y value. While typically reverse mapping does not give a single x value, I am using the maximum from my y values. This means that there will be a unique x value for the y value I input(the maximum). I don’t understand how to code this in c++

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:46:40+00:00Added an answer on May 23, 2026 at 2:46 am

    If you don’t need interpolation, only exact reverse lookup, then it’s relatively straighforward:

    std::map<YType, XType> lookup;
    // (code to read the file goes here)
    // for each x {
        YType y = f(x);
        if ((lookup.count(y) == 0) || (lookup[y] < x)) {
            lookup[y] = x;
        }
    // }
    

    Then your reverse lookup is just lookup[y], which will return 0 (or a default-constructed value where applicable) if y in fact was missing from the data.

    Be aware that my code is a bit inefficient, it looks up y several times in the map, up to 3. You can optimize using iterators, but I’m concerned that obscures what’s going on if you’re not already familiar with them:

    typedef std::map<YType, XType> maptype;
    typedef std::pair<maptype::iterator, bool> resulttype;
    
    resulttype result = lookup.insert(std::make_pair(y, x));
    if (!result.second) {
        // key already existed, so value was not inserted. Check for max.
        maptype::iterator pos = result.first;
        if ((*pos).second < x) {
            (*pos).second = x;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iam using a simple insert script function to pass the values from registration html
I'm using this simple function: def print_players(players): tot = 1 for p in players:
I've written this very simple function to replace a file extension using LINQ in
I'm using the simple jQuery DIV refresh code. var refreshId = setInterval(function() { $('#refreshdash').load('dashboard.php?cache=');
Are there conventions for function names when using the Perl Test::More or Test::Simple modules?
Hay I'm using PHPMailer to send some simple emails, however the function SetFrom() doesn't
After loading a PHP template (using jQuery's load function), this simple script won't make
I want to generate a number that is close to zero with a certain
I'm successfully using the boxplot function to generate... boxplots. Now I need to generate
#include<iostream> using namespace std; struct sample { int data[3][2]; }; struct sample* function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.