A-骰子魔术_牛客小白月赛98 (nowcoder.com)
直接判断这个数在数组里有没有就行
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x;
ll a[505];
void solve()
{
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
{
if(a[i]==x)
{
cout<<"YES"<<endl;
return;
}
}
cout<<"NO"<<endl;
return;
}
int main()
{
cin>>n>>x;
solve();
return 0;
}
B-最少剩几个?_牛客小白月赛98 (nowcoder.com)
先得到奇数和偶数的个数,我们不难想到若两个数相加为奇数,那必然是一个偶数加一个奇数,若两个数数相乘为奇数必然是两个数为奇数,即我们进行捆绑,把一个偶数和奇数看成一对,当偶数多于奇数时,偶数-奇数=最少的个数,当奇数多于偶数时,若奇数-偶数的个数为偶,则不会有剩余的,若为奇则会有一个剩余
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[1000010];
void solve()
{
for(int i=1;i<=n;i++)
cin>>a[i];
ll t1,t2;
for(int i=1;i<=n;i++)
{
if(a[i]%2)
t1++;
else
t2++;
}
if(t2>t1)cout<<t2-t1<<endl;
else {
if((t1-t2)%2)
cout<<"1"<<endl;
else
cout<<"0"<<endl;
}
return;
}
int main()
{
cin>>n;
solve();
return 0;
}
C-两个函数_牛客小白月赛98 (nowcoder.com)
这道题需要我们发现规律,g(x)我们通过计算可以发现=f(a)+f(2a)+...+f((x-1)a),又f(x)=ax,则g(x)=a*a*((x*x-x)/2),再进行mod即可
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
ll a,x;
void solve()
{
if(x==1){
cout<<a%mod<<endl;
return;
}
ll t1=a*a%mod;
ll t2=((x*x-x)/2)%mod;
ll ans=t1*t2%mod;
cout<<ans<<endl;
}
int main()
{
int q;
cin>>q;
while(q--){
cin>>a>>x;
solve();
}
return 0;
}
思路:
判断字符串首字符即可
代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
using namespace std;
typedef long long ll;
priority_queue<int, vector<int>, greater<int>> pq;
map<int, int>mp;
void solve()
{
int r, g, b;
cin >> r >> g >> b;
string c;
cin >> c;
if (c[0]=='R')
{
if (g > b)
cout << b << endl;
else
cout << g << endl;
return;
}
else if (c[0]=='B')
{
if (r > g)
cout << g << endl;
else
cout << r << endl;
return;
}
else
{
if (r > b)
cout << b << endl;
else
cout << r << endl;
return;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
B - Right Triangle (atcoder.jp)
思路:
三个变量代表三条边的长度(只要满足一次两边平方和==第三边平方和即可,记得在满足条件前先判定三条边是否能构成三角形即不在同一直线上)
代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
using namespace std;
typedef long long ll;
priority_queue<int, vector<int>, greater<int>> pq;
map<int, int>mp;
int a[3];
void solve()
{
int x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
int ac = pow(x1 - x2, 2) + pow(y1 - y2, 2);
int ab = pow(x2 - x3, 2) + pow(y2 - y3, 2);
int bc = pow(x1 - x3, 2) + pow(y1 - y3, 2);
if ((x1 - x2) * (y2 - y3) != (x2 - x3) * (y1 - y2))
{
if (ac + bc == ab || bc + ab == ac || ab + ac == bc)
{
cout << "Yes" << endl;
return;
}
else
{
cout << "No" << endl;
return;
}
}
cout << "No" << endl;
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
将左边界和右边界的所有数都加起来,若同时满足左边界<=0且右边界>=0则一定可以找到相应的序列,否则就不能,用一个变量记录左边界的全部和sum(最小值,还用一个数组来记录序列,初始化为左边界的数),我们一轮一轮的来看,得到每一轮的左右边界差,若能够使sum>=0则记录序列的数组相应的位置要变成能够使sum=0的值,否则让sum加上这一轮的边界查且当前序列数组变成这一轮的右边界
代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
using namespace std;
typedef long long ll;
priority_queue<int, vector<int>, greater<int>> pq;
map<int, int>mp;
const int n = 2e5 + 10;
int ans[n];
int l[n], r[n];
void solve()
{
int x;
cin >> x;
int sumr = 0,suml=0;
for (int i = 1; i <= x; i++)
{
cin >> l[i] >> r[i];
sumr += r[i];
suml += l[i];
}
int sum = 0;
if (suml <= 0 && sumr >= 0)
{
cout << "Yes" << endl;
for (int i = 1; i <= x; i++)
{
ans[i] = l[i];
sum += l[i];
}
for (int i = 1; i <= x; i++)
{
if (r[i] - l[i] + sum < 0)
{
sum += (r[i] - l[i]);
ans[i] = r[i];
}
else
{
ans[i] -= sum;
sum = 0;
break;
}
}
for (int i = 1; i <= x; i++)
cout << ans[i] << " ";
}
else
{
cout << "No" << endl;
return;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
标签:奇数,int,ll,long,牛客,solve,补题,ABC362,include
From: https://blog.csdn.net/xxx_jsu/article/details/140413238