HDUOJ---1171
http://acm.hdu.edu.cn/showproblem.php?pid=1171
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18439 Accepted Submission(s): 6457
Problem Description
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002. The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different. A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
Sample Input
2 10 1 20 1 3 10 1 20 2 30 1 -1
Sample Output
20 10 40 40
Author
lcy
简单的DP
1 #include<iostream>
2 #include<cstdlib>
3 using namespace std;
4 typedef struct Node
5 {
6 int value;
7 int num;
8 }node;
9 int cmp( const void *a, const void *b)
10 {
11 return (*(node*)b).value-(*(node*)a).value;
12 }
13 int main()
14 {
15 int n,i,sum,count,min;
16 node arr[301];
17 while(cin>>n,n>0)
18 {
19 for(sum=i=0;i<n;i++)
20 {
21 cin>>arr[i].value>>arr[i].num;
22 sum+=arr[i].value*arr[i].num;
23 }
24 qsort(arr,n,sizeof(arr[0]),cmp);
25 min=0;
26 for(count=i=0;i<n;i++)
27 {
28 while(arr[i].num)
29 {
30 if(count+arr[i].value<=sum/2)
31 {
32 count+=arr[i].value;
33 }
34 arr[i].num--;
35 }
36 if(min<count)
37 {
38 min=count;
39 }
40 }
41 cout<<sum-min<<" "<<min<<endl;
42 }
43 return 0;
44 }
- Python爬取链家网数据:新房楼盘价格分析
- 【编程基础】Java里面如何对字符串排序?
- 计算广告——广告定向实践
- 通过shell抓取html数据(r2笔记74天)
- 通过shell脚本分析足彩(r2笔记74天)
- 通过shell脚本得到数据字典的信息 (r2笔记72天)
- 机器学习算法实践——K-Means算法与图像分割
- 利用 Python、SciKit 和文本分类来构建客户行为描述模型
- 使用Python爬取社交网络数据分析
- PHP爬虫源码:百万级别知乎用户数据爬取与分析
- 使用Python抓取欧洲足球联赛数据
- python爬取百度新闻:分析共享单车火爆背后有哪些规则?
- Python爬虫(urllib2+bs4)数据采集:分析找出百度贴吧谁是水贴王
- 学界 | OpenAI 发布稀疏计算内核,更宽更深的网络,一样的计算开销
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 迭代加深搜索-POJ 3134 Power Calculus
- 浙大版《C语言程序设计(第3版)》题目集 习题9-2 计算两个复数之积
- 浙大版《C语言程序设计(第3版)》题目集 习题9-6 按等级统计学生成绩
- 实战|用pandas+PyQt5制作一款数据分组透视处理工具
- 带权/种类并查集-POJ 1182食物链
- 浙大版《C语言程序设计(第3版)》题目集 练习10-1 使用递归函数计算1到n之和
- 十分钟快速了解Pandas的常用操作!
- 一行代码如何隐藏 Linux 进程?
- SSH 只能用于远程 Linux 主机?那说明你见识太小了!
- 干货 | Trip.com 机票React Native整洁架构2.0实践
- 干货 | 日均TB级数据,携程支付统一日志框架
- 为什么 HTTPS 是安全的?
- Hello World背后的故事:如何在Linux上编译C语言程序
- 浅谈Linux的动态链接库
- 初识ABP vNext(9):ABP模块化开发-文件管理