题目传送门
A. There Are Two Types Of Burgers
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.

You have b buns, p beef patties and f chicken cutlets in your restaurant. You can sell one hamburger for h dollars and one chicken burger for c dollars. Calculate the maximum profit you can achieve.

You have to answer t independent queries.

Input
The first line contains one integer t (1≤t≤100) – the number of queries.

The first line of each query contains three integers b, p and f (1≤b, p, f≤100) — the number of buns, beef patties and chicken cutlets in your restaurant.

The second line of each query contains two integers h and c (1≤h, c≤100) — the hamburger and chicken burger prices in your restaurant.

Output
For each query print one integer — the maximum profit you can achieve.

Example
inputCopy
3
15 2 3
5 10
7 5 2
10 12
1 100 100
100 100
outputCopy
40
34
0
Note
In first query you have to sell two hamburgers and three chicken burgers. Your income is 2⋅5+3⋅10=40.

In second query you have to ell one hamburgers and two chicken burgers. Your income is 1⋅10+2⋅12=34.

In third query you can not create any type of burgers because because you have only one bun. So your income is zero.

题意:很简单,就是问你怎么选择制作不同汉堡的能使得卖的钱最多,一共有两种汉堡——汉堡包和鸡肉汉堡!要组装一个汉堡包,你需要两个面包和一个牛肉饼。要做一个鸡肉汉堡,你需要两个面包和一个鸡排。并给出两种汉堡的价格。问汉堡能卖的钱最大为多少?

简单判断两种汉堡价格,优先做价格高的,直接模拟即可。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
const int MM=10010;
int x,y;
int s[MM];
int a,b,c;
ll sum;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        sum=0;
        scanf("%d%d%d",&a,&b,&c);
        scanf("%d%d",&x,&y);
        if(x<y)//价格高
        {
            while(a>1)//先做y
            {
                if(c==0)
                    break;
                sum+=y;
                c--;
                a-=2;
            }
            while(a>1)
            {
                if(b==0)
                    break;
                sum+=x;
                b--;
                a-=2;
            }
        }
        else
        {
            while(a>1)
            {
                if(b==0)
                    break;
                sum+=x;
                b--;
                a-=2;
            }
            while(a>1)
            {
                if(c==0)
                    break;
                sum+=y;
                c--;
                a-=2;
            }
        }
        printf("%lld\n",sum);
    }
    return 0;
}

题目传送门

B. Square Filling
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0.

You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2×2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1≤x<n and 1≤y<m, and then set Bx,y, Bx,y+1, Bx+1,y and Bx+1,y+1 to 1.

Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B.

Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don’t have to minimize the number of operations.

Input
The first line contains two integers n and m (2≤n,m≤50).

Then n lines follow, each containing m integers. The j-th integer in the i-th line is Ai,j. Each integer is either 0 or 1.

Output
If it is impossible to make B equal to A, print one integer −1.

Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set Bx,y, Bx,y+1, Bx+1,y and Bx+1,y+1 to 1). The condition 0≤k≤2500 should hold.

Examples
inputCopy
3 3
1 1 1
1 1 1
0 1 1
outputCopy
3
1 1
1 2
2 2
inputCopy
3 3
1 0 1
1 0 1
0 0 0
outputCopy
-1
inputCopy
3 2
0 0
0 0
0 0
outputCopy
0
Note
The sequence of operations in the first example:

000→110 →110 →110
000 110 110 111
000 000 110 111

题意:给你两个矩阵A和B,每个矩阵正好包含N行和M列。a的每个元素都是0或1;b的每个元素最初是0。 您可以使用矩阵B执行一些操作。在每个操作期间,您可以选择大小为2×2的B的任何子矩阵,并将所选子矩阵中的每个元素替换为1。换句话说,选择两个整数x和y,使1≤x<n和1≤y<m,然后将bx、y、bx、y+1、bx+1、y和bx+1、y+1设置为1。
问你能否执行一些操作使得矩阵B等于矩阵A。
如果是的话,你必须想出一系列使b等于a的操作。注意,你不必最小化操作的数量。

解题:
就是按照题意枚举即可。

#include<bits/stdc++.h>
using namespace std;
bool a[55][55],b[55][55],ans[55][55];
int n,m,cnt;
int main()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin>>a[i][j];
    for(int i=1; i<=n-1; i++)//操作的范围
        for(int j=1; j<=m-1; j++)
            if(a[i][j]&&a[i+1][j]&&a[i][j+1]&&a[i+1][j+1])//四个操作
            {
                ans[i][j]=true;//标记
                cnt++;//记录操作次数
                b[i][j]=b[i+1][j]=b[i][j+1]=b[i+1][j+1]=true;//b的值标记
            }
    for(int i=1;i<=n;i++)//循环
    for(int j=1;j<=m;j++)
    if(a[i][j]!=b[i][j])//如果对应的值不相等那么必然不可能成立
    {
        cout<<-1;
        return 0;
    }
    cout<<cnt<<endl;//输出次数
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(ans[i][j])
    cout<<i<<' '<<j<<endl;
    return 0;
}