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. js点击拉拽轮播图pc端移动端适配

    <div class="content"> <button class="left">left</button> <b ...

  2. 关于poi的坑

    背景故事 今天遇上一个坑,关于poi公式计算结果出错的问题,自己打断点debug了半天,虽然没彻底搞清楚为啥不行,但所幸找到了解决办法. 干货 下面不废话,直接贴干货,原先的公式处理代码如下: fin ...

  3. JavaScript事件对象与事件的委托

    事件对象 包含事件相关的信息,如鼠标.时间.触发的DOM对象等 js默认将事件对象封装好,并自动的以参数的形式,传递给事件处理函数的第1个参数,如下: document.getElementsByTa ...

  4. Matlab数据转化至python端,并写入数据库

    因工作原因,一些获取的行业数据以已知的结构体存储在.mat文件中, 现需要将其存储在数据库中并且能够灵活调用至python dataframe里进行操作 原数据的一个例子如下 目标如上: 然后是转化代 ...

  5. python编写登录接口

    要求: 输入用户名密码     认证成功显示欢迎信息 输错三次以后锁定 代码如下: # Author:YKwhile(True): select=input('请问是注册还是登录') if selec ...

  6. 排序算法C语言实现——插入排序(优于冒泡)

    为什么插入排序要优于冒泡? 插入排序在于向已排序序列中插入新元素,主要的动作是移动元素,涉及1次赋值,即data[j] = data[j-1]; 而冒泡排序在于相邻元素交换位置,涉及3条赋值,即iTm ...

  7. Python中str、list、numpy分片操作

    在Python里,像字符串(str).列表(list).元组(tupple)和这类序列类型都支持切片操作 对对象切片,s是一个字符串,可以通过类似数组索引的方式获取字符串中的字符,同时也可以用s[a: ...

  8. loj2053 「HNOI2016」大数

    ref #include <algorithm> #include <iostream> #include <cstring> #include <cstdi ...

  9. 12个scp传输文件的命令栗子

    12个scp传输文件的命令栗子 一直在用scp进行简单的远程复制文件的功能,今天无意间看到一篇介绍scp的文章,便想着学习学习并将其翻译了过来.原文戳这里.翻译不对的地方,敬请指正. 另外我最近搭建了 ...

  10. Python+Selenium基础篇之4-XPath的使用

    开始写自动化脚本之前,我们先学习几个概念,在完全掌握了这几个概念之后,有助于我们快速上手,如何去编写自动化测试脚本. 元素,在这个教程系列,我们说的元素之网页元素(web element).在网页上面 ...