URAL 1788 On the Benefits of Umbrellas
2015-04-27 23:36
627 查看
题意:下雨了,有n个女生和m个男生。每个男生都有伞,每个女生都没有伞。女生如果被淋了就会产生怨念,每个女生都有自己的怨念值,男生如果不能邀请到女生,那么这个男生也会产生怨念,每个男生都有自己的怨念值。总怨念值等于被淋的女生的怨念值加上没有邀请到女生的男生的怨念值乘以邀请到女生的男生个数。问如何使得总怨念值最小。
解法:降序排序,把怨念值大的放前面,暴力遍历。男女成对数最多是男生个数和女生个数的最小值。我们就直接遍历,求0对到最大对之间怨念值最小的情况。
解法:降序排序,把怨念值大的放前面,暴力遍历。男女成对数最多是男生个数和女生个数的最小值。我们就直接遍历,求0对到最大对之间怨念值最小的情况。
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int a[110],b[110],n,m; bool cmp(int a,int b) { return a > b; } int main() { while(~scanf("%d%d",&n,&m)) { for(int i = 0; i < n; i++) scanf("%d",&a[i]); for(int i = 0; i < m; i++) scanf("%d",&b[i]); sort(a,a+n,cmp); sort(b,b+m,cmp); int p = min(n,m); int ans = 0x3f3f3f3f; for(int i = 0; i <= p; i++) { int sum1,sum2; sum1 = sum2 = 0; for(int j = i; j < n; j++) sum1 += a[j]; for(int j = i; j < m; j++) sum2 += b[j] * i; ans = min(ans,sum1+sum2); } printf("%d\n",ans); } return 0; }
相关文章推荐
- URAL 1788 On the Benefits of Umbrellas
- URAL - 1788 On the Benefits of Umbrellas(水题)
- Multiprocess programming - Lower Bounds on the Number of Locations
- Eric Sink on the Business of Software
- The opinion of cheated on an exam
- How to maintain the position of the scrollbar on postbacks (across the entire site)
- URAL 1774 Barber of the Army of Mages 最大流
- Create a Bootable Version of the OS X Mavericks Installer on a USB Flash Drive
- Running Xen: A Hands-On Guide to the Art of Virtualization
- Clarifications on Flash Player for Mobile Browsers, the Flash Platform, and the Future of Flash[翻译练习]
- HAProxy Installation and Configuration on CentOS 6.4 to Mitigate The Effects of Abusive Clients--转
- The Green Benefits of Tail Slag
- The effect of opinion clustering on disease outbreaeks
- CHANGING BEHAVIOR BASED ON THE VALUE OF AN ENUMERATED TYPE(ZT)
- Diesel powered timepieces selling on the web are usually really one of the most stylish timepieces
- Repeating Table Header on Each Page of the Report in the SSRS 2008
- 【随】Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack 问题解决。
- Changing the Output Voltage of a Switching Regulator on the Fly
- VizSEC 2007: Proceedings of the Workshop on Visualization for Computer Security
- Some comments on the situation of Chinese manufacturer