首页 > 其他分享 >Codeforces div2 #836

Codeforces div2 #836

时间:2022-11-28 00:00:14浏览次数:56  
标签:std 836 int Codeforces div2 solve const include 我们

B

核心思路:这题我们会发现其实n为奇数的时候是非常好处理的。主要是n为偶数。我们不能难发现,奇数其实就是偶数的扩展情况,这里其实主要有点比较难看出1 2 3这个的关系,但是我们可以套值,毕竟B题难不到那里去的。、

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
void solve()
{
	int n;
	cin >> n;
	if ((n & 1) == 0)
	{
		for (int i = 1;i <= n-2;i++)
			cout << 2 << " ";
		cout << 1 << " " << 3 << endl;
	}
	else
	{
		for (int i = 0;i < n;i++)
			cout << 7 << " ";
		cout << endl;
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}
		solve();
	}
}

C

核心思路:这里其实我们发现大部分数都可以a[i]=i,但是有个比较难处理的点就是n应该放在哪里呢。我们通过模拟下可以发现,n一定是放在x的倍数上面,所以如果\(x|n\)不为整数,那么就一定没有解.我们会发现原先的a[x]应该放x,但是x已经放在1那里了,所以我们只能尽量放x的最小倍数。这个我们可以把这个倍数:\(d=\frac{n}{x}\).分解质因数,然后每次乘上我们分解的质因数,那个数组的下标也就是相应变化的..

#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int a[N];
void solve()
{
	int n, x;
	cin >> n >> x;
	if (n % x)
	{
		cout << -1 << endl;
		return;
	}
	memset(a, 0, sizeof 0);
	for (int i = 1;i <= n;i++)
		a[i] = i;
	a[1] = x;
	a[n] = 1;
	int dx = n / x;
	int now = x;
	for (int i = 2;i <= dx / i;i++)
	{
		while (dx % i == 0)
		{
			a[now] = i * now;
			now = i * now;
			dx /= i;
		}
	}
	if (dx != 1)
		a[now] = now * dx;
	for (int i = 1;i <= n;i++)
		cout << a[i] << " ";
	cout << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

D

核心思路:其实这个题目并不算难,既然可以开平方那就说明肯定是\(a*n^2\),我们可以取a=4,那么开根号就是2*n;我们可以假设\(a_1=5*n,a_n=3*n\),然后去构造中间的数。并且需要保证这两个数是最大值和最小值。

我们可以构造一下数列:

\(5*n,4*n-1,4*n-2\cdots,4*n+1,4*n+2,3*n\)

我们可以发现这样并不会超过我们的最大值和最小值,因为最大也只是\(4*n+\frac{n}{2}\).ok,上代码.

#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int a[N];
void solve()
{
	int n;
	cin >> n;
	a[1] = 5 * n;
	for (int i = 1;i <= n;i++)
		a[i] = 4 * n;
	int t = n / 2;
	int i = 1;
	int j = 1;
	for (i = 1;i <= t;i++, j++)
	{
		a[i] -= j;
	}
	i--;
	if (n & 1)
		i += 2;
	else
		i += 1;
	for (j = 2;i <= n;i++, j++)
		a[i] += j;
	a[1] = 5 * n;
	a[n] = 3 * n;
	for (int i = 1;i <= n;i++)
		cout << a[i] << " ";

	cout << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

比赛链接

标签:std,836,int,Codeforces,div2,solve,const,include,我们
From: https://www.cnblogs.com/xyh-hnust666/p/16931075.html

相关文章

  • 『题解』Codeforces 1758B XOR = Average
    Description构造一个\(a\)序列,使\(a_1\oplusa_2\oplusa_3\oplus\cdots\oplusa_n=\dfrac{sum(a)}{n}\)。Solution第一眼看到这道题,我想到的是分情况讨论。......
  • Codeforces Round #739 (Div. 3) F1
    F1.NearestBeautifulNumber(easyversion)很像网络赛北大出的那题感觉这题是简化版我们只需要把所有数都搞出来然后二分即可我们先枚举k1的情况这个很简单先枚......
  • 『题解』Codeforces 808D Array Division
    题目传送门解题思路首先统计\(n\)个数字和为\(sum\),那么一半就是\(sum=sum\div2\)从\(1\)到\(n\)枚举,累计进前缀和\(ans\)中,如果发现第\(i\)个数字累......
  • 『题解』Codeforces 1743A Password
    Problem现有\(4\)位密码,满足以下条件:给定数位的集合\(S\),密码中没有用到这些数位。密码中恰好包含两个数位,每个数位出现了两次。求符合条件的密码个数。Solution......
  • 『题解』Codeforces 1742C Stripes
    Problem在\(8\times8\)的网格上,轮流染上红色和蓝色。红色只能染一整行。蓝色只能染一整列。问最后用的是哪种颜色。Solution题目说明了至少会染一个条纹,所以我......
  • 『题解』Codeforces 1702A Round Down the Price
    题意这道题其实就是让你求出当前数字与\(10\)的整数幂次的差值(注意不能向上取,只能向下取)。而且题目也标注了\(1\lek\le9\),所以我们可以让\(i\)从\(0\sim9\)......
  • Codeforces Round #836 (Div. 2) A-D
    比赛链接A题意给一个字符串\(s\),对其加倍,即每个字符后面追加一个相同字符。加倍后可以重排列,要求构造一个回文串。题解知识点:构造。既然可以重排列了,那顺序是随意......
  • Codeforces Round #825 (Div. 2)
    A核心思路:这题的第一反应是直接统计a所有的0的数目和b所有的0的数目,然后两式相减。但是我们会发现一个问题,因为有些是可能不需要排序的,所有还有记录下a和b所有不同的个数......
  • 【解题报告】CF DIV2 #ROUND 717 A~C D(只有思路)
    【解题报告】CFDIV2#ROUND717A~D​​比赛链接​​排名3694,终于上分了,回归pupil好耶A.TitforTat思路简单的贪心,字典序最小那就让前面的-1,然后+1全部加到最后一个数......
  • 【解题报告】CF DIV2 #ROUND 715 A~D
    【解题报告】CFDIV2#ROUND715A~D​​比赛链接​​​rating,已经无所谓了hhB想了个假算法,卡了半天,C也没时间看,我蠢爆了。A.AverageHeight思路速A了,先把奇数全部输出,然......