CodeForces 158 B. Taxi(模拟)
【题目链接】click here~~
【题目大意】n组团体去包车,每组团体的人数《=4,一辆车最多容纳4人,求所求车的数目最小
【解题思路】:思路见代码~~
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif #include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> #if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif // C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector> #if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif using namespace std;
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;++i)
#define per(i,j,k) for(int i=(int)j;i>=(int)k;--i)
typedef long long LL;
typedef unsigned long long LLU;
typedef double db;
const int N=2*1e5+10;
LL n,m,t,ans,res,cnt,tmp; int aa[N],bb[N];
char str[N];
bool vis[N];
int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; int main()
{
while(cin>>n)
{
memset(aa,0,sizeof(aa));
int sum=0;
rep(i,1,n){
cin>>tmp;
aa[tmp]++;
}
printf("%d\n",((max(aa[1]-aa[3],0)+3+aa[2]*2)/4+aa[3]+aa[4]));
}
return 0;
}
/*
2组的话直接乘以2对4相除
3,4组直接放入一辆车
然后对于1组 1
比較1组和3组的大小。若大于三组。则说明将当中的1与3合并后还剩下1组,
多余的1我们如果还与3合并,由于2组已经乘以2计算,最后结果对4相除,
相加就可以
*/
/*
Sample Input
5
1 2 4 3 3
8
2 3 4 4 2 1 3 1
9
2 2 2 3 1 3 1 4 4
8
2 2 2 3 1 3 4 4
Sample Output
4
5
6
6
*/
CodeForces 158 B. Taxi(模拟)的更多相关文章
- Codeforces 158 B. Taxi[贪心/模拟/一辆车最多可以坐4人同一个群的小朋友必须坐同一辆车问最少需要多少辆车]
http://codeforces.com/problemset/problem/158/B B. Taxi time limit per test 3 seconds memory limit pe ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 158 D
题目链接 :http://codeforces.com/contest/158/problem/D D. Ice Sculptures time limit per test 3 seconds me ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
随机推荐
- Eclipse中Cannot find any provider supporting DES解决之道
原文出处:http://blog.csdn.net/darwinchina/article/details/12037999 异常: Caused by: java.security.NoSuchAl ...
- crtmpserver通常使用基本类演示
以前我们做了分析过程,这一次,我们都参与了类做梳子,两个可以一起关注一下一起合并,整个方案的实施是有帮助. BaseClientApplication APP基类,一切APP都基于这个类 Stream ...
- Javascript高级程序设计读书笔记(第二章)
第二章 在HTML中使用Javascript 2.1<script>元素 延迟脚本(defer = "defer")表明脚本在执行时不会影响页面的构造,脚本会被延迟到 ...
- Android与JS混编(js调用android相机扫描二维码)
参考demo http://www.cnblogs.com/mythou/p/3280023.html 项目源码: https://github.com/weifengzz/Androi ...
- SQL中常用的时间格式
一些常用的时间格式 先讲一下一些基本的格式模式 格式模式 说明 d 月中的某一天.一位数的日期没有前导零. dd 月中的某 ...
- Oracle触发器Trigger4触发条件_when的使用
/* 同一表使用所有条件 Create or replace trigger t5 Before insert,delete,update on 表名 For each row //plsql块 */ ...
- oc随笔六:字典
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- hdu 1009 贪心基础题
B - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bi ...
- python字符串的encode和decode
原文 decode的作用是将其他编码的字符串转换成unicode编码. str1.decode('gb2312') #表示将gb2312编码的字符串转换成unicode编码 encode的作用是将un ...
- 修改mysql的默认字符集
\s 查看mysql的字符集 把server characterset和db characterset修改成utf8 在my.ini的mysqld下面添加两行代码,重启mysql [mysql] de ...