当前位置:网站首页>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;
}
边栏推荐
- Day 3. Suicidal ideation and behavior in institutions of higher learning: A latent class analysis
- 韦东山 数码相框 项目学习(二)在LCD上显示中文字符
- [first song] rebirth of me in py introductory training (3): if conditional sentence
- 古老的艺术-用好长尾关键词
- 韦东山 数码相框 项目学习(三)freetype的移植
- 个人开发者申请代码签名证书的签发流程
- 维度问题以及等高线
- A photo breaks through the face recognition system: you can nod your head and open your mouth, netizens
- 【第一篇博客-展望】
- 服务器相关的指标解释
猜你喜欢

Xmind 思维导图 2022 v12.0.3中文版更新了哪些内容?

STM32-红外遥控

Super remote connection management tool: Royal TSX

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

When multiple formulas in latex share a sequence number

C语言扫雷最新 递归展开 超详解(附源码)
![[high concurrency] interviewer](/img/50/baa662cb4ce30cf2ef4cb5952960dd.jpg)
[high concurrency] interviewer

STM32-FSMC外扩内存SRAM

Pix2Pix原理解析

安装windows下的redis
随机推荐
Day 2. Depressive symptoms, post-traumatic stress symptoms and suicide risk among graduate students
C language - linear sequence table
C语言-文件操作
C语言-动态内存管理
[first song] Introduction to data science of rebirth -- return to advanced level
Lightroom Classic 2022 v11.4中文版「最新资源」
编程学习记录——第4课【分支和循环语句】
C语言-自定义结构类型
谈谈为何需要将类的成员函数声明为private
C语言--字符串操作函数与内存操作函数
Dpdk network protocol stack VPP OVS DDoS Sdn nfv virtualization high performance expert Road
人月神话阅读笔记
STM32-FSMC外扩内存SRAM
子类调用父类构造函数的时机
2021-06-26
WebODM win10安装教程(亲测)
【头歌】重生之CNN图片分类基础
Weidongshan digital photo frame project learning (II) displaying Chinese characters on LCD
【头歌】重生之我在py入门实训中(7): 函数调用
AE 3D粒子系统插件:Trapcode Particular