标签:max sizeof 数组 个数 printf mon can lan nbsp
【题目链接】
http://acm.hdu.edu.cn/showproblem.php?pid=4864
【算法】
贪心
不妨将两个数组分别按x从大到小排序
然后枚举每件物品,选择x值大于该物品的且y值最小的机器对它进行修理
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 100010 #define MAXP 110 int n,m,i,j,pos; long long ans,money; int cnt[MAXP]; struct info { long long x,y; } a[MAXN],b[MAXN]; inline bool cmp(info a,info b) { return (a.x != b.x) ? a.x > b.x : a.y > b.y; } int main() { while (scanf("%d%d",&n,&m) != EOF) { money = ans = 0; memset(cnt,0,sizeof(cnt)); for (i = 1; i <= n; i++) scanf("%lld%lld",&a[i].x,&a[i].y); for (i = 1; i <= m; i++) scanf("%lld%lld",&b[i].x,&b[i].y); sort(a+1,a+n+1,cmp); sort(b+1,b+m+1,cmp); pos = 1; for (i = 1; i <= m; i++) { while (pos <= n && a[pos].x >= b[i].x) { cnt[a[pos].y]++; pos++; } for (j = b[i].y; j <= MAXP; j++) { if (cnt[j]) { cnt[j]--; ans++; money += 500 * b[i].x + 2 * b[i].y; break; } } } printf("%lld %lld\n",ans,money); } return 0; }
标签:max sizeof 数组 个数 printf mon can lan nbsp
原文地址:https://www.cnblogs.com/evenbao/p/9245103.html