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. 开发中经常遇到的一些css样式问题

    1.经常会遇到子元素浮动了,父元素就会探索到一个合适的值现在值是0,就要清除浮动操 <div class="search clearfix"> <div clas ...

  2. 1042: [HAOI2008]硬币购物

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3209  Solved: 2001[Submit][Status][Discuss] Descript ...

  3. vue-cli的build的文件夹下没有dev-server.js文件,怎么配置mock数据

    因为最新版本的vue-cli已经放弃dev-server.js,只需在webpack.dev.conf.js配置就行 新版webpack.dev.conf.js配置如下: 在const portfin ...

  4. Git笔记(流水账)

    命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况: 一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修 ...

  5. shell的条件判断

    .字符串判断 str1 = str2 当两个串有相同内容.长度时为真 str1 != str2 当串str1和str2不等时为真 -n str1 当串的长度大于0时为真(串非空) -z str1 当串 ...

  6. 微信在浏览器打开前的提示页面Android与IOS判断

    直接在网上扒一个页面,分分钟搞定!  先看一下效果 这是用微信开发工具打开的样式,直接上完整代码 <!DOCTYPE html> <html lang="en"& ...

  7. PhotoSwipe图片展示插件

    这个插件相当棒!功能也很强大,可以自行体会. 官方网址:http://www.photoswipe.com/ github地址:https://github.com/codecomputerlove/ ...

  8. vue之小小动态按钮

    Vue是前台框架,可以独立完成前后端分离式web项目渐进式的javascript框架 ,今天我们来设计一个简单的动态按钮   具体效果图如下: 点击后会变成这样: 首先我们需要下载vue.js:htt ...

  9. 科学计算库Numpy——排序

    矩阵按维度排序 使用np.sort()进行排序. 排序索引值 使用np.argsort()排序,返回排序后的索引值. 备注:array1[1,2]=1.2,array1[1,0]=5.6,array1 ...

  10. spring boot 设置tomcat post参数限制

    今天传图片,用的base64字符串,POST方法,前端传送的时候总是莫名其妙的崩溃,去网上搜了半天,以为是文件大小被限制了,但是我这个是字符串接收,不是文件接收,于是又继续搜,原来post本身没有参数 ...