当前位置: 移动技术网 > 科技>操作系统>windows > JZOJ 4282. 【NOIP2015模拟10.29B组】平方数游戏【暴力】

JZOJ 4282. 【NOIP2015模拟10.29B组】平方数游戏【暴力】

2020年10月23日  | 移动技术网科技  | 我要评论
无了...


题意:

在这里插入图片描述


分析:

考场上用模拟退火拿了 7 6 ′ 76' 76哈哈哈
愉快打表找规律,只要胆子大,题题都拿下
根据打表,莽撞猜测一下,当 n n n足够大的时候,答案奇数是 1 1 1,偶数是 0 0 0
再仔细观察,会有 x 2 − ( x + 1 ) 2 − ( x + 2 ) 2 + ( x + 3 ) 2 = 4 x^2-(x+1)^2-(x+2)^2+(x+3)^2=4 x2(x+1)2(x+2)2+(x+3)2=4,那对于相邻的两组,后一组取反下就是 4 − 4 = 0 4-4=0 44=0
就是 x 2 − ( x + 1 ) 2 − ( x + 2 ) 2 + ( x + 3 ) 2 − ( x + 4 ) 2 + ( x + 5 ) 2 + ( x + 6 ) 2 − ( x + 7 ) 2 = 0 x^2-(x+1)^2-(x+2)^2+(x+3)^2-(x+4)^2+(x+5)^2+(x+6)^2-(x+7)^2=0 x2(x+1)2(x+2)2+(x+3)2(x+4)2+(x+5)2+(x+6)2(x+7)2=0
但对于 n < 6 n<6 n<6时我们需要自己打表下


代码:

#pragma GCC optimize(2)
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<ctime>
#define LL long long
#define down 0.993
using namespace std;
inline LL read() {
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
int main()
{
	freopen("five.in","r",stdin);
	freopen("five.out","w",stdout);
	int n=read();
	if(n==1) return !printf("1\n-1");
	if(n==2) return !printf("3\n1 -1");
	if(n==3) return !printf("4/n1 1-1");
	if(n==4) return !printf("2\n1 1 1 -1");
	if(n==5) return !printf("3\n-1 1 1 1 -1");
	if(n%4==1||n%4==2) printf("1\n");
	else printf("0\n");
	if(n%8==6) printf("1 1 -1 1 1 -1 "),n-=6;
	else if(n%8==7) printf("-1 -1 1 -1 1 1 -1 "),n-=7;
	else if(n%8==0) printf("1 -1 -1 1 -1 1 1 -1 "),n-=8;
	else if(n%8==1) printf("1 1 -1 -1 1 -1 1 1 -1 "),n-=9;
	else if(n%8==2) printf("1 -1 -1 -1 1 1 1 -1 1 -1 "),n-=10;
	else if(n%8==3) printf("-1 1 -1 -1 -1 1 1 1 -1 1 -1 "),n-=11;
	else if(n%8==4) printf("-1 1 -1 -1 -1 1 -1 1 -1 1 1 -1 "),n-=12;
	else if(n%8==5) printf("-1 -1 1 -1 -1 1 -1 -1 -1 1 1 1 -1 "),n-=13;
	while(n)
	{
		printf("1 -1 -1 1 -1 1 1 -1 ");
		n-=8;
	}
	return 0;
}

本文地址:https://blog.csdn.net/qq_35786326/article/details/109244789

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网