6 条题解

  • 1
    @ 2021-8-7 18:39:47

    C++ :

    
    #include <iostream>
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long 
     
    const int maxn=2510;
    pair<int,int>cows[maxn];
    int n,m;
    signed main(){
        cin>>n>>m;
        for(int i=0;i<n;i++)cin>>cows[i].first>>cows[i].second;
        sort(cows,cows+n);
        
        
        map<int,int>spfs;
        for(int i=0;i<m;i++){
            int spf,cover;
            cin>>spf>>cover;
            spfs[spf]+=cover;
        }
        
        int res=0;
        
        //spfs[0]=spfs[1001]=n;
     
        for(int i=n-1;i>=0;i--){
            
            auto cow=cows[i];
            auto it=spfs.upper_bound(cow.second);
            it--;
            if(it->first>=cow.first && it->first<=cow.second){
                res++;
                if(--it->second==0)spfs.erase(it);
            }
        }
        
        cout<<res<<endl;
    }
    
    • 0
      @ 2025-3-29 18:58:40

      #include #include <bits/stdc++.h> using namespace std; #define int long long

      const int maxn=2510; pair<int,int>cows[maxn]; int n,m; signed main(){ cin>>n>>m; for(int i=0;i<n;i++)cin>>cows[i].first>>cows[i].second; sort(cows,cows+n);

      map<int,int>spfs;
      for(int i=0;i<m;i++){
          int spf,cover;
          cin>>spf>>cover;
          spfs[spf]+=cover;
      }
      
      int res=0;
      
      //spfs[0]=spfs[1001]=n;
      
      for(int i=n-1;i>=0;i--){
          
          auto cow=cows[i];
          auto it=spfs.upper_bound(cow.second);
          it--;
          if(it->first>=cow.first && it->first<=cow.second){
              res++;
              if(--it->second==0)spfs.erase(it);
          }
      }
      
      cout<<res<<endl;
      

      }

      • 0
        @ 2024-1-28 11:44:16

        #include #include <bits/stdc++.h> using namespace std; #define int long long

        const int maxn=2510; pair<int,int>cows[maxn]; int n,m; signed main(){ cin>>n>>m; for(int i=0;i<n;i++)cin>>cows[i].first>>cows[i].second; sort(cows,cows+n);

        map<int,int>spfs;
        for(int i=0;i<m;i++){
            int spf,cover;
            cin>>spf>>cover;
            spfs[spf]+=cover;
        }
        
        int res=0;
        
        //spfs[0]=spfs[1001]=n;
        
        for(int i=n-1;i>=0;i--){
            
            auto cow=cows[i];
            auto it=spfs.upper_bound(cow.second);
            it--;
            if(it->first>=cow.first && it->first<=cow.second){
                res++;
                if(--it->second==0)spfs.erase(it);
            }
        }
        
        cout<<res<<endl;
        

        }

        • 0
          @ 2023-1-6 18:06:43
          #include<bits/stdc++.h>
           using namespace std;
          const int MAXN=5000;
          struct cow{
             int minSPF,maxSPF;
          }c[MAXN];
          int SPF[MAXN],cover[MAXN];
          int L,C;
          int J=0;
          bool myc(cow a,cow b) { return a.minSPF>b.minSPF; }
          int main()
          {
             cin>>C>>L;
             for(int i=1;i<=C;i++) scanf("%d %d",&c[i].minSPF,&c[i].maxSPF);
             sort(c+1,c+C+1,myc);
             for(int i=1;i<=L;i++) scanf("%d %d",&SPF[i],&cover[i]);
             for(int i=1;i<=C;i++)
             {
             	int x=c[i].minSPF,y=c[i].maxSPF;
             	int use=-1,num;
          	for(int j=1;j<=L;j++)
             	 if(SPF[j]>=x && SPF[j]<=y && cover[j] && SPF[j]>use )  use=SPF[j],num=j;	
             	if(use!=-1) { J++; cover[num]--;} 
             }
             cout<<J;
          } 
          
          
          • -1
            @ 2023-4-3 20:33:21

            #include<bits/stdc++.h> #include #include<math.h> #include #include<string.h> #include #include<stdio.h> #include #include #include using namespace std; const int MAXN=5000; struct cow{ int minSPF,maxSPF; }c[MAXN]; int SPF[MAXN],cover[MAXN]; int L,C; int J=0; bool myc(cow a,cow b) { return a.minSPF>b.minSPF; } int main() { cin>>C>>L; for(int i=1;i<=C;i++) scanf("%d %d",&c[i].minSPF,&c[i].maxSPF); sort(c+1,c+C+1,myc); for(int i=1;i<=L;i++) scanf("%d %d",&SPF[i],&cover[i]); for(int i=1;i<=C;i++) { int x=c[i].minSPF,y=c[i].maxSPF; int use=-1,num; for(int j=1;j<=L;j++) if(SPF[j]>=x && SPF[j]<=y && cover[j] && SPF[j]>use ) use=SPF[j],num=j; if(use!=-1) { J++; cover[num]--;} } cout<<J; }

            • -2
              @ 2022-10-15 22:19:53
              #define pii pair<int,int>
              #define fi first
              #define  se second
              using namespace std;
              const int N = 1e3 + 10;
              vector<pii > cow;
              int cover[N], c, l;
              set<int> spf;
              
              int main() {
                  cin >> c >> l;
                  for (int i = 1; i <= c; i++) {
                      int x, y;
                      scanf("%d%d", &x, &y);
                      cow.push_back({x, y});
                  }
                  sort(cow.begin(), cow.end());
                  reverse(cow.begin(), cow.end());
                  for (int i = 1; i <= l; i++) {
                      int x, y;
                      scanf("%d%d", &x, &y);
                      if (!cover[x])
                          spf.insert(-x);
                      cover[x] += y;
                  }
                  int ans = 0;
                  for (auto &it:cow) {
                      int x = -(*spf.lower_bound(-it.se));
                      if (x < it.fi)continue;
                      ans++;
                      if (!(--cover[x]))spf.erase(-x);
                  }
                  cout << ans;
                  return 0;
              }
              
              
              • 1

              信息

              ID
              22
              时间
              1000ms
              内存
              128MiB
              难度
              1
              标签
              递交数
              133
              已通过
              92
              上传者