void LongSubSequence::createSequence(int i, int j)
{
    if (i==0 || j==0) {
        return;
    }
    
    if (subStringMark[i][j]==equal) {
        
        subString.push_back(firstString[i-1]);
        createSequence(i-1, j-1);
    }else if(subStringMark[i][j]==firstStringMove){
        createSequence(i-1, j);
    }else{
        createSequence(i, j-1);
    }
}
int LongSubSequence::calculateWithDynamicProgramming()
{
    for (int i=0; i<=firstString.size(); i++) {
        lengthOfSubSequence[i][0] = 0;
    }
    for (int i=0; i<=secondString.size(); i++) {
        lengthOfSubSequence[0][i] = 0;
    }
    
    for (int i=0; i<firstString.size(); i++) {
        for (int j=0; j<secondString.size(); j++) {
            if (firstString[i]== secondString[j]) {
                lengthOfSubSequence[i+1][j+1] = lengthOfSubSequence[i][j] + 1;
                subStringMark[i+1][j+1] = equal;
            }else if (lengthOfSubSequence[i+1][j]>=lengthOfSubSequence[i][j+1]){
                lengthOfSubSequence[i+1][j+1] = lengthOfSubSequence[i+1][j];
                subStringMark[i+1][j+1] = secondStringMove;
            }else{
                lengthOfSubSequence[i+1][j+1] = lengthOfSubSequence[i][j+1];
                subStringMark[i+1][j+1] = firstStringMove;
            }
        }
    }
    
    createSequence((int)firstString.size(), (int)secondString.size());
    
    for (int i=0; i<subString.size(); i++) {
        std::cout<<subString[subString.size() - 1 - i]<<std::endl;
    }
    
    return lengthOfSubSequence[firstString.size()][secondString.size()];
    
}
Exemple #3
0
int main( int argc, char **argv )
{
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // construct the viewer.
    osgViewer::Viewer viewer;
    // root
    osg::Group* rootNode = new osg::Group;

    // create info display
    const char* text[] = {
        "osg::Sequence Mini-Howto",
        "- can be used for simple flip-book-style animation",
        "- is subclassed from osg::Switch",
        "- assigns a display duration to each child",
        "- can loop or swing through an interval of it's children",
        "- can repeat the interval a number of times or indefinitively",
        "- press 's' to start/pause/resume",
        "- press 'l' to toggle loop/swing mode",
        NULL
    };
    rootNode->addChild(createHUD(createTextGroup(text)));

    // add sequence of models from command line
    osg::Sequence* seq = createSequence(arguments);
    rootNode->addChild(seq);

    // add model to viewer.
    viewer.setSceneData(rootNode);

    // add event handler to control sequence
    viewer.addEventHandler(new SequenceEventHandler(seq));

    return viewer.run();
}
void SCI_Transporter::setupRemoteSegment()   
{ 
   DBUG_ENTER("SCI_Transporter::setupRemoteSegment");
   Uint32 sharedSize = 0; 
   sharedSize =4096;   //start of the buffer is page aligned 
 
   Uint32 sizeOfBuffer = m_BufferSize; 
   const Uint32 slack = MAX_MESSAGE_SIZE;
   sizeOfBuffer -= sharedSize; 

   Uint32 *segPtr = (Uint32*) m_TargetSegm[m_ActiveAdapterId].mappedMemory ;   
    
   Uint32 * remoteReadIndex = (Uint32*)segPtr;  
   Uint32 * remoteWriteIndex = (Uint32*)(segPtr + 1); 
   m_remoteStatusFlag = (Uint32*)(segPtr + 3);
    
   char * remoteStartOfBuf = ( char*)((char*)segPtr+(sharedSize)); 
    
   writer = new SHM_Writer(remoteStartOfBuf,  
			   sizeOfBuffer, 
			   slack,
			   remoteReadIndex, 
			   remoteWriteIndex);
   
   writer->clear(); 
    
   m_TargetSegm[0].writer=writer; 
 
   m_sendBuffer.m_forceSendLimit = writer->getBufferSize();
    
   if(createSequence(m_ActiveAdapterId)!=SCI_ERR_OK) { 
     report_error(TE_SCI_UNABLE_TO_CREATE_SEQUENCE); 
     DBUG_PRINT("error", ("Unable to create sequence on active"));
     doDisconnect(); 
   } 
   if (m_adapters > 1) {
     segPtr = (Uint32*) m_TargetSegm[m_StandbyAdapterId].mappedMemory ; 
    
     Uint32 * remoteReadIndex2 = (Uint32*)segPtr;  
     Uint32 * remoteWriteIndex2 = (Uint32*) (segPtr + 1); 
     m_remoteStatusFlag2 = (Uint32*)(segPtr + 3);
    
     char * remoteStartOfBuf2 = ( char*)((char *)segPtr+sharedSize); 
    
     /** 
      * setup a writer. writer2 is used to mirror the changes of 
      * writer on the standby 
      * segment, so that in the case of a failover, we can switch 
      * to the stdby seg. quickly.* 
      */ 
     writer2 = new SHM_Writer(remoteStartOfBuf2,  
                              sizeOfBuffer, 
                              slack,
                              remoteReadIndex2, 
                              remoteWriteIndex2);

     * remoteReadIndex = 0; 
     * remoteWriteIndex = 0; 
     writer2->clear(); 
     m_TargetSegm[1].writer=writer2; 
     if(createSequence(m_StandbyAdapterId)!=SCI_ERR_OK) { 
       report_error(TE_SCI_UNABLE_TO_CREATE_SEQUENCE); 
       DBUG_PRINT("error", ("Unable to create sequence on standby"));
       doDisconnect(); 
     } 
   }
   DBUG_VOID_RETURN; 
} //setupRemoteSegment 
Exemple #5
0
//
// FUNCTION: WndProc (HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Process the message in the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - draw the main window
// WM_DESTROY - send a message to exit and return
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            switch (wmId)
            {
			case ID_COMBO:
				if (HIWORD(wParam) == CBN_SELCHANGE)
				{
					free(Array);
					currentFunction = getNewCurrentItem(lParam);
					Array = createSequence();
				}
				break;
			case ID_EDITBEGINX:
				if (HIWORD(wParam) == EN_CHANGE)
				{
					free(Array);
					Array = createSequence();
				}
				break;
			case ID_BUTTONAPPLY:
				if (HIWORD(wParam) == BN_CLICKED)
				{
					TCHAR buf[10];
					SearchX = _wtof(valueFromTextField(ID_SEARCHX, buf));
					Polynom = _wtoi(valueFromTextField(ID_POLYNOM, buf));
					newtonY = newton_method(SearchX, Polynom);
					splinesY = splines_method(SearchX);
					RealY = myFunc()(SearchX);
					InvalidateRect(hWnd, 0, true);
				}
				break;
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
			MoveToEx(hdc, 240, 15, NULL);
			LineTo(hdc, 240, 600);
			
			swprintf(out, L"Range: %d-%d; Newton method:  %2.9f ; Splines method:  %2.9f ; Real value: %2.9f", range.down, range.up, newtonY, splinesY, RealY);
			TextOutW(hdc, 260, 50, out, wcslen(out));
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
		free(Array);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Exemple #6
0
//
// FUNCTION: InitInstance (HINSTANCE, int)
//
// PURPOSE: Saves instance processing and creates the main window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Save the instance handle in a global variable

   hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   LV LVSettings = {
	   15,											// X position
	   45,											// Y position
	   210,											// width
	   500,											// height
	   3,											// amount of columns
	   { TEXT("N"), TEXT("X"), TEXT("Y") },			// name of columns
	   70											// width of column
   };

   hwndListView = createLV(LVSettings);

   CB CBSettings = {
	   15,											// X position
	   15,											// Y position
	   100,											// width
	   200,											// height
	   3,											// amount of items
	   { TEXT("sin"), TEXT("x^2"), TEXT("ln") },	// name of items
   };

   hwndComboBox = createCB(hWnd, CBSettings);

   EDIT EDITSettings;

   EDITSettings = {
	   125,											// X position
	   15,											// Y position
	   100,											// width text
	   40,											// width field
	   24,											// height
	   TEXT(" Start:"),								// Name
	   ID_EDITBEGINX								// Edit ID
   };

   createEditField(EDITSettings);

   EDITSettings = {
	   260,											// X position
	   15,											// Y position
	   100,											// width text
	   15,											// width field
	   24,											// height
	   TEXT(" Polynom:"),							// Name
	   ID_POLYNOM									// Edit ID
   };

   createEditField(EDITSettings);

   EDITSettings = {
	   370,											// X position
	   15,											// Y position
	   130,											// width text
	   45,											// width field
	   24,											// height
	   TEXT(" Search X:"),							// Name
	   ID_SEARCHX									// Edit ID
   };

   createEditField(EDITSettings);

   CreateWindowW(TEXT("BUTTON"), TEXT("Apply"),
	   WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 510, 15, 50, 24, hWnd, (HMENU)ID_BUTTONAPPLY, hInstance, NULL);

   Array = createSequence();

   TCHAR buf[10];
   SearchX = _wtof(valueFromTextField(ID_SEARCHX, buf));
   Polynom = _wtoi(valueFromTextField(ID_POLYNOM, buf));
   newtonY = newton_method(SearchX, Polynom);
   splinesY = splines_method(SearchX);
   RealY = myFunc()(SearchX);

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}