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#接口的隐式与显示实现
小弟不才,各位大牛嘴下留情... 一.对于继承类里头有相同方法时候,用接口方式去调用,会优先查走显式接口方法 例如 public interface IA { void Test(); } publi ...
- angular resolve路由
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from "@angular/router&q ...
- c++多线程基础4(条件变量)
条件变量是允许多个线程相互交流的同步原语.它允许一定量的线程等待(可以定时)另一线程的提醒,然后再继续.条件变量始终关联到一个互斥 定义于头文件 <condition_variable> ...
- 【bzoj4103】[Thu Summer Camp 2015]异或运算 可持久化trie树
Description 给定长度为n的数列X={x1,x2,...,xn}和长度为m的数列Y={y1,y2,...,ym},令矩阵A中第i行第j列的值Aij=xi xor yj,每次询问给定矩形区域i ...
- SpringMVC中视图解析器
视图解析器:固定写法直接coppy就行 1.dispatcherServlet-servlet.xml中添加 <!-- 视图解析器InternalResourceViewResolver --& ...
- Python实现KNN算法
Python实现Knn算法 关键词:KNN.K-近邻(KNN)算法.欧氏距离.曼哈顿距离 KNN是通过测量不同特征值之间的距离进行分类.它的的思路是:如果一个样本在特征空间中的k个最相似(即特征空间 ...
- [hadoop] map函数中使用FileSystem对象出现java.lang.NullPointerException的原因及解决办法
问题描述: 在hadoop中处理多个文件,其中每个文件一个map. 我使用的方法为生成一个文件,文件中包含所有要压缩的文件在HDFS上的完整路径.每个map 任务获得一个路径名作为输入. 在eclip ...
- c语言数据结构学习心得——线性表
线性表:具有相同数据类型的n(n>0)个数据元素的有限序列. 主要有顺序存储和链式存储. 顺序存储: 特点:地址连续,随机/存取,顺序存储. 建立:首地址/存储空间大小(数组),表长. 方式:静 ...
- Linux crontab定时任务命令使用记录
安装crontab 使用 crontab -v 如果提示没有该命令,则需要安装.安装也很简单,推荐使用yum安装.一条命令即可(yum install crontab),这里不多介绍. 下面是一些基础 ...
- C#图片处理3种高级应用(高缩略图清晰度、图片剪裁、图片水印)
利用C#图片处理的一些基本和高级应用,解决了显示排版时想让相片缩略图列表非常统一.整齐.和美观,每张缩略图大小固定为120 x 90且不拉伸变形,用户头像让缩略图比原图更清晰,上传的图片下加一个半透明 ...