codeforces A. Valera and Plates 题解

Valera is a lazy student. He has m clean bowls and k clean
plates.

Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish,
he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls
or plates.

When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn‘t let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find
the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.

Input

The first line of the input contains three integers nmk (1?≤?n,?m,?k?≤?1000) —
the number of the planned days, the number of clean bowls and the number of clean plates.

The second line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?2).
If ai equals
one, then on day i Valera will eat a first type dish. If ai equals
two, then on day i Valera will eat a second type dish.

Output

Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.

Sample test(s)

input

3 1 1
1 2 1

output

1

input

4 3 1
1 1 1 1

output

1

input

3 1 2
2 2 2

本题也是使用暴力法了。

最难的就是读懂题目了。原来这个家伙这么赖,一次只洗一个碗,从不肯多洗。

有两个思路:

1 模拟他洗碗的过程

2 计算多少碟菜,多少个碗和碟,然后进行加减处理

两种方法都需要O(n)时间效率。

方法1:

void ValeraandPlates()
{
	int days, b, p, dishType, times = 0;
	cin>>days>>b>>p;
	for (int t = 0; t < days; t++)
	{
		cin>>dishType;
		if (1 == dishType)
		{
			if (b <= 0)
			{
				times++;
			}
			b--;
		}
		else
		{
			if (b <= 0 && p <= 0)
			{
				times++;
			}
			if (p) p--;
			else b--;
		}
	}
	cout<<times;
}

方法二:

void ValeraandPlates_2()
{
	int days, b, p, dishType, times = 0, A[3] = {0};
	cin>>days>>b>>p;
	for (int t = 0; t < days; t++)
	{
		cin>>dishType;
		A[dishType]++;
	}
	A[2] -= p;
	if (A[2] >= 0) b -= A[2] + A[1];
	else b -= A[1];

	if (b >= 0) cout<<0;
	else cout<<-b;
}

codeforces A. Valera and Plates 题解,码迷,mamicode.com

时间: 2024-10-28 16:36:05

codeforces A. Valera and Plates 题解的相关文章

Codeforces A. Valera and X 题解

判断二维字符串是否满足下面条件: on both diagonals of the square paper all letters are the same; all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the progra

CodeForces 369A Valera and Plates( 水)

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int bowl,plate; int n; int dish[1100]; int main() { int i,j; while(scanf("%d%d%d",&n,&bowl,&plate)!=EOF) { int ans

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

codeforces A. Shaass and Oskols 题解

Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delici

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces D. Giving Awards 412 题解

就是按照一定顺序输出排序. 比如a欠b的钱就不能先输出a然后输出b. 本题的技巧就是,要求的是不能先输出a然后输出b,但是可以先输出b然后输出a. 故此可以按照a欠b的钱的关系,建立图,然后DFS深度优先搜索,然后逆向记录点,输出这些逆向点,也就是a欠b的钱,就先输出b然后输出a,那么这个顺序就满足要求了. 很狡猾的题意.要细心.不然就搞半天都白搞了. 题目连接:http://codeforces.com/problemset/problem/412/D #include <stdio.h>

codeforces A. Slightly Decreasing Permutations 题解

Permutation p is an ordered set of integers p1,??p2,??...,??pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation

Codeforces Round #259 (Div. 2) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

Codeforces 441C Valera and Tubes

题目链接:Codeforces 441C Valera and Tubes 没看到r >= 2一直错.让前几个管子占用2个格子.最后一个把剩下的都占用了.假设问题有解.这样做一定有解.其它策略就不一定了(比方让某个管子占用了3个格子.而总共同拥有四个格子,两个管子). #include <iostream> #include <cstdio> using namespace std; int main() { int n, m, k; scanf("%d%d%d&q