HDU 1171 Big Event in HDU
来源:互联网 发布:取英文名软件 编辑:程序博客网 时间:2024/06/03 22:01
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44535 Accepted Submission(s): 15321
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).
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.
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
210 120 1310 1 20 230 1-1
Sample Output
20 1040 40
代码:
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,n,m,m1,x,pr[5005],t,f[250005];
while(scanf("%d",&n)&&n!=-1){
j=0;
m=0;
memset(f,0,sizeof(f));
memset(pr,0,sizeof(pr));
for(i=0;i<n;i++){
scanf("%d%d",&x,&t);
m+=x*t;
while(t--)
pr[j++]=x;
}
m1=m/2;
for(t=0;t<j;t++)
for(i=m1;i>=pr[t];i--){
f[i]=f[i]>(f[i-pr[t]]+(pr[t]))?f[i]:(f[i-pr[t]]+(pr[t]));
}
printf("%d %d\n",m-f[m1],f[m1]);
}
return 0;
}
#include<string.h>
int main()
{
int i,j,n,m,m1,x,pr[5005],t,f[250005];
while(scanf("%d",&n)&&n!=-1){
j=0;
m=0;
memset(f,0,sizeof(f));
memset(pr,0,sizeof(pr));
for(i=0;i<n;i++){
scanf("%d%d",&x,&t);
m+=x*t;
while(t--)
pr[j++]=x;
}
m1=m/2;
for(t=0;t<j;t++)
for(i=m1;i>=pr[t];i--){
f[i]=f[i]>(f[i-pr[t]]+(pr[t]))?f[i]:(f[i-pr[t]]+(pr[t]));
}
printf("%d %d\n",m-f[m1],f[m1]);
}
return 0;
}
我肯定是个傻逼,一直用判断条件n!=-1作为结束循环的条件,看别人题解才发现原来是负数就不行,眼瞎了
阅读全文
0 0
- 1171 Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- 小程序刷屏之后,到底能给普通用户带来什么?
- Qt之布局管理——(1)基本布局管理
- Varnish用法详解
- 什么是敏捷
- Regular Expression算法研究
- HDU 1171 Big Event in HDU
- SpringMVC传参(中文乱发问题解决)
- python_str
- jQuery选择器
- 【SDR】Gnuradio Benchmark介绍
- 11.5水题TLE赛
- 10. Regular Expression Matching
- Description Resource Path Location Type Java compiler level does not match the version of(图解)
- CvvImage.h和CvvImage.cpp