【Codeforces 158B】Taxi
【链接】 我是链接,点我呀:)
【题意】
每辆车可以载重4个人.
一共有n个组,每个组分别有s[i]个人.
要求每个组的人都在同一辆车里面.
问最少需要多少辆车
【题解】
将每个组的人数从小到大排序.
然后逆序枚举每个组r.
显然这个组肯定要占用一辆车。
那么现在问题就变成尽可能多带几个人在这一辆车里面。
那么就找人数最小的几个组就好(这样一辆车里面的人能多一点。)
【代码】
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static int N = 100000;
public static int n,k;
public static int s[];
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
s = new int[n];
for (int i = 0;i < n;i++) s[i] = in.nextInt();
Arrays.sort(s);
int l = 0,r = n-1,temp = 0;
while (l<=r) {
int rest = 4;
rest-=s[r];r--;
while (l<=r && rest>=s[l]) {
rest-=s[l];
l++;
}
temp++;
}
System.out.println(temp);
}
}
【Codeforces 158B】Taxi的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- [Codeforces Round495B] Sonya and Exhibition
[题目链接] https://codeforces.com/contest/1004/problem/B [算法] 不难发现 , 最优解一定是01010101.... 时间复杂度 : O(N) [代码 ...
- [Django基础] gunicorn启动django时静态文件的加载
目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时 ...
- 37. ext 中sm什么意思
转自:https://zhidao.baidu.com/question/112450217.htmlsm是SelectionModel的缩写默认为RowSelectionModel其他模式还有Che ...
- codevs地鼠游戏(贪心)
1052 地鼠游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 王钢是一名学习成绩优异的学生,在平时的学习中,他 ...
- windows下 redis/tomcat 服务自启动
//设置redis服务自启动 //根据个人配置执行语句. redis-server --service-install redis.windows.conf --loglevel verbose ...
- ibatis 基类生成
using IBatisNet.Common.Utilities; using IBatisNet.DataMapper; using IBatisNet.DataMapper.Configurati ...
- jQuery获取Select元素
jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Se ...
- 安卓中Canvas实现清屏效果
可以在代码里面添加: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPaint(paint) ...
- python爬虫值requests模块
- 基于如下5点展开requests模块的学习 什么是requests模块 requests模块是python中原生的基于网络请求的模块,其主要作用是用来模拟浏览器发起请求.功能强大,用法简洁高效.在 ...
- Java系列学习(五)-流程控制语句
1.顺序结构 1.if语句 (1)图例 (2)三种格式 A:格式1 B:格式2 C:格式3 2.swich语句 图例: 格式: [注]input可以是byte,short,int,char:JDK5以 ...