Pure C language: greedy part of the problem source code

Source: Internet
Author: User

# Include
 
  
Struct Bag {int BagID; int BagWeight; int BagPrice; int SinglePrice; float Num ;}; void seekBest (Bag bag [], int n, float bagRL) {int I; float PCIe = bagRL; for (I = 0; I
  
   
PCIe) break; else {bag [I]. num = 1; PCIe = PCIe-bag [I]. bagWeight ;}}if (I <= n) {bag [I]. num = WAV/bag [I]. bagWeight;} for (I = 0; I
   
    
0) {printf ("% f items with ID: % d weight: % d !!! \ N ", bag [I]. bagID, bag [I]. bagWeight, bag [I]. num) ;}} void Sort (Bag bag [], int n) {int j; Bag temp; int I; for (I = 0; I
    
     
# Include
     
      
# Define N 50 struct Object {int list; // Object ID float p; // Object Value float w; // Object weight float v; // Object value/weight ratio}; void MERGE (Object A [], int low, int mid, int high) {int h, I, j, k; object * B = (Object *) malloc (high-low + 1) * sizeof (Object); h = low; I = 0; j = mid + 1; while (h <= mid & j <= high) {if (A [h]. v> = A [j]. v) {B [I] = A [h]; h = h + 1;} else {B [I] = A [j]; j = j + 1 ;} I ++;} if (h> mid) {for (k = j; k <= high; k ++) {B [I] = A [k]; I = I + 1 ;}} else for (k = h; k <= mid; k ++) {B [I] = A [k]; I = I + 1;} I = 0; for (k = low; k <= high; k ++) {A [k] = B [I]; I ++;} free (B);} void MERGESORT (Object array [], int low, int high) {int mid; if (low
      
        > M; cout <"Enter the number of objects:"; cin> n; cout <"Enter the object price and weight:" <
       
         > Instance [I]. p> instance [I]. w; cout <"--------------------------------------" <
        
         

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.