首页 > 其他分享 >牛客小白月赛98+ABC362补题

牛客小白月赛98+ABC362补题

时间:2024-07-15 21:26:42浏览次数:16  
标签:奇数 int ll long 牛客 solve 补题 ABC362 include

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;
}

A - Buy a Pen (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;
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;
}

C - Sum = 0 (atcoder.jp)

将左边界和右边界的所有数都加起来,若同时满足左边界<=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

相关文章

  • [ABC362E]Count Arithmetic Subsequences
    题目大意给定\(N\)个数字的序列,每个元素为\(a[i]\),问长度为i的数字序列是由多少个子序列构成的?定义数字序列:如果\(a[i]-a[j]==a[k]-a[i]\),则\(a[j],a[i],a[k]\)构成数字序列数据范围\(N\leq80,a_i\leq10^9\)题解一看到这个数据范围,就和\(a[i]\)没关系,肯定是和\(N\)有......
  • [ABC362C]Sum = 0
    题目大意给定\(N\)个区间,每个区间有左端点和右端点,问从每个区间选择一个数字,使得这些数字加起来为0,如果能,输出“Yes”,并且输出这些数字,否则输出“No”,题解这个题如果只是输出Yes或者No,我们将所有的左端点加起来,所有的右端点加起来,这就是所有数的范围,如果这个范围内有0,则是Yes,否......
  • 牛客周赛 Round 51
    A.小红的同余思路+解法:找到唯一一个x满足2x%m=1(0<=x<m)  就可以推出(m+1)*2即可Code: #include<bits/stdc++.h>usingnamespacestd;intmain(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);intm;cin>>m;......
  • 2024/7/13 ABC362 比赛记录
    7/14:昨晚打的abc,外面下着大雨;1650ptsrank975T1:简单签到题,愣是被我拖了7min死因:开赛时老师开始收手机,一直叫我名,我一着急装了两个翻译插件,导致页面错版。时间宝贵,于是我艰难的对照样例勉强读懂题(T2:计算几何?给平面直角坐标系3点,判rt三角形。直接double勾股定理算边......
  • 题解:AT_abc362_d [ABC362D] Shortest Path 3
    一句话题意:给定一个带点权的有权无向连通图,求点1到所有其它点的最短路径。首先,只有1一个起点,所以是单源最短路,又因为最大是\(2\times10^5\),所以是优先队列(堆)优化过后的Dijkstra。所以,我们只需要解决点权的问题就好了。一种显而易见的想法是把与这条边的边权加上起终点......
  • AtCoder Beginner Contest 362 补题记录(A~E,G)
    A分三类情况讨论即可。voidsolveqwq(){intr=io.read(),g=io.read(),b=io.read();stringqwq=io.readstring();if(qwq=="Blue")printf("%lld\n",min(r,g));elseif(qwq=="Red")printf("%lld\n",......
  • 题解:AT_abc362_c [ABC362C] Sum = 0
    很好写(15min解决)但不好讲(跟别人讲了20min)的写法QwQ……首先,咱先算出原式的范围。最小值(暂且记为\(k\))的公式就是:\[k=\sum_{i=1}^{N}L_i\]就是每一个最小可能值的和。同理,最大值(我记为\(w\))的公式就是:\[w=\sum_{i=1}^{N}R_i\]即最大可能值的和。算这玩意儿......
  • D-走一个大整数迷宫(牛客月赛97)
    题意:给两个n行m列的矩阵a和b,计数器,只有当计数器的值模(p-1)时出口才打开,要从左上走到右下,求最快多久走出迷宫。分析:无论2的bij次方有多大p的2的bij次方的次方取模(p-1)都为1,所以cij=aij。用bfs搜索最短路径代码:#include<bits/stdc++.h>usingnamespacestd;structA{   i......
  • 精选力扣,牛客链表面试题
    ......
  • 个人赛补题
    round1范围很小用暴力+贪心,左右枚举,先拿再放。尽量放小的所以需要排下序includeinclude"map"include"algorithm"include"cmath"include"vector"include"set"include"queue"defineintlonglongusingnamespacestd;void......