2017 计蒜之道 初赛 第五场 A. UCloud 机房的网络搭建
2024-08-21 20:37:00
贪心。
从大到小排序之后进行模拟,注意$n=1$和$n=0$的情况。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std; int n,m;
int a[100010]; bool cmp(int x,int y)
{
return x>y;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d",&a[i]); sort(a+1,a+1+m,cmp); int now = n; if(n==0||n==1)
{
printf("0\n");
return 0;
} for(int i=1;i<=m;i++)
{
if(a[i] <= 0) break;
if(a[i]<now)
{
now = now - a[i];
a[i+1]--;
}
else
{
now = 0;
printf("%d\n",i);
break;
}
} if(now!=0)
{
printf("Impossible\n");
} return 0;
}
最新文章
- CSS 使用母版页的内容页如何调用css和javascript
- MySQL的特点
- eclipse启动时报错 Could not create the java virtual machine
- Swift开发小技巧--private访问修饰符报错的情况
- 纸上谈兵:哈希表(hash table)
- Android开发之 Android应用程序目录结构解析
- JQuery下CheckBox全选全不选反选
- iOS应用架构谈 本地持久化方案及动态部署
- Google Java Style Guide
- 转载Expression Tree揭秘
- linux shell 远程执行命令
- h5开发app之在线生成二维码
- 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——解码篇:(一)用ffmpeg解码视频
- Android源码浅析(一)——VMware Workstation Pro和Ubuntu Kylin 16.04 LTS安装配置
- C语言之linux内核--BCD码转二进制与二进制转BCD码(笔试经典)
- MT【241】红蓝两色染色
- Toy Train(贪心)
- App调试的几个命令实践【转】
- django基础 -- 1. 前奏 web框架的本质
- 使用zabbix-java-gateway可以通过该网关来监听多个JVM