当前位置:网站首页>【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)
【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)
2022-07-27 17:57:00 【tsunaa】
【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)
A. Kids Seating
- Yes 1 To 4n Number , Ask to find out n Number , Make any two numbers not coprime and not divisible .
Their thinking
- A construction problem .
- n The scale is 100, Just do it violently .
- It can be found that the first number must be at least from 4 Start . Then traverse 4*n Number , For each number , Find out whether he is coprime with the previous number , And whether there is an integer division relationship with the previous number . For divisible Relations , You can sift every time you find an integer division relationship , This can improve efficiency .
- Traverse 4*n After the count , Judge whether the number found meets n Number , If not enough n, So from 5 Start as the first number …… And so on .
- keyword : Violent structure
Here are some definitions : * pos[]: Initialize to 1,0 It means that it does not meet the requirements * ans[]: Record the numbers that meet the requirements * cnt: Indicates how many numbers currently meet the requirements * j: The first number * check(a): take a Multiple of pos[] They are all marked with 0, Because there is an integer division relationship , So it doesn't meet the requirements , Marked as 0. * check2(a, cnt): Judge a Whether it meets the requirements of the previous cnt There is a reciprocal relationship between numbers , If coprime , return 1, Otherwise return to 0.
Be careful
- If you find that you cannot find n A digital , want j++ When looking for it from the beginning , Remember to reinitialize pos[] and ans[].
skill
- __gcd(a,b): return a,b Maximum common divisor of .
Judge a,b Whether two numbers are mutually prime : Judgment __gcd(a,b) == 1
My code
#include<bits/stdc++.h>
using namespace std;
int n, cnt;
int a[4005], pos[4005], ans[1005];
void check(int a){
for(int i = a; i <= 4*n; i+=a){
pos[i] = 0;
}
}
int check2(int a, int cnt){
for(int i = 0; i <= cnt; i++)
if(__gcd(a, ans[i]) == 1)
return 1;
return 0;
}
int main(){
int t;
cin >> t;
while(t--){
cin >> n;
cnt = 0;
int j = 4;
while(j < 4*n){
memset(ans, 0, sizeof(ans));
memset(pos, 1, sizeof(pos));
ans[cnt] = j;
check(j);
for(int i = j+1; i <= 4*n; i++){
if(check2(i, cnt)){
continue;
}
if(i % ans[cnt] == 0){
check(i); continue;
}
if(pos[i] == 0) continue;
ans[++cnt] = i;
check(i);
if(cnt == n-1) break;
}
if(cnt < n-1){
j++;
memset(ans, 0, sizeof(ans));
cnt = 0;
continue;
}
else break;
}
if(n == 1){
cout << 1 << endl;
}
else{
for(int i = 0; i <= cnt; i++)
cout << ans[i] << " ";
cout << endl;
}
}
}
Optimize
- keyword : thinking 、 structure

边栏推荐
- Help, boost and take responsibility, the new value and significance of the 6th Tuba rabbit 718 national home decoration Festival
- Can oracle-linux-7.9 support oracle-19c ACFs file system?
- 【Codeforces】 B. Make it Divisible by 25
- Compilation and testing of raspberry pie driver code
- 数据库超话(四)
- Zhengzhou University database course resource description
- Windows与网络基础-15-本地安全策略
- Explain the pile of binary trees in detail
- 【Codeforces】 A. Computer Game
- Database hyperphone (II)
猜你喜欢

面试官:什么是脚手架?为什么需要脚手架?常用的脚手架有哪些?

TCP的连接状态标识 (SYN, FIN, ACK, PSH, RST, URG)

Gods at dusk, "cat trembles" bid farewell to the big V Era

Count the six weapons of the domestic interface cooperation platform!

知物由学 | 易盾自研文本实时聚类技术,一网打尽社交网络中的同类有害内容

【单片机】2.1 AT89S52单片机的硬件组成

How to restrict root remote login so that ordinary users have root privileges

Oracle 11g数据库安装教程

选择体育场馆的LED显示屏时应该注重哪些方面

阿里巴巴鹰眼系统简介
随机推荐
#yyds干货盘点# 面试必刷TOP101:链表内指定区间反转
数据库超话(一)
泰山OFFICE技术讲座:WORD奇怪的段落边框
KMP template - string matching
How to learn C language? This article gives you the complete answer
X-sheet development tutorial: initialization configuration custom layout
Fast parsing combined with Huatu document encryption software
Common shell commands (1) -- variable case conversion
Cow! His secret is to reproduce the paper in 2 hours——
交换机和路由器技术-03-交换机基本配置
面试好难啊!蚂蚁金服的六轮面试我是强撑过来!差点OUT(面试复盘)
卷积神经网络——YOLOV2(YOLO9000)论文翻译
工信部再治数据安全,网易易盾“隐私合规”守住企业经营底线
Interviewer: what is scaffolding? Why do you need scaffolding? What are the commonly used scaffolds?
卷积神经网络——SSD论文翻译
如何开发一款在线Excel表格系统(上)
Mlx90640 infrared thermal imager temperature sensor module development notes (VII)
How to restrict root remote login so that ordinary users have root privileges
Chen Yili of ICT Institute: reducing cost and increasing efficiency is the greatest value of cloud native applications
Chery omenda is also too similar to Chang'an uni-t, but does it look like it? Is the product power like it?