当前位置:网站首页>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];
}
}
}
边栏推荐
- MP3是如何诞生的?
- Three or two things about the actual combat of OMS system
- [public class preview]: basis and practice of video quality evaluation
- Huawei ENSP simulator configures DHCP for router
- How much is the minimum stock account opening commission? Is it safe to open an account online
- [weekly translation go] how to code in go series articles are online!!
- Jerry's ad series MIDI function description [chapter]
- Shutter WebView example
- [buuctf.reverse] 151_ [FlareOn6]DnsChess
- 类方法和类变量的使用
猜你喜欢

A quick start to fastdfs takes you three minutes to upload and download files to the ECS

Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"

SolidWorks工程图添加材料明细表的操作

奋斗正当时,城链科技战略峰会广州站圆满召开

Huawei ENSP simulator layer 3 switch

Redis03 - network configuration and heartbeat mechanism of redis

Can be displayed in CAD but not displayed in print

输入的查询SQL语句,是如何执行的?
![[early knowledge of activities] list of recent activities of livevideostack](/img/14/d2cdae45a18a5bba7ee1ffab903af2.jpg)
[early knowledge of activities] list of recent activities of livevideostack

How was MP3 born?
随机推荐
一文掌握数仓中auto analyze的使用
minidom 模块写入和解析 XML
Caduceus从未停止创新,去中心化边缘渲染技术让元宇宙不再遥远
Daily question -leetcode1200- minimum absolute difference - array - sort
redis发布订阅的使用
MYSQL 用!=查询不出等于null的数据,解决办法
历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
How was MP3 born?
应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
如何使用ConcurrentLinkedQueue做一个缓存队列
Flutter WebView示例
Huawei ENSP simulator configures DHCP for router
Huawei ENSP simulator enables devices of multiple routers to access each other
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
Jerry added the process of turning off the touch module before turning it off [chapter]
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
How to remove the black dot in front of the title in word document
Case sharing | integrated construction of data operation and maintenance in the financial industry