当前位置:网站首页>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.
边栏推荐
- CAS:474922-26-4,DSPE-PEG-NH2,DSPE-PEG-amine,磷脂-聚乙二醇-氨基供应
- mysql cdc 为什么需要RELOAD 这个权限?这个权限在采集数据的过程中的作用是什么?有哪
- 谷歌开源芯片 180 纳米制造工艺
- LVS+Keepalived群集
- 2022年7月31日 暑假第三周总结
- 语音识别学习资源
- Flask框架实现注册加密功能详解【Flask企业课学习】
- 合宙Cat1 4G模块Air724UG配置RNDIS网卡或PPP拨号,通过RNDIS网卡使开发板上网(以RV1126/1109开发板为例)
- 【web自动化测试】Playwright快速入门,5分钟上手
- DHCP&OSPF组合实验演示(Huawei路由交换设备配置)
猜你喜欢
随机推荐
树莓派利用autofs自动挂载/卸载外部硬盘
2022年7月31日 暑假第三周总结
数仓相关,总结
Documentary on Security Reinforcement of Network Range Monitoring System (1)—SSL/TLS Encrypted Transmission of Log Data
树莓派通过API向企业微信推送图文
华为云计算HCIE之oceanstor仿真器的使用操作
22/8/4 记忆化搜索+博弈论
July 31, 2022 Summary of the third week of summer vacation
解决错误:The package-lock.json file was created with an old version of npm
How to make JS code unbreakable
数据库SqlServer迁移PostgreSql实践
Hezhou Cat1 4G module Air724UG is configured with RNDIS network card or PPP dial-up, and the development board is connected to the Internet through the RNDIS network card (taking the RV1126/1109 devel
企业调查相关性分析案例
巴比特 | 元宇宙每日必读:微博动漫将招募全球各类虚拟偶像并为其提供扶持...
clickhouse online and offline table
Error when using sourcemap for reporting an error: Can‘t resolve original location of error.
Interval greedy (interval merge)
【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?
基于大学生内卷行为的调查研究
【日记】高并发下的DB分库分表分区策略










