Wednesday, January 29, 2020

POJ.3614 Sunscreen

1.Problem
http://poj.org/problem?id=3614

2.Idea
Greedy method works. Process from the cow that has the min of maxSPF.

3.Source
 int c, l;  
 int Lot[1003];  
 struct Cow {  
      int l, r;  
      bool operator < (const Cow &a)const {  
           return r < a.r;  
      }  
 } Cows[2503];  
 int main()  
 {  
      cin >> c >> l;  
      for (int i = 0; i < c; i++) {  
           cin >> Cows[i].l >> Cows[i].r;  
      }  
      sort(Cows, Cows + c);  
      for (int i = 0; i < l; i++) {  
           int x, y;  
           cin >> x >> y;  
           Lot[x] += y;  
      }  
      int ans = 0;  
      for (int i = 0; i < c; i++) {  
           for (int j = Cows[i].l; j <= Cows[i].r; j++) {  
                if (Lot[j] > 0) {  
                     ans++;  
                     Lot[j]--;  
                     break;  
                }  
           }  
      }  
      cout << ans << endl;  
      return 0;  
 }  

No comments:

Post a Comment