A. On and Off
题目描述
二十四小时进制下,在SSS时000分开灯,在TTT时000分关灯,问XXX时303030分是否灯亮?
分析
两种情况
- S≤T:S\le T:S≤T: 那么XXX一定要在区间[S,T)[S,T)[S,T)中
- S>T:S>T:S>T:跨过了242424点,那么XXX要≥S\ge S≥S或者<T<T<T
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int S,T,X;
cin>>S>>T>>X;
bool f;
if (S<=T)f = (X>=S&&X<T);
else f = (X>=S||X<T);
cout<<(f?"Yes\n":"No\n");
}
B. Takahashi’s Secret
题目描述
高桥君有nnn个好朋友,高桥将秘密告诉好朋友XXX,然而,每个朋友iii如果知道这个秘密,将告诉朋友AiA_iAi请问最后一共有几个朋友知道这个秘密?
分析
我们只要模拟信息传递的过程就可以了,类似于dfsdfsdfs但是可以更为简单的实现
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
int a[maxn],b[maxn];
int n,x;
int main()
{
ios::sync_with_stdio(0);
cin>>n>>x;
for (int i=1;i<=n;++i)cin>>a[i];
int ans = 0;
while (!b[x])
{
b[x]=1;
x = a[x];
++ans;
}cout<<ans<<endl;
}
C.Final Day
题目描述
nnn名考生,已经进行了三门考试。第四门考试满分300300300,对每一名考生,询问他是否有可能总分在前kkk名内?
分析
很简单,判断第iii名考生时,我们认为他考了300300300分,其他人都考了零分,然后看他是否能进前kkk大
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
k -= 1;
vector<int> p(n);
for (int& x : p) {
int a, b, c;
cin >> a >> b >> c;
x = a + b + c;
}
vector<int> q = p;
sort(begin(q), end(q), greater<>());
for (int x : p) {
cout << (x + 300 >= q[k] ? "Yes" : "No") << '\n';
}
}
D.Linear Probing
题目描述
长度为nnn的数组aaa,初始元素都为−1-1−1
现在要求执行qqq次操作,操作有两种
- 给出数字xxx,令h=x%nh=x\%nh=x%n,只要a[h]≠−1,h=(h+1)%na[h]\not=-1,h=(h+1)\%na[h]

这篇博客详细解析了AtCoder Beginner Contest 228中的六道编程题目,包括A. On and Off、B. Takahashi’s Secret、C. Final Day、D. Linear Probing、E. Integer Sequence Fair和F. Stamp Game。针对每一道题目,博主给出了题目描述、解题思路和代码实现,涉及C++编程、算法设计以及ACM竞赛策略。
最低0.47元/天 解锁文章
1523

被折叠的 条评论
为什么被折叠?



