首页 > 其他分享 >「Codeforces」寒假训练 2023 #4

「Codeforces」寒假训练 2023 #4

时间:2023-01-11 16:25:34浏览次数:61  
标签:cin int ll 2023 Codeforces long sign 寒假 ans

A. Coprime

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int t, n, ans;
map<int, int> mp;
int gcd(int u, int v)
{
	return v == 0 ? u : gcd(v, u % v);
}
int main()
{
	cin >> t;
	while(t--)
	{
		ans = 0;
		mp.clear();
		cin >> n;
		for(int i = 1; i <= n; i++) 
		{
			int x;
			scanf("%d", &x);
			mp[x] = i;
		}
		for(int i = 1; i <= 1000; i++)
		{
			for(int j = 1; j <= 1000; j++)
			{
				int _gcd = gcd(i, j);
				if(_gcd == 1 && mp.count(i) && mp.count(j)) ans = max(ans, mp[i] + mp[j]);
			}
		}
		if(ans == 0) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

B. Run For Your Prize

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6;
int n, ans;
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		ans = max(ans, min(x - 1, N - x));
	}
	cout << ans << endl;
	return 0;
}

C. Vasya and Robot

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, l, r, ql, qr, ans = 2e9;
int w[N], s[N];
int main()
{
	cin >> n >> l >> r >> ql >> qr;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", w + i);
		s[i] = s[i - 1] + w[i];
	}
	for(int i = 1; i <= n + 1; i++)
	{
		int res = 0;
		int minus = (n - i + 1) - (i - 1);
		if(minus > 0) res += (abs(minus) - 1) * qr;	
		else if(minus < 0) res += (abs(minus) - 1) * ql;
		res += (s[i - 1] - s[0]) * l + (s[n] - s[i - 1]) * r;
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}

D. Alternating Subsequence

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int t, n;
int main()
{
	cin >> t;
	while(t--)
	{
		scanf("%d", &n);
		ll sum = 0;
		ll pos = -2e9, neg = -2e9;
		int sign = 0;
		for(int i = 0; i < n; i++)
		{
			ll x;
			scanf("%lld", &x);
			if(x > 0)
			{
				if(sign == -1)
				{
					pos = -2e9;
					sum += neg;
				}
				sign = 1;
				pos = max(pos, x);
			}
			else if(x < 0)
			{
				if(sign == 1)
				{
					neg = -2e9;
					sum += pos;
				}
				sign = -1;
				neg = max(neg, x);
			}
		}
		if(sign == 1) sum += pos;
		else if(sign == -1) sum += neg;
		printf("%lld\n", sum);
	}
	return 0;
}

E. Move and Turn

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, p;
int main()
{
	cin >> n;
	p = n / 2;
	if(n % 2) cout << 2 * (p + 1) * (p + 2) << endl;
	else cout << (p + 1) * (p + 1) << endl;
	return 0;
}

标签:cin,int,ll,2023,Codeforces,long,sign,寒假,ans
From: https://www.cnblogs.com/YuukiAsuna/p/17044108.html

相关文章

  • Educational Codeforces Round 1
    Problem-A-Codeforcesvoidsolve(){ios;intt;cin>>t;while(t--){intn;cin>>n;intsum=n*(n+......
  • 2023年,新的一年,新的目标和希望
    时间在不知不觉中走进了2023年。最近繁琐的工作,各种不同的声音,还有来自背后的压力。有的时候,感觉自己很茫然,但每天一睁眼,脑海里已经在考虑今天的工作怎么安排,有哪些需要......
  • 【2023.01.11】PVE设置网卡直通
    打开直通nano/etc/default/grub注释并添加#GRUB_CMDLINE_LINUX_DEFAULT="quiet"GRUB_CMDLINE_LINUX_DEFAULT="quietintel_iommu=on"更新配置update-grub安装模......
  • Namomo Winter Camp 2023 Day 2
    A-MixJuice排个序再求和就好#include<bits/stdc++.h>usingnamespacestd;intread(){...}int32_tmain(){intn=read(),k=read();vector<int>......
  • 一个CF1775C(Codeforces Round #843 (Div. 2))的小技巧
    若\(n\)的第\(i\)位为\(1\),而我们需要不断令\(n+1\)找到下一个最小的\(k\),使得\(k\)的第\(i\)位为\(0\)。技巧:假设\(n\)为10101[1]1001,括号内是要求的第\(i\)位那么先......
  • 2023-01-11 小程序 Empty file is NOT a valid json file
    问题描述:wepy小程序预览时报错,说我的一个json文件是空文件,就是没代码,空的。原因:不详,我估计是微信开发者工具的问题。解决方案:删掉dist包,重新npmrunbuild打包,然后在微信......
  • CF Codeforces Round #843 (Div. 2)
    CodeforcesRound#843(Div.2)本次脑袋不大灵光,一方面可能是怕掉分。另一方面就是交的人实在是太少了,导致我一直不敢交,其实这场cf没有我想象中那么难,甚至来说我一直是......
  • 【2023-01-04】父母使命
    20:00白的米饭、甜的果子是平凡的,然能适合大多数人的胃口,所以是最好的食物,艺术也是一样。                        ......
  • 【2023-01-03】除旧迎新
    20:00多美好的一天呵!花园里干活儿,晨雾已消散,蜂鸟飞上忍冬的花瓣。世界上没有任何东西我想占为己有,也没有任何人值得我深深抱怨;那身受的种种不幸我早已忘却,依然故我的思想......
  • Educational Codeforces Round 141
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1783。CF车队翻车咯,本来上大分,喜提skippedA如果所有数均相等则无解。否则先降序排序......