首页 > 其他分享 >atcoder ABC 356-B题详解

atcoder ABC 356-B题详解

时间:2024-06-04 13:31:02浏览次数:16  
标签:atcoder ABC 20 goal int long 356 units 100

atcoder ABC 356-B题详解

Problem Statement

Takahashi is health-conscious and concerned about whether he is getting enough of M types of nutrients from his diet.

For the i-th nutrient, his goal is to take at least Ai​ units per day.

Today, he ate N foods, and from the i-th food, he took Xi,j​ units of nutrient j.

Determine whether he has met the goal for all M types of nutrients.

Constraints

1≤N≤100
1≤M≤100
0≤Ai​,Xi,j​≤107
All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
A1​ … AM​
X1,1​ … X1,M​

XN,1​ … XN,M​

Output

Print Yes if the goal is met for all M types of nutrients, and No otherwise.

Sample Input 1

2 3
10 20 30
20 0 10
0 100 100

Sample Output 1

Yes
For nutrient 1, Takahashi took 20 units from the 1-st food and 0 units from the 2-nd food, totaling 20 units, thus meeting the goal of taking at least 10 units.
Similarly, he meets the goal for nutrients 2 and 3.

Sample Input 2

2 4
10 20 30 40
20 0 10 30
0 100 100 0

Sample Output 2

No
The goal is not met for nutrient 4.

思路分析:

本题需要比较每天摄入的总量和目标值的比较,可以定义一个数组来存储每天摄入的总量来对目标值进行比较,定义一个ans来计数,表示摄入量达标了几天。

code:

#include <iostream>
using namespace std;
int n,m,x1;
const int N=110;
long long a[N];
long long x[N][N];
long long b[N];
int ans=0;
int main(int argc, const char * argv[]) {
    cin>>n>>m;
    for(int i=1;i<=m;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) cin>>x[i][j];
    for(int j=1;j<=m;j++)
        for(int i=1;i<=n;i++) b[j]=b[j]+x[i][j];
        for(int i=1;i<=m;i++){
            if(b[i]>=a[i]){
                ans++;
            }
        }
        if(ans==m) cout<<"Yes";
        else cout<<"No";
        return 0;
}

标签:atcoder,ABC,20,goal,int,long,356,units,100
From: https://blog.csdn.net/2301_80662593/article/details/139440239

相关文章

  • ABC356
    A.SubsegmentReverse模拟代码实现n,l,r=map(int,input().split())l-=1a=list(range(1,n+1))a[l:r]=a[l:r][::-1]print(*a)B.Nutrients模拟代码实现#include<bits/stdc++.h>#definerep(i,n)for(inti=0;i<(n);++i)usingnamespacest......
  • ABC 307 D Mismatched Parentheses
    题解现在有个长度为N的字符串s,其中s由(,)和小写字母组成,每个)都要与其左边的(配成一对,并且将他们和中间的部分给删除掉。输出最后的s思路我们首先设最后的答案为空串,然后模拟整个过程就行了,一旦遇到(,我们就用cnt进行计数。一旦遇到),就在答案里一直删直到遇到最近的(为止。其......
  • ABC 309 E Family and Insurance
    题意一个家庭用一颗树来表示。其中有m个人买了保险,x[i]买的保险可以继承y[i]代,请问有多少人至少有一份保险思路感觉是比较水的E题了,我们采取bfs遍历,然后类似于最短路的想法来更新每个点可以继承的最大保险代数。最后扫一遍所有人,看他们的dis有多少大于等于0,即为答案(dis最初所有......
  • ABC 308E MEX
    题意给定长度为N的包含0,1,2的a序列,和一个长度为N的包含字符M,E,X的字符串s。对于所以符合条件的1<=i<j<k<=N,使得s[i]s[j]s[k]=="MEX"的三元组(i,j,k),请你求出所有mex(a[i],a[j],a[k])之和。mex()函数表示未出现在序列中的最小非负整数。思路我们先看一个非常典的题目,给你一串由a......
  • ABC 310 E NAND repeatedly
    题意太懒了,直接给链接吧,题意挺好懂的。https://atcoder.jp/contests/abc310/tasks/abc310_e思路NAND运算,根据题意,我们可以总结出以下两点:当前结果如果遇到1,那么结果反转(0->1,1->0)当前结果如果遇到0,那么结果赋值为1我们手模一下这个样例1:00110(初始)01011(i==1)×0101(i==......
  • ABC 311 C Find it!
    题意给定一个有向图,其中有N个顶点和N条边。保证其中有一个环,请找出这个环并且输出环上的点。思路我们先将图dfs一遍,遍历到的点我们用map进行标记一下,并且储存在一个数组里面,当我们dfs到一个已经标记过的点时,此时则出现了环。那么如何将这个环输出出来呢?我们这个时候扫一遍刚刚......
  • ABC 312 E Tangency of Cuboids
    题意给定三维空间的n个长方体,每个长方体以其一条体对角线的坐标形式给出,即对于每一个长方体i,其一条体对角线的两个端点的坐标会给出。现在对于每一个给出的长方体,求出其它给出的长方体,与其共面的长方体个数。(保证每个长方体两两不相交)思路首先我们第一个关注的应该是坐标的数......
  • ABC 312 F Cans and Openers
    题意现在有三种物品,给出的格式为(t[i],x[i])如下:拉环罐头,被标记为t[i]=0,得到即食,可以得到x[i]的开心值。普通罐头,被标记为t[i]=1,需要用开罐器打开,食用后可以得到x[i]的开心值。开罐器,被标记为t[i]=2,使用后可以打开x[i]个普通罐头。现在有N个这样的物品,你可以选择其中的......
  • ABC 313C Approximate Equalization 2
    题意现在给出一个数组a[n],现在你可以进行这种操作:选择i,j(1<=i,j<=n),使得a[i]=a[i]-1,a[j]=a[j]+1现在你可以进行无限次这种操作,现在需要你求出最少次数,使得数组中的最大值与最小值之间的差不超过1。思路我们考虑到每一次操作可以使得数组中的一个数加一,另一个数减一,那么无......
  • [ABC238E] Range Sums
    原题链接题解把这里的数字看成间隔,不要看成点假设已知能和\(l\)组成区间的端点集合\(A\)和以\(r\)组成区间的端点集合\(B\),这时候加入一个以\(l,r\)为左右端点的区间,那么在加入区间\(l,r\)之后,这两个集合可以合并code#include<bits/stdc++.h>usingnamespacestd......