快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0
实在太冷了今天
taxi :错误原因1 忽略了 1 1 1 1 和 1 2 1 这种情况,直接认为最多两组一车了
2 语句顺序错
double cola: 忘了减去n的序号1,即n--
3 seconds
256 megabytes
standard input
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)?
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.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
5
1 2 4 3 3
4
8
2 3 4 4 2 1 3 1
5
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); }
1 second
256 megabytes
standard input
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.
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.
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.
1
Sheldon
6
Sheldon
1802
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的更多相关文章
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- 快速切题 poj 2485 Highways prim算法+堆 不完全优化 难度:0
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23033 Accepted: 10612 Descri ...
- CodeForces - 158B.Taxi (贪心)
CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...
- 快速切题 sgu113 Nearly prime numbers 难度:0
113. Nearly prime numbers time limit per test: 0.25 sec. memory limit per test: 4096 KB Nearly prime ...
- B - Double Cola
Problem description Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double C ...
- Double Vision (Unity 5.0)
Double Vision (Unity 5.0): 根据 http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 acdream手速赛(6)A-C
Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...
- 快速切题 sgu136. Erasing Edges
136. Erasing Edges time limit per test: 0.25 sec. memory limit per test: 4096 KB Little Johnny paint ...
随机推荐
- Python开发【Django】:路由规则
Django路由规则 1.基于正则的URL 在templates目录下创建index.html.detail.html文件 <!DOCTYPE html> <html lang=&q ...
- Linux下tomcat启动项目原因排查
先停掉tomcat服务器: 然后把文件删除: 这时候启动服务器: 看下有没有启动成功: 接着把重新优化过的代码用X ftp传上去. 等几分钟就可以. 如果老是出现问题,就去catalina.out文件 ...
- Mysql学习笔记—concat以及group_concat的用法(转载)
本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数 1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接参数产生的字 ...
- 最长DNA重复序列长度,并输出该序列。 JAVA
1: 最长DNA重复序列长度,并输出该序列. 例如 ATCGTAGATCG,它的最大长度为4,序列为 ATCG. package com.li.huawei; import java.util.S ...
- Missing Number-[回溯][难]
2. Missing number 转自:https://mp.weixin.qq.com/s/WLRXLdi-3igkjtiWlHg7Ug Given a positive integer n(n≤ ...
- Selenium IDE脚本录制步骤简介
录制脚本步骤: 1.打开Selenium IDE,输入需要录制脚本的地址,然后启动Firefox,输入selenium IDE需录制的地址,根据实际需求,做相关操作: 2.录制过程中,会发现做的相关操 ...
- curl基本使用
curl简介 linux curl是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载. curl可以使用URL的语法模拟浏览器来传输数据,因为它是模拟浏览器,因此它同样支持多种协 ...
- ubuntu16.04(liunx) 离线安装 xgboost (anaconda3,anaconda2共存)
服务器ubuntu 系统同时安装了 anaconda3,anaconda2 ,但服务器没有连接外网,所以 想在python3 环境下安装离线安装xgboost. 主要分2步: 0:进入py3环境 ( ...
- Linux命令: grep命令
基本用法 ...
- 通过J2EE Web工程添加Flex项目,进行BlazeDS开发
http://www.cnblogs.com/noam/archive/2010/07/22/1782955.html 环境:Eclipse 7.5 + Flex Builder 4 plugin f ...