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个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
随机推荐
- 关于eWebEditorAPI
1.获取HTML document.getElementById(Iframe的名称).contentWindow.getHTML();在线API http://www.ewebeditor.net/ ...
- c# 如何筛选datatable
对DataTable数据各种筛选 筛选一个DataTable的数据,赋值给另外一个DataTable 假设: 有2个DataTable:DataTable A.DataTable B. 要求: 筛选D ...
- 使用C#代码发送邮件,不完整的demo
作为一只入行不久的小菜鸟,最近接触到利用C#代码发送邮件,做了一点小的demo练习.首先,需要配置,这边我做的是QQ邮箱的相关的练习,练习之前,首先应该解决的问题肯定是关于服务器的配置,这边偷一个懒, ...
- C# 继承(3)
接上章代码: class NameList { public NameList() => Console.WriteLine("这个是NameList的构造函数"); ~Na ...
- kali linux之sqlmap
一款开源的命令行自动SQL注入工具,它能够对多种主流数据库进行扫描支持,基于Python环境. 检测动态页面中get/post参数,cookie,http头 数据榨取/文件系统访问 操作系统命令执行 ...
- 关于Java中SQL语句的拼接规则
实现目标语句是这个注意,这里的java变量是idd int idd; String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEE ...
- hosts是什么意思?Hosts文件有什么作用和功能?
hosts是什么意思?Hosts文件有什么作用和功能? 熟悉网络的朋友们都会用到hosts文件,针对还不清楚hosts是什么意思以及hosts文件有什么功能和作用?针对此问题,本文就为大家进行解答 ...
- 洛谷P4458 /loj#2512.[BJOI2018]链上二次求和(线段树)
题面 传送门(loj) 传送门(洛谷) 题解 我果然是人傻常数大的典型啊-- 题解在这儿 //minamoto #include<bits/stdc++.h> #define R regi ...
- Xamarin Forms:小马过河,王者归来
因为我媳妇的原因,去年下半年从零开始学习Android原生开发,做了一个答题库app.整体给我的感觉是入门难度不大,前期折腾一番,大部分时间都是花在开发上面,其实任何一门语言都是如此. 今年我又有另一 ...
- Ntrip协议使用流程及服务器实现架构
Ntrip协议 在RTK接收机中,有多种方式获取到差分数据:电台.挂外串口.网络等.其中网络方式适合在有网络基准站的地区,省掉携带多一台RTK接收机来完成工作. CORS是网络基准站,通过网络收发GP ...