当前位置:网站首页>The Martian - Simple Math Problems
The Martian - Simple Math Problems
2022-08-09 08:02:00 【scwMason】
The question is simply that five fingers represent 1 2 3 4 5, and then arrange them from small to large, and then calculate the largest number in the entire arrangement according to the second data given
Then the first thing we have to solve is: the order problem of sorting from small to large, here we can use two methods:
1. Handwritten code
2.STL function
The handwritten code mainly masters the following logic
1. First, look for two adjacent elements from the end, let the first element be *i, the second element be *ii, and satisfy *i<*ii.
2. After finding such a set of adjacent elements, check forward from the end to find the first element greater than *i, let it be *j, and swap the i and j elements (swap).
3. Reverse all elements after ii.
Then you can write the code:
#include#include#includeusing namespace std;int arr[10005],n,m;void work(){int flag;//find the first set of arr[i]=0;i--){if(arr[i]=0;i--){if(arr[i]>arr[flag]){int cur=arr[flag];arr[flag]=arr[i];arr[i]=cur;break;}}//Reverse all numbers after flagint left=flag+1,right=n-1;while(left<=right){int ds=arr[left];arr[left]=arr[right];arr[right]=ds;left++;right--;}}int main(){scanf("%d%d",&n,&m);for(int i=0;i
If you use STL functions, you can:
#include#include#includeusing namespace std;int arr[10005],n,m;}int main(){scanf("%d%d",&n,&m);for(int i=0;i
The principle is the same
边栏推荐
猜你喜欢
随机推荐
测试和开发之间的恩恩怨怨
Set集合
Forest Program DFS + tanjar cactus
火星人 --简单的数学题
VMware虚拟机强制关闭后,无法联网
浅谈Endpoint
种子数据报错:liquibase.exception.ValidationFailedException: Validation Failed
Native JDBC operation database
网络布线及数制转换
测试流程
libtorch示例
db2数据库备份恢复问题
如何把无用的代码注释为 Deprecated 弃用
Win10电脑的WLAN消失的故事
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Visualize、HOOPS Publish
.net(四) 数据层实现
Anaconda use proxy
Laravel文档阅读笔记-Rendering JSON(对JS变量进行赋值)
2019 Nanchang Internet Competition Question C, Hello 2019
Jmeter连接Mysql和Mysql编码问题