当前位置:网站首页>Acwing 2022 daily question
Acwing 2022 daily question
2022-07-04 21:43:00 【. Ashy.】
List of articles
Week 1 Friday Sexy prime ( Selection structure + Prime judgment )
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
bool judge(int n)
{
if(n<2) return 0;
for(int i=2;i*i<=n;i++)
if(n%i==0)
return 0;
return 1;
}// Prime judgment
int main()
{
cin>>n;
if(judge(n)&&judge(n-6))
{
puts("Yes");
cout<<n-6;
return 0;
}// Find the small matching sexy prime first
if(judge(n)&&judge(n+6))
{
puts("Yes");
cout<<n+6;
return 0;
}// Can't find a small matching sexy prime number
for(int i=n+1;;i++)
{
if(judge(i)&&judge(i+6)||judge(i)&&judge(i-6))
{
cout<<"No"<<endl<<i;
break;
}
}// Can't find it. Search later to find a sexy prime
}
Week 4 Sunday The problem of pouring water ( Violent search )
Original link :
The problem of pouring water
Ideas :
At the beginning of reading, I naturally thought of bezu theorem and extended Euclid , But after reading the question carefully, I found that it was not the case , After reading the solution carefully, I'll come back to make up the problem .
It's a search question , Violent search All States are ok ;
A,B,C It's all about 0 ~ 4000 It seems that the number of States has 40013 There are so many ( It's going to explode ), But it's not , Because every transfer must guarantee A cup is empty or a cup is full , In this way, the worst complexity is reduced to 3 ∗ 2 ∗ 4000 ∗ 4000 3*2*4000*4000 3∗2∗4000∗4000 It's about 9.6*107 That is to say 1e8
At first, the state of three glasses of water is (0,0,C)
Start pouring water, that is, after the state begins to shift , The transfer direction is
a - b
a - c
b - a
b - c
c - a
c - b
These six directions , We can transfer according to the meaning of the topic
Note that duplicate states are not counted , The status of each time is (a,b,c),a,b,c Satisfy a+b==c Therefore, as long as we write down the state of two numbers, it is equivalent to indicating the state of these three numbers , We use it set To save the status , When the state is different C It could be the same , Let's use another set Come and save All different C, Statistics C The answer .
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
int A,B,C;
typedef pair<int,int> PII;
set<PII>st;
set<int>ans;
/* a - b a - c b - a b - c c - a c - b */
void dfs(int a,int b,int c)
{
if(st.count({
a,b})) return ;
st.insert({
a,b});// Record status
ans.insert(c);// Record the answers in the current state
int x;
x=min(a,B-b);
dfs(a-x,b+x,c);//a - b
x=min(a,C-c);
dfs(a-x,b,c+x);//a - c
x=min(b,A-a);
dfs(a+x,b-x,c);//b - a
x=min(b,C-c);
dfs(a,b-x,c+x);//b - c
x=min(c,A-a);
dfs(a+x,b,c-x);//c - a
x=min(c,B-b);
dfs(a,b+x,c-x);//c - b
}
int main()
{
while(cin>>A>>B>>C)
{
ans.clear();
st.clear();
dfs(0,0,C);
cout<<ans.size()<<endl;
}
}
summary
Read the questions carefully in the future , You can't look like using a certain idea , The small details of this question are particularly clever , Including its search method ( The transfer of state ), Method of recording , We should study this problem well .
Week 5 Monday Tree search ( Selection structure )
Ideas :
The first k The left serial number of the layer l yes 2k-1 Right serial number r yes 2k-1
Determine whether it is null Judgment n And l Of Size relationship
And when it is not empty , Also pay attention to whether this layer is complete
Attention format
Move left k That is to say × 2k
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4+10;
int n,k;
int a[N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
cin>>k;
int r=(1<<k)-1;
int l=1<<(k-1);
if(n<l)
{
cout<<"EMPTY";
}
else
{
r=min(r,n);
for(int i=l;i<=r;i++)
{
if(i!=r) cout<<a[i]<<" ";
else cout<<a[i];
}
}
}
边栏推荐
- 超详细教程,一文入门Istio架构原理及实战应用
- 刘锦程荣获2022年度中国电商行业创新人物奖
- Enlightenment of maker thinking in Higher Education
- ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
- IIC (STM32)
- 巅峰不止,继续奋斗!城链科技数字峰会于重庆隆重举行
- 每日一题-LeetCode1200-最小绝对差-数组-排序
- How much is the minimum stock account opening commission? Is it safe to open an account online
- Daily question-leetcode556-next larger element iii-string-double pointer-next_ permutation
- Case sharing | integrated construction of data operation and maintenance in the financial industry
猜你喜欢
![[early knowledge of activities] list of recent activities of livevideostack](/img/14/d2cdae45a18a5bba7ee1ffab903af2.jpg)
[early knowledge of activities] list of recent activities of livevideostack

Methods of improving machine vision system

OMS系统实战的三两事

At the right time, the Guangzhou station of the city chain science and Technology Strategy Summit was successfully held

Analysis of maker education technology in the Internet Era

How to remove the black dot in front of the title in word document

Huawei ENSP simulator realizes communication security (switch)

The video sound of station B is very low - solution

Three or two things about the actual combat of OMS system

迈动互联中标北京人寿保险
随机推荐
Le module minidom écrit et analyse XML
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
2021 CCPC Harbin I. power and zero (binary + thinking)
Roast B station charges, is it because it has no money?
redis管道
奋斗正当时,城链科技战略峰会广州站圆满召开
Cadeus has never stopped innovating. Decentralized edge rendering technology makes the metauniverse no longer far away
Analyzing the maker space contained in steam Education
Compréhension approfondie du symbole [langue C]
redis RDB AOF
Jerry's ad series MIDI function description [chapter]
redis布隆过滤器
Huawei ENSP simulator realizes communication security (switch)
改善机器视觉系统的方法
minidom 模塊寫入和解析 XML
Case sharing | integrated construction of data operation and maintenance in the financial industry
In the release version, the random white screen does not display the content after opening the shutter
为什么说不变模式可以提高性能
刘锦程荣获2022年度中国电商行业创新人物奖
Difference between ApplicationContext and beanfactory (MS)