当前位置:网站首页>AcWing 2022 每日一题
AcWing 2022 每日一题
2022-07-04 20:47:00 【.Ashy.】
Week 1 星期五 性感素数(选择结构+素数判断)
#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;
}//素数判断
int main()
{
cin>>n;
if(judge(n)&&judge(n-6))
{
puts("Yes");
cout<<n-6;
return 0;
}//先找小的匹配性感素数
if(judge(n)&&judge(n+6))
{
puts("Yes");
cout<<n+6;
return 0;
}//找不到小的找大的匹配性感素数
for(int i=n+1;;i++)
{
if(judge(i)&&judge(i+6)||judge(i)&&judge(i-6))
{
cout<<"No"<<endl<<i;
break;
}
}//都找不到往后搜索找一个性感素数
}
Week 4 星期日 倒水问题(暴力搜索)
原题链接:
倒水问题
思路:
一开始读理所当然的想到了贝祖定理和扩展欧几里得,但是仔细读题后发现并不是那回事,仔细看了题解后回来补题。
是一个搜索题,暴力搜索所有的状态即可;
A,B,C 的范围都是 0 ~ 4000 看起来状态数好像有 40013 那么多(必爆),但其实不然,因为每次转移必须保证 一个杯子是空的或者一个杯子是满的,这样最坏复杂度就降低到 3 ∗ 2 ∗ 4000 ∗ 4000 3*2*4000*4000 3∗2∗4000∗4000 大约是 9.6*107 也就是 1e8
一开始三杯水的状态为 (0,0,C)
开始倒水即状态开始转移后,转移方向是
a - b
a - c
b - a
b - c
c - a
c - b
这六个方向,我们根据题意进行转移即可
注意不计算重复的状态,每次的状态为(a,b,c),a,b,c 满足 a+b==c 因此我们只要记下其中两个数的状态就相当于表示出了这三个数的状态,我们用 set 来存状态,状态不同的时候 C 有可能相同, 我们用另一个 set 来存 所有不同的的C,统计C的答案。
#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});//记录状态
ans.insert(c);//记录当前状态下的答案
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;
}
}
总结
以后看题要好好读题,不能看着像就用某种思路,这题的各种小细节都特别巧妙,包括它搜索的方法(状态的转移),记录的方法,应当好好学习这个题。
Week 5 星期一 树查找(选择结构)
思路:
第k层的左侧序号 l 是 2k-1 右侧序号 r 是 2k-1
判断是否为空 即判断 n 与 l 的 大小关系
而当不为空的时候,也要注意这一层是否完全
注意格式
左移 k 即为 × 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];
}
}
}
边栏推荐
- Arcgis 10.2.2 | arcgis license server无法启动的解决办法
- 吐槽 B 站收费,是怪它没钱么?
- 迈动互联中标北京人寿保险
- In the release version, the random white screen does not display the content after opening the shutter
- y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
- How to use concurrentlinkedqueue as a cache queue
- Delphi SOAP WebService 服务器端多个 SoapDataModule 实现相同的接口方法,接口继承
- 华为ensp模拟器 给路由器配置DHCP
- Use of class methods and class variables
- ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
猜你喜欢
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
[wechat applet] collaborative work and release
Huawei ENSP simulator configures ACL access control list
杰理之AD 系列 MIDI 功能说明【篇】
TCP三次握手,四次挥手,你真的了解吗?
How was MP3 born?
[leetcode] 17. Letter combination of telephone number
How to remove the black dot in front of the title in word document
Jerry added the process of turning off the touch module before turning it off [chapter]
随机推荐
Monitor the shuttle return button
华为模拟器ensp常用命令
Jerry's ad series MIDI function description [chapter]
Daily question-leetcode556-next larger element iii-string-double pointer-next_ permutation
Roast B station charges, is it because it has no money?
杰理之AD 系列 MIDI 功能说明【篇】
Jerry's ad series MIDI function description [chapter]
[wechat applet] collaborative work and release
哈希表(Hash Tabel)
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
__init__() missing 2 required positional arguments 不易查明的继承错误
【公开课预告】:视频质量评价基础与实践
华为ensp模拟器实现通信安全(交换机)
Routing configuration and connectivity test of Huawei simulator ENSP
每日一题-LeetCode1200-最小绝对差-数组-排序
ArcGIS 10.2.2 | solution to the failure of ArcGIS license server to start
[ 每周译Go ] 《How to Code in Go》系列文章上线了!!
How was MP3 born?
Flutter TextField示例