A.打靶
题意:
小蓝在玩打靶游戏,每打到一个靶子得1分,当前一共n个靶子,还剩m个靶子没打,并且小蓝当前的分数是x,问当全部打完后分数是否有可能为y分。
思路:这道题是很简单的模拟题只要用总共会出现的靶子数量减去已出现的,然后加上已得到的分数X,判断
是否有可能总分为Y就可以,但是要当前分数大于y的情况
代码:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
void test()
{
ll n,m,x,y;
cin>>n>>m>>x>>y;
y-=x;
n-=m;
// x+=n;
if(n>=y&&y>=0)
{
cout<<"Yes"<<endl;
}else
{
cout<<"No"<<endl;
}
}
int main() {
ll n;
cin>>n;
while(n--)
test();
return 0;
}
B小蓝的疑惑
题意;
给定gcd(a, b) 和 lcm(a, b)这两个数,要你求出符合gcd和lcm的a和b,如果有多个答案队,则输出a最小的答案队;如果a相等,则输出a最小同时b最小的答案对。如果无法求出a、b,则输出-1。
思路:数学知识:gcd(a, b) * lcm(a, b) == a * b; 同时因为a是最小的,则a只可能是gcd(a, b),因为最大公约数的最小值就是其本身 ,所以根据前面的数学知识,b就为lcm(a, b)。如果给定的gcd不是lcm的因子,则无法得到答案,输出-1:因为gcd是a和b的因子,而a和b又是lcm的因子,所以gcd是lcm的因子。这里的思路是照搬别人的,因为我个人的思路是有点混沌
代码:
#include<bits/stdc++.h>
using namespace std;
int t;
int x, y;
void solve()
{
cin >> x >> y;
if(y % x != 0)
{
cout << -1 << endl;
return;
}
cout << x << " " << y << endl;
}
int main()
{
cin >> t;
while (t--)
{
solve();
}
return 0;
}
C.K级数列
链接:C-k级序列_牛客小白月赛84 (nowcoder.com)
题意:给定一个序列a和k值,询问是否存在一个数列b,使得|ai−bi|≤k|,其中为为i为[1,n],并且b数组为非递减数组。
思路:因为|ai−bi|≤k,所以bi的取值范围就是[ai−k,ai+k],因为要满足b数组是非递减,所以贪心要尽可能选择b数组满足条件的同时尽可能小。
又因为只要a数组后一个数比前一个数大,就一定有答案,否则前面的数也无解。
所以,如果a数字当前的数的取值范围ai+k比前一个数的最小选择范围还要小,则无解。
代码:
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
void test()
{
ll n,m,cn=0;
bool t=false;
cin>>n>>m;
vector<ll>v(n+1);
vector<ll>a(n+1);
vector<ll>b(n+1);
for(int i=1;i<=n;i++)
{
cin>>v[i];
a[i]=v[i]-m;
b[i]=v[i]+m;
}
ll tem=a[1];
for(int i=2;i<=n;i++)
{
if(b[i]>=tem)
{
tem=max(a[i],tem);
}else{
cout<<"No"<<endl;
return ;
}
}
cout<<"Yes"<<endl;
return ;
}
int main() {
ll n;
cin>>n;
while(n--)
test();
return 0;
}
等期末结束就来补DEF
比赛主页:
牛客小白月赛84_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)
浙公网安备 33010602011771号