实在太冷了今天

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. 洛谷 P2602 [ZJOI2010]数字计数

    洛谷 第一次找规律A了一道紫题,写篇博客纪念一下. 这题很明显是数位dp,但是身为蒟蒻我不会呀,于是就像分块打表水过去. 数据范围是\(10^{12}\),我就\(10^6\)一百万一百万的打表. 于 ...

  2. Selenium之IE浏览器的启动

    1.下载IEDriverServer.exe文件放至需要的目录中: 2.编写代码 import org.openqa.selenium.WebDriver; import org.openqa.sel ...

  3. Selenium之firefox浏览器的启动

    1.编写如下代码 import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; /** ...

  4. enum 枚举类型默认值

    enum value { one, two, three, four }; 默认值

  5. Sql Server查询同一ID 时间较大的一条数据

  6. 2018 Multi-University Training Contest 4 Solution

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

  7. Qt信号和槽连接方式的选择

    看了下Qt的帮助文档,发现connect函数最后还有一个缺省参数. connect函数原型是这样的: QMetaObject::Connection QObject::connect(const QO ...

  8. foo、bar美国版的张三李四

    不管看javascript还是其他语言举例,经常看到使用foo和bar来充当变量.那么究竟foo.bar是什么鬼? 一说:foo 和 bar 组合在一起所构成的 foobar 应该最能反映其原始的意思 ...

  9. WebCollector2.7爬虫框架——在Eclipse项目中配置

    WebCollector2.7爬虫框架——在Eclipse项目中配置 在Eclipse项目中使用WebCollector爬虫非常简单,不需要任何其他的配置,只需要导入相关的jar包即可. Netbea ...

  10. 20145221 《Java程序设计》第九周学习总结

    20145221 <Java程序设计>第九周学习总结 教材学习内容总结 整合数据库 JDBC入门 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则对接口进行 ...