当前位置:网站首页>2019 Haidian District Youth Programming Challenge Activity Elementary Group Rematch Test Questions Detailed Answers
2019 Haidian District Youth Programming Challenge Activity Elementary Group Rematch Test Questions Detailed Answers
2022-08-04 18:01:00 【51CTO】
Evaluation results of six programs:
1 约数
2 阶乘
#include<iostream>
using namespace std;
// zero count from tail of n!
int zeroCnt1(int n)
{
int cnt = 0;
while(n)
{
n /= 5;
cnt += n;
}
return cnt;
}
// zero count from tail of n!! when n is even
int zeroCnt2(int n)
{
n /= 10;
int cnt = n;
while(n)
{
n /= 5;
cnt += n;
}
return cnt;
}
int main()
{
int n;
cin >> n;
cout << zeroCnt1(n) << ' ';
if(n % 2)
{
cout << 0;
}
else
{
cout << zeroCnt2(n) << endl;
}
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
3 序列
#include <iostream>
using namespace std;
int a[200005];
int main()
{
int n, i;
cin >> n;
for(i = 0; i < n; i++)
{
cin >> a[i];
}
for(i = n - 1; i >= 0; i -= 2)
{
cout << a[i] << " ";
}
if(n % 2)
{
i = 1;
}
else
{
i = 0;
}
for(; i < n; i += 2)
{
cout << a[i] << " ";
}
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
4 糖果
#include <iostream>
#include <memory.h>
#include <cstring>
using namespace std;
char a[10000000 + 5];
inline string read()//inlineKeep going faster
{
// getchar()Compare when the amount of data is largescanf和cin快
char ch = getchar();
string res = "";
while(ch>='A' && ch<='Z')
{
res += ch;
ch = getchar();
}
return res;
}
int main()
{
freopen("candy.in", "r", stdin);
freopen("candy.out", "w", stdout);
int cnt[128];
memset(cnt, 0, sizeof(cnt));
int start = 0;
int maxLen = 26;
int len;
bool same = false;
//string a = read();
scanf("%s", a);
int Size = strlen(a);
for(int i = 0; i < Size; i++)
{
cnt[a[i] - 65]++;
if(2 == cnt[a[i] - 65])
{
same = true;
for(int j = start; j < i; j++)
{
if(a[j] == a[i])
{
len = i - j;
if(len < maxLen)
{
maxLen = len;
}
start = j + 1;
break;
}
}
cnt[a[i] - 65] = 1;
}
}
if(!same)
{
cout << "-1" << endl;
return 0;
}
cout << maxLen << endl;
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
5 迷宫
#include <iostream>
using namespace std;
const int N = 205;
// 4 directions: right, left, down, up
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int n, m, ans;
char a[N][N];
bool vis[N][N];
void dfs(int x, int y)
{
for(int dir = 0; dir < 4; dir++)
{
int nextX = x + dx[dir];
int nextY = y + dy[dir];
if(!vis[nextX][nextY] && nextX >= 1 && nextX <= n && nextY >= 1 && nextY <= m && (a[nextX][nextY] == '.' || a[nextX][nextY] == '*'))
{
vis[nextX][nextY] = true;
if(a[nextX][nextY] == '*')
{
ans++;
}
dfs(nextX, nextY);
}
}
}
int main()
{
freopen("maze.in", "r", stdin);
freopen(“maze.out”, “w”, stdout);
int startX, startY;
cin >> n >> m; // n rows m columns
int row, col;
for(row = 1; row <= n; row++)
{
for(col = 1; col <= m; col++)
{
cin >> a[row][col];
if('S' == a[row][col])
{
startX = row;
startY = col;
}
}
}
vis[startX][startY] = true;
dfs(startX, startY);
cout << ans << endl;
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
6 盒子
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
const int N = 500000 + 5;
int n, a[N];
int main()
{
freopen("box.in", "r", stdin);
freopen("box.out", "w", stdout);
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
multiset<int, greater<int> > s; // Each element represents how many elements each heap has
for(int i = 1; i <= n; i++)
{
// For descending collections,lower_boundWhat you get is the first less thana[i]的元素的位置
// Only the number of heaps is less than or equal toa[i],a[i]to be added to the bottom of the heap
// If the number of min heap is greater than a[i],Description to bea[i]新建一堆
multiset<int>::iterator it = s.lower_bound(a[i]);
if(it == s.end()) // sThere is no such element in it
{
// Add a new heap,堆的大小为1(contains this element)
s.insert(1);
}
else
{
// Put elements into this heap,The number of elements in the heap is added1
int cnt = *it + 1;
s.erase(it);
s.insert(cnt);
}
}
printf("%d", s.size());
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
边栏推荐
猜你喜欢
leetcode 14. 最长公共前缀
力扣学习---0804
公司自用的国产API管理神器
解决错误:The package-lock.json file was created with an old version of npm
Kotlin挂起函数原理是什么
OpenInfra Days China 2022|SelectDB与你共享 Apache Doris 在互联网广告业务中的实践
图解LeetCode——899. 有序队列(难度:困难)
信息系统项目管理师必背核心考点(六十)项目集管理
EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法
DMPE-PEG-Mal,二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺简述
随机推荐
JS中null与undefined的异同点
Route lazy loading
EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法
Speech Recognition Learning Resources
基于层次分析法的“内卷”指数分析
基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
网络靶场监控系统的安全加固纪实(1)—SSL/TLS对日志数据加密传输
leetcode/含有所有字符的最短字符串
Codeforces积分系统介绍
解决错误:The package-lock.json file was created with an old version of npm
Matlab drawing 1
八猴渲染器是什么?它能干什么?八猴软件的界面讲解
flink-cdc支持并行读取一张mysql表的binlog不?
Go 言 Go 语,一文看懂 Go 语言文件操作
谷歌开源芯片 180 纳米制造工艺
[Web Automation Test] Quick Start with Playwright, 5 minutes to get started
Thrift installation configuration
mmdetection/mmdetection3d多机多卡训练
容器化 | 在 NFS 备份恢复 RadonDB MySQL 集群数据
leetcode 14. 最长公共前缀