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个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
随机推荐
- OnExit事件 OnChange事件
procedure TSetParkForm.edtPrePosExit(Sender: TObject); // 焦点移开 或已操作 begin if (G2.RowCount > 0) an ...
- Arduino I2C + DS1307实时时钟
主要特性 DS1307是Maxim的串行.I2C实时时钟芯片.主要特性有: 工作电压:主电源电压4.5~5.5V,电池电压2.0~3.5V 功耗:电池供电.备份模式时<500nA 接口:I2C, ...
- C#调用OCX控件的常用方法[转]
小伙伴们在使用ICP提供的各种能力进行集成开发时常常会遇到一些技术上的困扰,例如ICP中很多接口是通过OCX控件的方式提供的,如何调用这些接口,就成了一个不大不小的问题,毕竟开发指南上可没这些内容啊~ ...
- 修改vscode caipeiyu.writeCnblog ,简化博客发布
修改vscode caipeiyu.writeCnblog ,简化博客发布 1. 安装caipeiyu.writeCnblog vscode的博客园文章发布插件WriteCnblog : https: ...
- App Store提交审核报错 ERROR ITMS-90087解决办法
1.原因说明 app对Wifi进行配网, 使用了GizWifiSDK.framework提交App Store时候报错了 App Store Connect Operation Error ERROR ...
- upsource代码审查
upsource 从零搭建代码审查平台,需要的不仅是把代码审查的工具搭起来,还要结合公司情况制定一系列的代码审查规范.下面是对选择的upsource web端代码审查工具的安装及介绍.详细的请看这篇文 ...
- java技术
线程池的原理及实现:https://blog.csdn.net/hsuxu/article/details/8985931 Java高级工程师面试题总结及参考答案:https://www.cnblog ...
- AtCoder - 2566 优先队列
Let N be a positive integer. There is a numerical sequence of length 3N, a=(a1,a2,…,a3N). Snuke is c ...
- php 替换 oracle 数据字段中“看不见”换行符号
工作需要,把oracle中的数据导出csv,导出代码如下:<?php$file_name = "申請書承認(予定休出).csv";header("Content-D ...
- n阶幻方
前序 最近在学习一些经典的算法,搞得头昏脑涨,就想换换脑子.在家里的旧书堆里面乱翻,无意中将一本具有十多年历史的小学数学奥林匹克竞赛的书发掘了出来,能放到现在挺不容易的,就拿起来随便翻翻.看了看目录, ...