当前位置:网站首页>*6-3 节约小能手
*6-3 节约小能手
2022-07-25 09:19:00 【叶萧白】
题目描述

源代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100000;
int a[N + 1];
int b[N + 1];
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int n, m,t=0,d,i,j;
cin >> n >> m;
int count = 0;
int x;
for ( i = 0; i < n; i++)
{
cin >> a[i];
}
while (1)
{
for (j = 2; j <= a[n - 1]; j++)
{
t = 0;
for (i = 0; i < n; i++)
{
t += a[i] / j;
if (t == m)
{
b[i] = j;
break;
}
}
}
sort(b, b + N + 1, cmp);
cout << b[0] << endl;
break;
}
return 0;
}
关于这题
这里用了sort来帮助我们排序
如果根数满足要求 我们就存到 b数组里 再用sort 进行降序排序 求得最长长度
(这道老师给的题 没有找到能测试代码的地方 题目给的两个案例是能通过的 )
边栏推荐
- Leetcode组合总和+剪枝
- Understand why we should rewrite the equals method and hashcode method at the same time + example analysis
- OverTheWire-Bandit
- 通过robocopy对文件/夹进行复制
- C language and SQL Server database technology
- activemq--消息重试机制
- activemq--持久化机制之LevelDB
- 将list集合的某一字段拼接单个String
- Bi business interview with data center and business intelligence (I): preparation for Industry and business research
- 数据查询语言(DQL)
猜你喜欢
随机推荐
~4.1 剑指 Offer 05. 替换空格
[GYCTF2020]Ez_Express
Click to hide the column in wechat applet, and then click to show it
registration status: 204
ActiveMQ -- AMQ of persistent mechanism
ActiveMQ -- dead letter queue
C#语言和SQL Server数据库技术
OverTheWire-Bandit
Detailed explanation of pipeline pipeline mechanism in redis
动态添加多tab,并初始化每个tab页面
卷积神经网络的兴趣简单介绍
『每日一问』简单聊聊JMM/说说对JMM的了解
ActiveMQ -- JDBC Journal of persistent mechanism
抽象类和接口的区别(最详细)
OmniPeek packet capturing tool
神经网络方法——美国波士顿房价(回归问题)
matplotlib数据可视化三分钟入门,半小时入魔?
通过robocopy对文件/夹进行复制
Two Sum
[HCTF 2018]admin









