欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

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

程序员文章站 2022-03-16 08:10:49
无了......


题意:

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


分析:

考场上用模拟退火拿了 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

相关标签: 暴力