生活随笔
收集整理的這篇文章主要介紹了
Acwing第 38 场周赛【完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 4299. 刪點【簽到】
- 4300. 兩種操作【BFS】
- 4301. 截斷數列【枚舉】
4299. 刪點【簽到】
https://www.acwing.com/problem/content/4302/
#include<bits/stdc++.h>
using namespace std
;
int n
;
int main(void)
{cin
>>n
;int cnt1
=0,cnt2
=0;while(n
--){int x
,y
; cin
>>x
>>y
;if(x
<0) cnt1
++;else cnt2
++;}if(cnt1
<=1||cnt2
<=1) puts("Yes");else puts("No");return 0;
}
4300. 兩種操作【BFS】
https://www.acwing.com/problem/content/4303/
#include<bits/stdc++.h>
using namespace std
;
typedef long long int LL
;
const int N
=1e5*2+10;
int n
,m
;
int bfs()
{int st
[N
];memset(st
,-1,sizeof st
);queue
<int>q
; q
.push(n
); st
[n
]=0;while(q
.size()){int temp
=q
.front(); q
.pop();if(temp
==m
) {return st
[temp
];}if(st
[temp
*2]==-1&&temp
*2<=1e5){st
[temp
*2]=st
[temp
]+1;q
.push(temp
*2);}if(st
[temp
-1]==-1&&temp
>=0){st
[temp
-1]=st
[temp
]+1;q
.push(temp
-1);}}return -1;
}
int main(void)
{cin
>>n
>>m
;cout
<<bfs();return 0;
}
4301. 截斷數列【枚舉】
https://www.acwing.com/problem/content/4304/
數據范圍很弱直接枚舉即可。
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5*2+10;
int n
,a
[N
];
string s
;
bool check(int x
)
{int cnt
=0,flag
=0;for(int i
=0;i
<s
.size();i
++){cnt
+=s
[i
]-'0';if(cnt
==x
) cnt
=0,flag
++;if(cnt
>x
){return false;}}if(flag
>=2&&cnt
==0)return true;else return false;
}
int main(void)
{cin
>>n
>>s
;for(int i
=0;i
<=900;i
++){if(check(i
)){puts("YES");return 0;}}puts("NO");return 0;
}
總結
以上是生活随笔為你收集整理的Acwing第 38 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。