20200530混合训练2总结

Block Towers

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students’ towers.

Input
The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output
Print a single integer, denoting the minimum possible height of the tallest tower.

Examples
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
Note
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.

In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
emmm…水题,直接上代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
const int maxn=1005;
int main()
{
    int a,b;
    int m,n;
    while(cin>>m>>n)
    {
        int a=m*2,b=n*3;
        for(int i=6; i<=min(a,b); i+=6)
        {
            if(a<=b)
                a+=2;
            else
                b+=3;
        }
        cout<<max(a,b)<<endl;
    }
    return 0;
}

Buns

Lavrenty, a baker, is going to make several buns with stuffings and sell them.

Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has a i grams left of the i-th stuffing. It takes exactly b i grams of stuffing i and c i grams of dough to cook a bun with the i-th stuffing. Such bun can be sold for d i tugriks.

Also he can make buns without stuffings. Each of such buns requires c 0 grams of dough and it can be sold for d 0 tugriks. So Lavrenty can cook any number of buns with different stuffings or without it unless he runs out of dough and the stuffings. Lavrenty throws away all excess material left after baking.

Find the maximum number of tugriks Lavrenty can earn.

Input
The first line contains 4 integers n, m, c 0 and d 0 (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10, 1 ≤ c 0, d 0 ≤ 100). Each of the following m lines contains 4 integers. The i-th line contains numbers a i, b i, c i and d i (1 ≤ a i, b i, c i, d i ≤ 100).

Output
Print the only number — the maximum number of tugriks Lavrenty can earn.

Examples
Input
10 2 2 1
7 3 2 100
12 3 1 10
Output
241
Input
100 1 25 50
15 5 20 10
Output
200
Note
To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.

In the second sample Lavrenty should cook 4 buns without stuffings.

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[10005],n,m,x,y,a,b,c,d;
void init()
{
    memset(dp,0,sizeof(dp));
    for(int i=x; i<=n; i++)
        dp[i]=i/x*y;
}
int main()
{
    cin>>n>>m>>x>>y;
    init();
    for(int i=0; i<m; i++)
    {
        cin>>a>>b>>c>>d;
        for(int j=1; j<=a/b; j++)
        {
            for(int k=n; k>=c; k--)
                dp[k]=max(dp[k-c]+d,dp[k]);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Game Outcome

Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board’s squares by some tricky rules we don’t know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.
在这里插入图片描述

For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.

Input
The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Output
Print the single number — the number of the winning squares.

Examples
Input
1
1
Output
0
Input
2
1 2
3 4
Output
2
Input
4
5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3
Output
6
Note
In the first example two upper squares are winning.

In the third example three left squares in the both middle rows are winning:

5 7 8 4
9 5 3 2
1 6 6 4
9 5 7 3

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int a[32][32];
int main()
{
    int n,i,j,k,sum1 = 0,sum2 = 0,m = 0;
    scanf("%d",&n);
    for(i = 0;i < n;i++)
    {
        for(j = 0;j < n;j++)
            scanf("%d",&a[i][j]);
    }
    for(i = 0;i < n;i++)
    {
        for(j = 0;j < n;j++)
        {
            for(k = 0;k < n;k++)
            {
            sum1 += a[i][k];
            sum2 += a[k][j];
            }
            if(sum1 < sum2)m++;
            sum1 =  0;
            sum2 = 0;
        }

    }
    printf("%d\n",m);
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值