实在太冷了今天

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. jquery 获取对象

    jquery 获取对象 1.引用this作为对象时,必须以$(this)的形式变为对象目标,否则,无法识别,会报错“ has no method”

  2. Python开发【数据结构】:基础

    数据结构 什么是数据结构? 简单来说,数据结构就是设计数据以何种方式组织并存储在计算机中. 比如:列表.集合与字典等都是一种数据结构 N.Wirth: “程序=数据结构+算法” 列表 列表:在其他编程 ...

  3. day17(JDBC入门&jdbcUtils工具介绍)

    day17 JDBC整体思维导图 JDBC入门 导jar包:驱动! 加载驱动类:Class.forName("类名"); 给出url.username.password,其中url ...

  4. 2018 Multi-University Training Contest 8 Solution

    A - Character Encoding 题意:用m个$0-n-1$的数去构成k,求方案数 思路:当没有0-n-1这个条件是答案为C(k+m-1, m-1),减去有大于的关于n的情况,当有i个n时 ...

  5. web上的复制

    你可能曾经尝试过复制网页上的一些文字,得到的却是令人沮丧的的结果.这篇文章介绍相关的内容. 不是真正的文字 这可能是最常见的问题,很多人尝试对一张带有文字的图片进行像文字那样的选择,复制当然不行了. ...

  6. android自定义Activity窗口大小(theme运用)

    http://gundumw100.iteye.com/blog/906195 正常情况下,我们开发的应用程序都会上占满整个屏幕,那么怎么样才能开发出自定义窗口大小的的程序呢?如下图所示: 实现起来非 ...

  7. Java编程学习之JDBC连接MySQL

    JDBC连接MySQL 一.对JDBC连接数据库的步骤1.加载数据库驱动//加载驱动Class.forName(driverClass)-------------------------------- ...

  8. 关于JS和JSON

    讲得不准确! 看网课,JS也算是面向对象的一门语言,不过其是解释性的脚本语言. JSON是把用JS的表示法将数据包装起来进行传递用的. JS语法是松散型的,没有int String这些像JAVA里的类 ...

  9. UVa 12549 机器人警卫(最小点覆盖)

    https://vjudge.net/problem/UVA-12549 题意: 在一个Y行X列的网格里有空地(.),重要位置(*)和障碍物(#),用最少的机器人看守所有重要位置,每个机器人要放在一个 ...

  10. hdu 4739 Zhuge Liang's Mines DFS

    http://acm.hdu.edu.cn/showproblem.php?pid=4739 题意: 给定100*100的矩阵中n(n<= 20)个点,每次只能一走能够形成正方形的四个点,正方形 ...