TOJ 4119 Split Equally
描述
Two companies cooperatively develop a project, but they don’t like working with one another. In order to keep the company together, they have decided that only one of them will work on each job. To keep things fair, the jobs need to be split so that both work the same amount. This is accomplished by estimating the time necessary for each job and assigning jobs based upon these estimates. The purpose of your program is to determine whether the jobs can be equally split (the total estimated time necessary for both individuals sums to the same value).
输入
The input will consist of multiple test cases (one per line terminated
by a line containing the string END). Each line will contain a space
seperated list of integers which are the estimated times required for
the jobs.
输出
For each case your output should be either YES or NO depending on whether they can be split equally.
样例输入
1 2 3 4 5 6
2 3 4 5 6 8
7 2 4 8 11 16
9 10 11 30
14 12 9 15
END
样例输出
NO
YES
YES
YES
NO
题目来源
01背包问题,背包问题只会01了。%>_<%
#include <stdio.h>
#include <string.h>
#include <stdlib.h> int n,w[50001]={0};
int best[2][50001],sum,c; int main()
{
char ch[52000];
while(gets(ch),strcmp(ch,"END")!=0){
//初始化
int n=1,sum=0;
char *p=strtok(ch," ");
w[n]=atoi(p);
sum+=w[n++];
while(p=strtok(NULL," ")){
w[n]=atoi(p);
sum+=w[n++];
}
c=sum/2;
n--;
memset(best[0],0,sizeof(best[0]));
for(int i=1;i<=n;i++){
for(int j=1;j<=c;j++){
if(j>=w[i]){
if(best[(i-1)%2][j-w[i]]+w[i]>=best[(i-1)%2][j]){
best[i%2][j]=best[(i-1)%2][j-w[i]]+w[i];
}else {
best[i%2][j]=best[(i-1)%2][j];
}
}else{
best[i%2][j]=best[(i-1)%2][j];
}
}
}
if(best[n%2][c]==sum-best[n%2][c]) {
puts("YES");
}else{
puts("NO");
}
}
return 0;
}
TOJ 4119 Split Equally的更多相关文章
- Problem C: Celebrity Split
题目描写叙述 Problem C: Celebrity Split Jack and Jill have decided to separate and divide their property e ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- 第十二届浙江省大学生程序设计大赛-Capture the Flag 分类: 比赛 2015-06-26 14:35 10人阅读 评论(0) 收藏
Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer security, Ca ...
- Capture the Flag(模拟)
Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer se ...
- Divide Candies CodeForces - 1056B (数学)
Arkady and his friends love playing checkers on an n×nn×n field. The rows and the columns of the fie ...
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第三部分)
Earthstone Keeper Time Limit: 4 Seconds Memory Limit: 65536 KB Earthstone Keeper is a famous ro ...
- CSS:Tutorial one
1.Three Ways to Insert CSS External style sheet Internal style sheet Inline style External Style She ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
Little Boxes Problem Description Little boxes on the hillside.Little boxes made of ticky-tacky.Littl ...
- hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map
题目传送门 题目大意: 给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物).题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
随机推荐
- Javascript脚本 : eval()函数
Javascript 中 eval(X)函数 是将参数 当做语句来执行 var number1='1+2'; alert(number1); 输出为 '12': var number2=eval('1 ...
- android 仿QQ气泡聊天界面
1.现在的QQ,微信等一些APP的聊天界面都是气泡聊天界面,左边是接收到的消息,右边是发送的消息, 这个效果其实就是一个ListView在加载它的Item的时候,分别用了不同的布局xml文件. 2.效 ...
- log4net工作原理(2)
上回说道:Repository可以说成基于一个log4net配置节创建的log4net容器,它根据log4net配置节的指示创建其他所有对象(Logger/Appender/Filter/Layout ...
- MSSQL中数据库对象类型解释
public string GetObjectTypeName(object oType) { switch (oType+"") { case "U": re ...
- EventTrigger
EventTrigger事件触发器. 相比较数据,属性,事件触发器是XAML的UI层中最重要的一个部分. 事件触发器中,触发的效果是动画,不再是setter. 也是很有意思的 <对象.Style ...
- day8学python 各种简单模板
各种简单模板 内容: 1.shelve模板 存储数据 2.shutil 模板 用作拷贝/删除/压缩文件(使用便捷) 3.hashlib 模板 加密文件 4.re模板 ================= ...
- Codeforces Round #545 (Div. 2)C(离散化,思维,PAIR排序)
#include<bits/stdc++.h>using namespace std;int a[1007][1007];pair<int,int>p1[1007],p2[10 ...
- Codeforces Round #551 (Div. 2)A. Serval and Bus
A. Serval and Bus time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 关于DataGridView的ClearSelection方法
最近做winform项目,遇到一个问题. 纠结了几天,最终解决了,记录一下! 新建一个Form窗体,拽一个DataGridView上去,然后写一个方法 private void BindData() ...
- nginx负载均衡fair模块安装和配置
nginx-upstream-fair-master fair模块源码 官方github下载地址:https://github.com/gnosek/nginx-upstream-fair说明:如果从 ...