当前位置:网站首页>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];
}
}
}
边栏推荐
- 杰理之AD 系列 MIDI 功能说明【篇】
- Enlightenment of maker thinking in Higher Education
- Difference between ApplicationContext and beanfactory (MS)
- 改善机器视觉系统的方法
- 超详细教程,一文入门Istio架构原理及实战应用
- Numpy vstack and column_ stack
- 杰理之AD 系列 MIDI 功能说明【篇】
- 解决异步接口慢导致的数据错乱问题
- 2021 CCPC Harbin B. magical subsequence (thinking question)
- Jerry's ad series MIDI function description [chapter]
猜你喜欢
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
Application practice | Shuhai supply chain construction of data center based on Apache Doris
【LeetCode】17、电话号码的字母组合
历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
杰理之增加进关机前把触摸模块关闭流程【篇】
IIC (STM32)
WGCNA analysis basic tutorial summary
Three or two things about the actual combat of OMS system
MP3是如何诞生的?
[C language] deep understanding of symbols
随机推荐
How much is the minimum stock account opening commission? Is it safe to open an account online
How to use concurrentlinkedqueue as a cache queue
Redis cache
redis03——Redis的网络配置与心跳机制
Enlightenment of maker thinking in Higher Education
每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation
奋斗正当时,城链科技战略峰会广州站圆满召开
Arcgis 10.2.2 | arcgis license server无法启动的解决办法
SolidWorks工程图添加材料明细表的操作
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
每日一题-LeetCode1200-最小绝对差-数组-排序
Master the use of auto analyze in data warehouse
Huawei ENSP simulator enables devices of multiple routers to access each other
为什么说不变模式可以提高性能
Jerry's ad series MIDI function description [chapter]
Flutter在 release版本,打开后随机白屏不显示内容
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
Go语言循环语句(第10课中3)
2021 CCPC Harbin B. magical subsequence (thinking question)
Interviewer: what is XSS attack?