河工院首届工业设计大赛程序组(选拔赛)题解

news/2024/10/18 20:44:52/

更好的阅读体验 \huge{\color{red}{更好的阅读体验}} 更好的阅读体验

不存在的数

  • 签到题,模拟
  • 对输入的数进行标记,从 1 遍历到 N,输出没有被标记的数字即可

std标程:

cpp">#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>using namespace std;#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);int a[N];void solve(){int n, m; cin >> n >> m;for (int i = 0; i < m; i ++) {int x; cin >> x; a[x] = 1;}for (int i = 1; i <= n; i ++) {if (a[i] == 0) cout << i << ' ';}
}int main(){IOS;int _ = 1;// cin >> _;while(_ --){solve();}return 0;}

一血代码:

cpp">#include<bits/stdc++.h>
using namespace std;int main()
{int n, m;cin >> n >> m;map<int, int>mp;for( int i = 1 ; i <= m ; i++ ) {int x;cin >> x;mp[x]++;}for( int i = 1 ; i <= n ; i++ ) {if( mp[i] ) continue;else cout << i << ' ';}
} 

疯狂校园跑

配速为1km所用时间,所以配速为时间除以路程;

知道这一点之后就可以写代码了。

std标程:

#include <stdio.h>int main()
{int t; scanf("%d", &t);while (t --){int s, t; scanf("%d %d", &s, &t);double sps = t * 1.0 / s; //多少秒每米double spm = sps * 1000; //多少秒每公里 printf("%d:%02d:%03d\n", (int)(spm / 60), (int)(spm - (int)(spm / 60) * 60), ((int)(spm * 1000) % 1000));}return 0;
}

一血代码:

#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'using namespace std;void solve(){int n, s;cin >> n >> s;double res = 1.0 * 1000 * s / n;int h = res / 60;int m = res - h * 60;int ms = 1.0 * (res - h * 60 - m) * 1000;printf("%d:%02d:%03d\n", h, m, ms); 
}signed main(){IOS;int t = 1;cin >> t;while(t --) solve();return 0;
}

输出语句

  • 模拟

  • 考察转义字符,这里只考察了大家单引号 \',双引号 \",回车符 \n以及反斜杠 \\,对输出加以判定即可

std标程:

cpp">#include <bits/stdc++.h>using namespace std;void solve()
{string s;getline(cin, s);int l = 8, r = s.size() - 4;for (int i = l; i <= r; i ++){if (i != r && s[i] == '\\'){if (s[i + 1] == '\''){cout << '\'';i ++;}else if (s[i + 1] == '\"'){cout << '\"';i ++;}else if (s[i + 1] == '\\'){cout << '\\';i ++;}else if (s[i + 1] == 'n'){cout << '\n';i ++;}}else{cout << s[i];}}
}int main()
{solve();return 0;
}

一血代码:

#include<iostream>
#include<string>
using namespace std;
int main(void)
{string a;getline(cin,a);int flag=0;for(int i=0;i<a.size();i++){if(a[i-1]=='f'&&a[i]=='('&&a[i+1]=='"'){for(int j=i+2;j<a.size();j++){if(a[j]=='"'&&a[j+1]==')'&&a[j+2]==';'){break;}if(a[j]=='\\'){j++;if(a[j]=='0'){cout<<" ";}else if(a[j]=='n'){cout<<endl;}else{cout<<a[j];}}else cout<<a[j];}}}return 0;
}

疯狂汽车运输队

本题为简单的01背包,不过是需要算一下超重多少,但是最多超重100%,那么代码就如下。

std标程:

#include<bits/stdc++.h>using namespace std;
int f[10000];
int main()
{  int T;cin>>T;while(T--){int n,m;cin>>n>>m;for(int i=1;i<=m*2;i++) f[i]=0;for(int i=1;i<=n;i++){int x,y;cin>>x>>y;for(int j=m*2;j>=x;j--) f[j]=max(f[j],f[j-x]+y);}int ans=0;for(int i=m;i<=2*m;i++){int x=(i-m)*1.0/(m*1.0)*10;// cout<<x<<" "<<f[i]<<" ";x=f[i]-(int)(f[i]*x*0.1);ans=max(x,ans);// cout<<x<<"\n";}cout<<ans<<"\n";} return 0;
} 

为什么演奏春日影

  • 签到题,trick
  • 选择 k = 1,则后面每次都开摆,任何正整数取模结果都是 0,因此结果全为 Yes

std标程:

cpp">#include <bits/stdc++.h>using namespace std;int main()
{int n, m; cin >> n >> m;for (int i = 0; i < n; i ++) {int x; cin >> x;}cout << "Yes";return 0;
} 

一血代码:

cpp">#include<bits/stdc++.h>
using namespace std;map<int, int>mp;void calc( int x ) 
{for( int i = 2 ; i <= sqrt(x) ; i++ ) {if( x % i == 0 ) {mp[i]++;mp[x % i]++;}}
}
int main()
{int n, m;cin >> n >> m;vector<int> a(n);for( int i = 0 ; i < n ; i++ ) {cin >> a[i];}for( int i = 0 ; i < n ; i++ ) {calc(a[i]);}int mx = 0;for( auto i : mp ) {mx = max(mx, i.second);}if( mx + m < n ) cout << "No";else cout << "Yes";
} 

BinGo游戏

  • 签到题,模拟
  • 根据题意模拟循环判断即可

std标程:

cpp">#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>using namespace std;#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);int a[10][10];bool check1() {for (int i = 0; i < 5; i ++) {bool flag = 1;for (int j = 0; j < 5; j ++) {if (a[i][j] % 2 != 0) {flag = 0; break;}}if (flag) return 1;}return 0;
}bool check2() {for (int i = 0; i < 5; i ++) {bool flag = 1;for (int j = 0; j < 5; j ++) {if (a[j][i] % 2 == 0) {flag = 0; break;}}if (flag) return 1;}return 0;
}bool check3() {bool mainDiag = a[0][0] % 2 == 0;bool offDiag = a[0][4] % 2 == 0;for (int i = 1; i < 5; i++) {if ((a[i][i] % 2 == 0) == mainDiag || (a[i][4-i] % 2 == 0) == offDiag) return false;mainDiag = !mainDiag;offDiag = !offDiag;}return true;
}void solve(){for (int i = 0; i < 5; i++) {for (int j = 0; j < 5; j++) cin >> a[i][j];}if (check1() || check2() || check3()) {cout << "BINGO" << endl;} else {cout << "OHNO" << endl;}
}int main(){IOS;int _ = 1;// cin >> _;while(_ --){solve();}return 0;}

一血代码:

#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'using namespace std;int a[10][10];
bool ok;bool check(int x){int f = 0;for(int i = 0; i < 5; i ++){if(a[i][x] % 2 != 1) break;if(i == 4) f = 1;}for(int i = 0; i < 5; i ++){if(a[x][i] % 2 != 0) break;if(i == 4) f = 1;}if(f) return true;return false;
}void solve(){for(int i = 0; i < 5; i ++)for(int j = 0; j < 5; j ++)cin >> a[i][j];for(int i = 0; i < 5; i ++){if(check(i)){ok = true;
//			cout << i << endl;}}
//	if(ok) cout << 1 << endl;bool ok1 = false, ok2 = false;for(int i = 1; i < 5; i ++){if(a[i][i] % 2 == a[i - 1][i - 1] % 2){break;}if(i == 4) ok1 = true;}for(int i = 1; i < 5; i ++){if(a[i][4 - i] % 2 == a[i - 1][5 - i] % 2){break;}if(i == 4) ok2 = true;}if(ok1 && ok2) ok = true;if(ok) cout << "BINGO" << endl;else cout << "OHNO" << endl;
}signed main(){IOS;int t = 1;
//	cin >> t;while(t --) solve();return 0;
}

下载序列

  • 思维,小根堆

  • 每个文件总共需要的时间(包含下载和文件验证)可以预处理出来,那么我们可以维护一个容量为 m 的队列,每次让当前队列里时间最小的文件出列,并将时间累加到新的入队时间上,那么最终最后一个出队的文件将是时间最大的,记为 tmax,将 tmax * 维护费k 输出即可。

std标程:

cpp">#include <bits/stdc++.h>using namespace std;
typedef long long LL;
const int N = 1e5 + 10;int x, m, k, n, e[N];
priority_queue<LL, vector<LL>, greater<LL>> q;int main() {cin >> x >> m >> k;cin >> n;for (int i = 1; i <= n; i ++){int a, t;cin >> a >> t;e[i] = (a + x - 1) / x + t;}for (int i = 1; i <= m; i ++){q.push(e[i]);}LL ans = 0;for (int i = m + 1; i <= n; i ++){ans = q.top(); q.pop();q.push(e[i] + ans);}while (q.size()){ans = q.top(); q.pop();}cout << ans * k;return 0;
}

会 赢 的

我们只需要以下操作即可:

  1. 选取数组中的 100(至多一个)
  2. 选取 1 ~ 9 之间的一个数
  3. 选取 10 ~ 90 之间能被10整除的数
  4. 如果 2、3 操作选不出任何一个数,那么可以在剩下的数里选任意一个(没有则不选)

std标程:

cpp">#include <stdio.h>int n, a[1010];int main()
{scanf("%d", &n);for (int i = 1; i <= n; i ++)scanf("%d", &a[i]);for (int i = 1; i < n; i ++)for (int j = i + 1; j <= n; j ++)if (a[i] > a[j]){int temp = a[i];a[i] = a[j];a[j] = temp;}int ans = 0, p[5] = {0};for (int i = 1; i <= n; i ++){if (p[1] == 0 && a[i] >= 1 && a[i] <= 9)p[1] ++, ans ++;else if (p[2] == 0 && a[i] >= 10 && a[i] <= 99 && a[i] % 10 == 0)p[2] ++, ans ++;else if (p[3] == 0 && a[i] == 100)p[3] ++, ans ++;elsep[0] ++;}if (p[1] == 0 && p[2] == 0 && p[0] > 0) ans ++;printf("%d", ans);return 0;
}

一血代码:

cpp">#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=110;
int a[5];
int n,res=0,cnt=0;
int main(){cin>>n;for(int i=1;i<=n;i++){int x;cin>>x;if(x==0)a[0]++;else if(x==100)a[1]=1;else if(x>0&&x<10)a[2]++;else a[3]++;if(x%10==0)cnt++;}if(a[0])res+=a[0];if(a[1])res++;if(a[2]&&a[3]){if(cnt)res+=2;else res+=1;}else if(a[2]||a[3])res+=1;cout<<res<<endl;return 0;
}

http://www.ppmy.cn/news/1509421.html

相关文章

Mapreduce_partition分区入门

分区 将输入的csv按照员工号拆分成每个员工&#xff0c;每个员工存储为员工对象&#xff0c;之后按每个员工的不同部门存储 pom <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:x…

react框架安全设计

react框架安全设计 1、易受攻击的React版本 React库在过去有一些严重性很高的漏洞,因此最好保持稳定版中的最新版本。 2、数据绑定 使用默认的{}进行数据绑定,React会自动对值进行转义以防止XSS攻击。但注意这种保护只在渲染textContent时候有用,渲染 HTML attributes的…

【Hot100】LeetCode—560. 和为 K 的子数组

目录 1- 思路前缀和 2- 实现⭐560. 和为 K 的子数组——题解思路 3- ACM 实现 原题链接&#xff1a;560. 和为 K 的子数组 1- 思路 前缀和 ① 借助 HashMap 存储前缀和&#xff1a;Key 为对应的前缀和&#xff0c;Value 为对应的出现次数 hm 初始化放入 (0,1) 代表和为 0 的情…

electron 中的ipcMain.handle和ipcMain.on 的区别

在Electron中,ipcMain.handle和ipcMain.on是主进程(main process)用于处理来自渲染进程(renderer process)消息的两个主要方法,它们之间存在明显的区别,主要体现在消息处理的同步性、响应方式和应用场景上。 ipcMain.on 同步性:ipcMain.on是异步的。当渲染进程通过ipc…

苹果Mac电脑——装macOS和Windows双系统的方法

一、实验环境 在Windows系统电脑上制作MacOS启动U盘。准备一个大于16G的U盘。 二、实验步骤 2.1 在Windows系统电脑上制作MacOS启动U盘 MacOS镜像下载 在Windows系统电脑上制作MacOS启动U盘的方法 2.2 U盘插上苹果电脑&#xff0c;安装macOS系统 U盘插上苹果电脑&#xf…

Unity(2022.3.38LTS) - 下载,安装

目录 A. 简介 B. 下载和安装UnityHub C. 下载安装unity编辑器 安装页面 选择版本 添加模块 D.总结 A. 简介 Unity 是一款广泛使用的跨平台游戏开发引擎。 一、主要特点 跨平台性&#xff1a; 支持多种主流平台&#xff0c;包括 Windows、Mac、Linux、iOS、Android、Xb…

uniapp自定义浮动图标、列表布局

uniapp自定义浮动图标 <button class="fab" @click="goPage"><image src="../../../static/yiyuan.png" mode="" style="width: 60rpx;height:60rpx;"></image></button>.fab {z-index: 100;positi…

FPGA开发板的基本知识及应用

FPGA开发板是一种专门设计用于开发和测试现场可编程门阵列(Field-Programmable Gate Array, FPGA)的硬件平台。FPGA是一种高度可配置的集成电路&#xff0c;能够在制造后被编程以执行各种数字逻辑功能。FPGA开发板通常包含一个FPGA芯片以及一系列支持电路和接口&#xff0c;以便…