Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38607    Accepted Submission(s): 13362

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
 
Recommend
We have carefully selected several similar problems for you:  2602 1203 2159 2955 2844 

题意:

给出一些互不相同的数以及这些数的个数,把这些数字组合成两个数使得这两个数最接近并且前一个数字大于后一个数字,然后切记最后case结尾是负数不是-1

分析:

我们处理出所有的可以组成的数字然后找出最接近的$\frac {sum}{2}$的数字...

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
//by NeighThorn
using namespace std; int n,a,b; bitset<500005> s,l; signed main(void){
while(scanf("%d",&n)&&n>=0){
s.reset(),s[0]=1;int sum=0,res;
for(int i=1,a,b;i<=n;i++){
scanf("%d%d",&a,&b);
l.reset();
for(int j=0;j<=b;j++)
l|=s<<(a*j);
s=l;sum+=a*b;
}
for(int i=sum/2;i<=sum;i++)
if(s[i]&&i>=sum-i){
res=i;
break;
}
printf("%d %d\n",res,sum-res);
}
return 0;
}

  


By NeighThorn

HDOJ 1171 Big Event in HDU的更多相关文章

  1. [HDOJ 1171] Big Event in HDU 【完全背包】

    题目链接:HDOJ - 1171 题目大意 有 n 种物品,每种物品有一个大小和数量.要求将所有的物品分成两部分,使两部分的总大小尽量接近. 题目分析 令 Sum 为所有物品的大小总和.那么就是用给定 ...

  2. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  3. HDU 1171 Big Event in HDU (多重背包变形)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. 组合数学 - 母函数的变形 --- hdu 1171:Big Event in HDU

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU 1171 Big Event in HDU (多重背包)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. 杭电1171 Big Event in HDU(母函数+多重背包解法)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. 【01背包】HDU 1171 Big Event in HDU

    Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...

  8. HUD 1171 Big Event in HDU(01背包)

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  9. HDU 1171 Big Event in HDU dp背包

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...

随机推荐

  1. AB test学习笔记

    AB Test 介绍: https://vwo.com/ab-testing/ AB Test 的意义: 数据分析告诉我们要不要去做一件事情,ab 实验反馈告诉我们我们做得好不好,哪里有问题,以及衡量 ...

  2. go包的理解

    结论: import时指定的字符串,是相对于$GOPATH的目录路径,告诉了go,要去加载这个目录下所有的包文件(不包括子目录中的文件) 一个目录中所有的源文件(不包括子目录)代表了单独的一个包,这些 ...

  3. 【JavaScript】修改图片src属性切换图片

    今天做项目时其中一个环节需要用到js修改图片src属性切换图片,现在来记录一下 以下是示例: html <img src="/before.jpg" id="img ...

  4. 29.VUE学习之--键盘事件.键盘修饰符的实例讲解

    键盘事件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  5. python字符编码小结

    首先简要说一下各种字符编码: 1. ASCII 计算机只认识0101,但如何让计算机认识人类语言?将每个字母和符号给予固定的编号,然后将这个编号转换成二进制,计算机就可以正确识别这些字母与符号,同时计 ...

  6. bootmem_free_node

    该函数设置: 1.pgdata节点的成员 2.pgdata->zone的成员 3.初始化zone->free_area 4.初始化zone所包含的所有页对应的页框描述符page结构体 /* ...

  7. STM32启动文件:startup_stm32f10x_hd.s等启动文件的简单描述

    在官方的库文件中,分别有如下文件: startup │ │ │ ├─arm │ │ │ │ startup_stm32f10x_cl.s │ │ │ │ startup_stm32f10x_hd.s ...

  8. 数据库——MySQL进阶

    1.索引 2.触发器 3.存储过程 4.函数 5.事务 6.视图 1.索引 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结构.类似于字典中的目录,查找字典内容时可以根据目录查找到数据的存放位 ...

  9. WampServer配置说明

    注意:所有的修改操作都要重启WampServer服务器,部分需要重启WampServer软件 1.修改默认端口 1)打开文件:C:\wamp\bin\apache\apache2.4.9\conf\h ...

  10. plsql 编程基础

    分支 declare --声明变量 a ); b ); c ); begin --开始 a := '小明'; dbms_output.put_line(a); b :; c :; if b > ...