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个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
随机推荐
- 【C#】CLR内存那点事(高级)
对于这篇,不想再对值类型进行讨论,如要看值类型的内存怎么玩可以看一下(CLR内存那点事 初级),我们这篇主要讨论一下引用类型. 先来装备两个类 internal class Employee { pu ...
- C# PDF、winform 生成解析二维码
PDF 生成.解析二维码 界面样式: 第一步:下载ThoughtWorks.QRCode.dll 类并引用 地址 http://download.csdn.net/detail/liwb1987/8 ...
- Atcoder Beginner Contest 121D(异或公式)
#include<bits/stdc++.h>using namespace std;int main(){ long long a,b; cin>>a>&g ...
- Linux man语法结构说明
一.man手册的内容结构(说明书页的格式): 标题含义: Name命令的名称和用途(摘要) Synopsis命令语法(摘要) Description完整描述 Environment命令使用的环境变量 ...
- SHELL编程之条件判断
一.if 语句结构 (1)单分支语句结构 if 条件测试操作 then 命令序列 fi #!/bin/bash MOUNT_DIR="/media/cdrom/" #-d $M ...
- django部署ubuntu数据库MYSQL时区问题
SELECT * FROM mysql.time_zone; SELECT * FROM mysql.time_zone_name; mysql_tzinfo_to_sql /usr/share/zo ...
- php 面试常问问题
1.看看简历,会问一些过去做的项目的用户量.pv.吞吐量.相关难点和解决方法等2.数据库设计经验,为什么进行分表? 分库?一般多少数据量开始分表? 分库? 分库分表的目的? 什么是数据库垂直拆分? 水 ...
- Spark调优秘诀——超详细
版权声明:本文为博主原创文章,转载请注明出处. Spark调优秘诀 1.诊断内存的消耗 在Spark应用程序中,内存都消耗在哪了? 1.每个Java对象都有一个包含该对象元数据的对象头,其大小是16个 ...
- 在Windows上搭建Git Server (2)
第一步:下载Java,下载地址:http://www.java.com/zh_CN/ 第二步:安装Java.安装步骤不再详述. 第三步:配置Java环境变量. 右键”计算机” => ”属性” ...
- External Tools
Preferences偏好设置-External Tools External Tools: External Script Editor:外部脚本编辑器,通过此项可以切换您所擅用的脚本的编辑器 Ed ...