快速切题CF 158B taxi 构造 && 82A double cola 数学观察 难度:0

实在太冷了今天

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;
}

  

posted @ 2014-11-11 21:40  雪溯  阅读(503)  评论(0编辑  收藏  举报