Phoenix and Puzzletime(什么类型吗 不晓得嘛)

Phoenix and Puzzletime

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Phoenix is playing with a new puzzle, which consists of n identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.
在这里插入图片描述

A puzzle piece
The goal of the puzzle is to create a square using the n pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all n pieces must be used (of course, the square shouldn’t contain any holes as well). Can he do it?

Input
The input consists of multiple test cases. The first line contains an integer t (1≤t≤104) — the number of test cases.

The first line of each test case contains an integer n (1≤n≤109) — the number of puzzle pieces.

Output
For each test case, if Phoenix can create a square with the n puzzle pieces, print YES. Otherwise, print NO.

Example
inputCopy
3
2
4
6
outputCopy
YES
YES
NO
Note
For n=2, Phoenix can create a square like this:
在这里插入图片描述

For n=4, Phoenix can create a square like this:

在这里插入图片描述

For n=6, it is impossible for Phoenix to create a square.

题意:
一个正方形 能否由n个相同的等腰直角三角形构成

思路:
一个最基本的判别方式 如果n等于2的n次方 是ok的 因为总是切分
2大正方形由小正方形构成 我们需要知道能够组成几个小正方形
小正方形的个数是否为一个平方数
因为 如果小正方形的个数为平方数的话 那么正好可以 组成一个大的正方形
由于找小正方形不知道是哪一个 所以遍历一波即可

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<queue>
#define inf 1e9
using namespace std;
typedef long long ll;
ll n,m,k;
const int maxn=1e6+199;

int main(){
	
	int _;
	cin>>_;
	while(_--){
		
		cin>>n;
		if(n&1){
			cout<<"NO"<<endl;
			continue;
		} 
		int flag=0;
		m=n;
		while(n){
			if(n%2!=0&&n!=1){
				flag=1;
				break;
			}
			n/=2;
		}
		if(flag){
			int bj=0;
			double a[100];
			a[0]=1;
			
			for(int i=1;i<=10;i++){
				a[i]=a[i-1]*2;
			}
			for(int i=1;i<=10&&a[i]<m;i++)
			if(int(sqrt(m/a[i]))*int(sqrt(m/a[i]))==m/a[i]){
				bj=1;
				break;
			}
			if(bj){
				cout<<"YES"<<endl;
			}else{
				cout<<"NO"<<endl;
			}
			
		}else{
			cout<<"YES"<<endl;
		}
	}
	return 0;
}```

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牛郎恋刘娘,刘娘念牛郎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值