当前位置:网站首页>Acwing the number of square arrays of one question per day
Acwing the number of square arrays of one question per day
2022-07-27 06:07:00 【The last tripod】
acwing The number of square arrays
Topic ideas
- After the direct arrangement, the inspection will TLE, Therefore, whether the two critical values meet the requirements is directly detected in the sorting process , If you are not satisfied with direct pruning , Greatly reduce the time complexity ( Because few meet the requirements )
- secondly , Double check the arrangement , The simple way is to store each number in the form of a hash table , Iterate every number with iterators , After use, reduce the number of times . It's used here Y The weight checking method taught by the general manager , It's a little difficult for me , From understanding to writing code independently 1 Hours ,hh
y Introduction to the total duplicate checking method , There is no guarantee that you can make it clear , As your own notes
When we sort the array , The repeated numbers come together , Treat the repeated number set as an interval . If you want to ensure that each arrangement is not repeated, as long as you can ensure that the number taken at this position is only taken once in this interval .
y The general method is to ensure that the number obtained each time is taken in this interval for the first time , Because the arrangement value of each number is checked from the front to the back of the array , For the following picture
Because it is checked from front to back , In the first arrangement, the first number must be red 2, The second one must be blue 2, The third time must be yellow 2, Trace back after this arrangement , the second 2 To the yellow 2 Location , At this time, I found the blue one in front 2 No place to use , It shows that this number is not the first time to use , End directly , Go back to the first 2, first ·2 To traverse to the blue .2, At this time, I found the front 2 There is no place to take , It's not the first time to take this number , End directly
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
int cnt = 0;
int n;
int w[15];
bool used[15];
bool check(int sum){
// Check whether the sum of the two numbers is square
int x = sqrt(sum);
return x*x == sum;
}
void permutation(int t,int last){
if(t == n){
cnt++;// It shows that it is a square array
return;
}
for(int i=0; i< n; i++){
if(used[i])continue;
if(i && !used[i-1] && w[i] == w[i-1])continue;// Check whether it is the first time to use the number of this interval
if(t && !check(w[i] + last))continue;// If you take the number of the first position , There is no need to check whether the sum of the previous number and this number is a square number
used[i] = true;
permutation(t+1, w[i]);
used[i] = false;
}
}
int main(){
cin>>n;
for(int i=0; i<n; i++)cin>>w[i];
sort(w,w+n);
permutation(0,0);
cout<<cnt<<endl;
}
边栏推荐
- C#线程锁(Lock)
- 百问网驱动大全学习(二)I2C驱动
- 编程学习记录——第7课【函数】
- Unity Shader 概述
- Gbase 8C - SQL reference 6 SQL syntax (12)
- WebODM win10安装教程(亲测)
- Dpdk network protocol stack VPP OVS DDoS Sdn nfv virtualization high performance expert Road
- 根据SQL必知必会学习SQL(MYSQL)
- Baiwen driving Daquan learning (II) I2C driving
- Can it replace PS's drawing software?
猜你喜欢

Unity Shader 概述

AE 3D particle system plug-in: Trapcode particle

Day 3. Suicidal ideation and behavior in institutions of higher learning: A latent class analysis

对于windows下的Redis,只能读不能写的问题
![[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog](/img/75/8f41db9f9c077b43751d63b7b5b57e.png)
[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog

发布 分辨率0.22m的建筑物分割数据库
![[first song] machine learning of rebirth - linear regression](/img/70/3efd9eacf88f55022eb52d096926f7.png)
[first song] machine learning of rebirth - linear regression

能替代ps的修图软件?

安装windows下的redis

Super remote connection management tool: Royal TSX
随机推荐
使用Markdowm
STM32-红外遥控
如何管理大量的定时任务
编程学习记录——递归解决汉诺塔问题
C language - linear sequence table
Day 3. Suicidal ideation and behavior in institutions of higher learning: A latent class analysis
编程学习记录——第8课【数组与设计五子棋,扫雷游戏】
【动态规划----钢条切割问题】
力扣题解 二叉树(8)
Weidongshan digital photo frame project learning (I) display ASCII characters on LCD
16. Over fitting and under fitting
pycharm安装及导入项目注意事项
QGIS系列(1)-QGIS(server-apache) win10安装
Weidongshan digital photo frame project learning (IV) simple TXT document display (e-paper book)
C语言-动态内存管理
Lightroom Classic 2022 v11.4中文版「最新资源」
【头歌】重生之我在py入门实训中(10): Numpy
这是我的博客
WebODM win10安装教程(亲测)
【头歌】重生之我在py入门实训中(8): 模块