5 条题解
-
1赵青海 (huhe) LV 7 SU @ 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; }
-
02024-1-28 11:44:16@
#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;
}
-
02023-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; }
-
-12023-4-3 20:33:21@
#include<bits/stdc++.h> #include<cstdio> #include<math.h> #include<queue> #include<string.h> #include<vector> #include<stdio.h> #include<stack> #include<iostream> #include<iomanip> 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; }
-
-22022-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
- 标签
- 递交数
- 118
- 已通过
- 79
- 上传者