Big Event in HDU

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

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

A easy one ,but the question producer is so boring that he make such fucking test cases.The input is terminated with a negative integer not minus one.Beside when N equals to zero the case is also not to be processed too.

#include<stdio.h>
#include<string.h>
bool f[300000];
int v[125],m[125];
int main()
{
int N;
while (scanf("%d",&N)!=EOF)
{
if (N<0) return 0;
if (N==0) continue;
int sum=0,i,j,k,A;
for (i=1;i<=N;i++)
{
scanf("%d%d",&v[i],&m[i]);
sum+=v[i]*m[i];
}
memset(f,0,sizeof(f));
f[0]=true;
for (i=1;i<=N;i++)
for (j=1;j<=m[i];j++)
for (k=sum;k>=0;k--)
if (f[k]) f[k+v[i]]=true;
for (i=(sum+1)/2;i<=sum;i++)
if (f[i])
{
A=i;
break;
}
printf("%d %d\n",A,sum-A);
}
return 0;
}

Big Event in HDU[HDU1171]的更多相关文章

  1. Big Event in HDU(HDU1171)可用背包和母函数求解

    Big Event in HDU  HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1     结果是:20 10.才最均匀! 三 ...

  2. HDU-1171 Big Event in HDU

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

  3. HDU1171——Big Event in HDU(母函数)

    Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...

  4. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

  5. hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏

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

  6. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

    题目链接: id=3211">poj3211  hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...

  7. Big Event in HDU

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

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

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

  9. 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 ...

随机推荐

  1. [OpenJudge 3063]罪犯问题

    [OpenJudge 3063]罪犯问题 试题描述 一天,警官抓获了N个嫌犯,审问N个罪犯的途中,作为警长助手的你突然发现其中被确定为罪犯的K号人是你曾经出生入死的兄弟,你不能眼睁睁看着他被抓进牢里. ...

  2. Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  3. neutron 中 flat vlan gre vxlan的区别

    In a flat network, everyone shares the same network segment. For example, say 2 tenants are sharing ...

  4. tcp/IP点对点通信程序

    点对点的通信 服务器端与客户端在建立连接之后创建一个进程 服务器端: 子进程用于接收主机的输入并将数据发送出去.父进程用于接收客户端的数据并输出到主机. 子进程一直等待主机的输入,输入的数据放在发送缓 ...

  5. iOS constraint被应用于view上的时间

    在viewdidload时,constraint是没有被应用的,之后在layoutSubviews时,系统应用了constraint.但是我感觉在viewWillLayoutSubviews函数时就已 ...

  6. iOS 端的第三方语音识别库

    最近在看语音识别方面的库,主要看了2个收费的项目,一个是 At&t 的,一个是Nuance的.这2个项目虽然是收费的,但是仅仅测试的话,是免费的,连接如下 https://developer. ...

  7. codeforces A. Domino 解题报告

    题目链接:http://codeforces.com/problemset/problem/353/A 题目意思:通俗地说,就是当上下两半的数的总和不完全是偶数时,通过上下调换某些骨牌来使这两半的数和 ...

  8. 新建myeclipse工作空间需要的工作

    接触了许多个项目,都挺大的,每次都需要配置,简单总结总结. 第一.右击项目,选择Text file encoding 第二.点击window-->preferences-->myeclip ...

  9. 【数据结构】hanoi

    #include<stdio.h> void hanoi(int n,char x,char y,char z) { ; ) printf("%d. Move disk %d f ...

  10. 有关PowerShell脚本你必须知道的十个基本概念

    1.PS1文件 一个PowerShell脚本其实就是一个简单的文本文件,这个文件包含了一系列PowerShell命令,每个命令显示为独立的一行,对于被视为PowerShell脚本的文本文件,它的文件名 ...