当前位置:网站首页>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.
边栏推荐
- 敏捷开发项目管理的一些心得
- 防火墙基础之防火墙做出口设备安全防护
- EasyCVR calls the cloud recording API and returns an error and no recording file is generated. What is the reason?
- 智能视频监控平台EasyCVR如何使用接口批量导出iframe地址?
- 巴比特 | 元宇宙每日必读:微博动漫将招募全球各类虚拟偶像并为其提供扶持...
- Interval greedy (interval merge)
- EasyCVR调用云端录像API接口返回错误且无录像文件生成,是什么原因?
- darknet源码阅读笔记-02-list.h和lish.c
- Thrift installation configuration
- SQL优化最全总结 - MySQL(2022最新版)
猜你喜欢
2018年南海区小学生程序设计竞赛详细答案
Documentary on Security Reinforcement of Network Range Monitoring System (1)—SSL/TLS Encrypted Transmission of Log Data
buuctf(探险1)
嵌入式开发:使用堆栈保护提高代码完整性
SQL优化最全总结 - MySQL(2022最新版)
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
EasyCVR如何通过接口调用设备录像的倍速回放?
【web自动化测试】Playwright快速入门,5分钟上手
Flink / Scala - 使用 RedisSink 存储数据
【无标题】
随机推荐
数据集成:holo数据同步至redis。redis必须是集群模式?
margin 塌陷和重合的理解
树莓派安装samba用来共享文件
使用scikit-learn计算文本TF-IDF值
Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺一种修饰性PEG
路由懒加载
2022年7月31日 暑假第三周总结
Matlab drawing 1
【日记】mysql数据库连接池
leetcode/含有所有字符的最短字符串
DMPE-PEG-Mal,二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺简述
【技术笔记】树莓派4B开机流程整理(无显示器安装)
不论你是大众,科班和非科班,我这边整理很久,总结出的学习路线,还不快卷起来
网页端IM即时通讯开发:短轮询、长轮询、SSE、WebSocket
树莓派温度监视关机保护脚本
数仓建模面试
dotnet core 使用 CoreRT 将程序编译为 Native 程序
flink-cdc支持并行读取一张mysql表的binlog不?
shell函数内如何调用另一个函数
PT100铂热电阻三种测温方法介绍