【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- 【POJ 1716】 Integer Intervals
[题目链接] 点击打开链接 [算法] 差分约束系统 [代码] #include <algorithm> #include <bitset> #include <cctyp ...
- JZOJ 5461 购物 —— 贪心
题目:https://jzoj.net/senior/#main/show/5461 贪心,原来想了个思路,优先选优惠价最小的 K 个,然后其他按原价排序遍历: 如果当前物品没选过,原价选上,如果选过 ...
- 使用 Jenkins + GitHub + Nginx + HTTPS 搭建静态网站
参考https://www.imooc.com/article/20079 http://www.haoduoyu.cc/
- Linux扩展正则表达式
1. 扩展正则表达式 1.1 +(加号) + 表示前一个字符出现1次或1次以上 1.1.1 理解+ 要求:取出文件内容连续出现的小写字母 [root@oldboyedu50-lnb /oldboy]# ...
- Linux分区方式 及 Xshell远程连接排错
第1章 远程连接 1.1 Linux远程连接软件 Windows: Xshell/SecureCRT/Putty mac: 终端ssh命令或iterm2 Android: ...
- 一个不错的jquery插件模版
pageplugin.js (function ($) { $.PagePlugin = function (obj, opt) { var options = $.extend({}, $.Page ...
- mahjong
题目描述 “为什么, 你们的力量在哪里得到如此地......”“我们比 1 分钟前的我们还要进步, 虽然很微小, 但每转一圈就会前进一寸.这就是钻头啊!”“那才是通向毁灭的道路.为什么就没有意识到螺旋 ...
- JVM 垃圾回收器详解
小结: 新生代 串行Serial 并行 Parallel(关注吞吐量) 并行ParNew 老年代 串行 Serial Old 并行Para ...
- CF831C Jury Marks
思路: 关键在于“插入”一个得分之后,其他所有得分也随之确定了. 实现: #include <iostream> #include <cstdio> #include < ...
- React Native导航器Navigator
React Native导航器Navigator 使用导航器可以让你在应用的不同场景(页面)间进行切换.导航器通过路由对象来分辨不同的场景.利用renderScene方法,导航栏可以根据指定的路由来渲 ...