Kattis-Another Brick in the Wall
Posted 做一个AC梦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kattis-Another Brick in the Wall相关的知识,希望对你有一定的参考价值。
题目所述基本内容
The construction worker previously known as Lars has many bricks of height 1 and different lengths, and he is now trying to build a wall of width w and height h. Since the construction worker previously known as Lars knows that the subset sum problem is NP-hard, he does not try to optimize the placement but he just lays the bricks in the order they are in his pile and hopes for the best. First he places the bricks in the first layer, left to right; after the first layer is complete he moves to the second layer and completes it, and so on. He only lays bricks horizontally, without rotating them. If at some point he cannot place a brick and has to leave a layer incomplete, then he gets annoyed and leaves. It does not matter if he has bricks left over after he finishes.
Yesterday the construction worker previously known as Lars got really annoyed when he realized that he could not complete the wall only at the last layer, so he tore it down and asked you for help. Can you tell whether the construction worker previously known as Lars will complete the wall with the new pile of bricks he has today?
输入输出样例
Input
The first line contains three integers h, w, n (1≤h≤100, 1≤w≤100, 1≤n≤10000), the height of the wall, the width of the wall, and the number of bricks respectively. The second line contains n integers xi (1≤xi≤10), the length of each brick.
Output
Output YES if the construction worker previously known as Lars will complete the wall, and NO otherwise.
代码
#include<iostream>
#include<algorithm>
using namespace std;
int main()
int h, w, n;
int sum = 0;
cin >> h >> w >> n;
int a[10000];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
sum = sum + a[i];
if (sum == w)
sum = 0;
else if (sum > w)
cout << "NO" << endl;
return 0;
cout << "YES" << endl;
结束语
好兄弟好兄弟,留下你的关注和点赞,666走一波!!!!!
以上是关于Kattis-Another Brick in the Wall的主要内容,如果未能解决你的问题,请参考以下文章