实在太冷了今天

taxi :错误原因1 忽略了 1 1 1 1 和 1 2 1 这种情况,直接认为最多两组一车了

2 语句顺序错

double cola: 忘了减去n的序号1,即n--

B. Taxi
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output

Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Sample test(s)
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
Note

In the first test we can sort the children into four cars like this:

  • the third group (consisting of four children),
  • the fourth group (consisting of three children),
  • the fifth group (consisting of three children),
  • the first and the second group (consisting of one and two children, correspondingly).

There are other ways to sort the groups into four cars.

#include <cstdio>
#include <cstring>
using namespace std;
int n,temp,num[5];
int main(){
scanf("%d",&n);
while(n--){scanf("%d",&temp);num[temp]++;}
int ans=num[4];
if(num[3]>=num[1]){
num[3]-=num[1];
ans+=num[1];
num[1]=0;
}
else {
ans+=num[3];
num[1]-=num[3];
num[3]=0;
}
if(num[2]>=(num[1]+1)/2){
num[2]-=(num[1]+1)/2;
ans+=(num[1]+1)/2;
num[1]=0;
}
else {
ans+=num[2];
num[1]-=2*num[2];
num[2]=0;
}
ans+=(num[1]+3)/4+(num[2]+1)/2+num[3];
printf("%d\n",ans); }

  

A. Double Cola
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.

For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.

Write a program that will print the name of a man who will drink the n-th can.

Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.

Input

The input data consist of a single integer n (1 ≤ n ≤ 109).

It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.

Output

Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.

Sample test(s)
input
1
output
Sheldon
input
6
output
Sheldon
input
1802
output
Penny
#include <cstdio>
#include <cstring>
using namespace std;
int base[30];
long long fifb[30];
char name[5][10]={
"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"
};
int main(){
int n;
for(int i=0;i<30;i++){base[i]=1<<i;fifb[i]=(i?fifb[i-1]:0)+5*base[i];}
while( scanf("%d",&n)==1){
for(int i=0;i<30;i++){
if(fifb[i]>=n){
int gap=(n-(i?fifb[i-1]+1:1))/base[i];
puts(name[gap]);
break;
}
}}
return 0;
}

  

快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0的更多相关文章

  1. 快速切题 poj 1003 hangover 数学观察 难度:0

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103896   Accepted: 50542 Descr ...

  2. 快速切题 poj 2485 Highways prim算法+堆 不完全优化 难度:0

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23033   Accepted: 10612 Descri ...

  3. CodeForces - 158B.Taxi (贪心)

    CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...

  4. 快速切题 sgu113 Nearly prime numbers 难度:0

    113. Nearly prime numbers time limit per test: 0.25 sec. memory limit per test: 4096 KB Nearly prime ...

  5. B - Double Cola

    Problem description Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double C ...

  6. Double Vision (Unity 5.0)

    Double Vision (Unity 5.0): 根据 http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html ...

  7. 快速切题 sgu120. Archipelago 计算几何

    120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...

  8. 快速切题 acdream手速赛(6)A-C

    Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  9. 快速切题 sgu136. Erasing Edges

    136. Erasing Edges time limit per test: 0.25 sec. memory limit per test: 4096 KB Little Johnny paint ...

随机推荐

  1. 个人理解---KMP与Next数组详解

    Kmp就是求子串在母串中的位置等相关问题:当然KMP最重要的是Next数组,也称失败数组,Next[i]代表的意思是子串 sub 从sub[0] 到 sub[i-1]的前缀和后缀的最大匹配.模拟KMP ...

  2. 关于Controller层返回JSON字符串

    /** * 导入jackson包. * @param pn * @return */ @RequestMapping("/emps") @ResponseBody public M ...

  3. Navicat连接服务器上的Mysql数据库

  4. 表单(中)-EasyUI Combogrid 组合网格、EasyUI Numberbox 数字框、EasyUI Datebox 日期框、EasyUI Datetimebox 日期时间框、EasyUI Calendar 日历

    EasyUI Combogrid 组合网格 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults.通过 $.fn.combogrid.defaults 重写 ...

  5. sql用法

    1:  SELECT `SCHEMA_NAME`  FROM `information_schema`.`SCHEMATA`;    查询sql中的数据库名 2:  select * from for ...

  6. 一个很大的文件,存放了10G个整数的乱序数列,如何用程序找出中位数。

    一.梳理审题 一.看清题目: 注意这个题目的量词,这个文件中有10G个整数,而不是这个文件占了10G的内存空间. 二.一些疑问: 在计算机中我们讲的G.M等都是存储容量的概念,但是一般都会在会面加上B ...

  7. 2018 Multi-University Training Contest 4 Solution

    A - Problem A. Integers Exhibition 留坑. B - Problem B. Harvest of Apples 题意:计算$\sum_{i = 0}^{i = m}C( ...

  8. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) Solution

    A. Drawing Borders Unsolved. B. Buildings Unsolved. C. Joyride Upsolved. 题意: 在游乐园中,有n个游玩设施,有些设施之间有道路 ...

  9. 20155203 2016-2017-4 《Java程序设计》第8周学习总结

    20155203 2016-2017-4 <Java程序设计>第8周学习总结 教材学习内容总结 1.channel的继承架构 2.position()类似于堆栈操作中的栈顶指针. 3.Pa ...

  10. docker 删除所有的 docker ps -a 记录

    docker rm `docker ps -a -q` 删除的是镜像运行的实例,要删除镜像用docker rmi + 镜像名或者那串字符(image  id)