Codeforces Round #219 (Div. 2) A-C

最近在倒腾准备考试,做题有点少啊。。。得多刷点了啊。。sad。。

A。水题看懂题意就可以了啊,一开始竟然忘记了人有两只手,哈哈,真逗啊、、、

A. Collecting Beats is Fun
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Cucumber boy is fan of Kyubeat, a famous music game.

Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel.

Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.

You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.

Input

The first line contains a single integer k (1 ≤ k ≤ 5) — the number of panels Cucumber boy can press with his one hand.

Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit i was written on the panel, it means the boy has to press that panel in time i. If period was written on the panel, he doesn't have to press that panel.

Output

Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).

Sample test(s)
input
1
.135
1247
3468
5789
output
YES
input
5
..1.
1111
..1.
..1.
output
YES
input
1
....
12.1
.2..
.2..
output
NO
Note

In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define LL long long
#define INF 1 << 30;


using namespace std;

int main()
{
    char s;
    int n, sum[20];
    int i, j;
    while(cin >>n)
    {
        memset(sum , 0 , sizeof(sum));
        for(i = 0; i < 4; i++)
            for(j = 0; j < 4; j++)
            {
                cin >>s;
                if(s != '.')
                {
                    sum[s-'0'] ++;
                }
            }
        int flat = 0;
        for(i = 1; i <= 9; i++)
            if(sum[i] > 2*n)
                flat = 1;
        if(!flat)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

B。注意数据范围啊。。。

B. Making Sequences is Fun
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3,S(114514) = 6.

You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(nk to add the number n to the sequence.

You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.

Input

The first line contains three integers w (1 ≤ w ≤ 1016), m (1 ≤ m ≤ 1016), k (1 ≤ k ≤ 109).

Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cincout streams or the %I64dspecifier.

Output

The first line should contain a single integer — the answer to the problem.

Sample test(s)
input
9 1 1
output
9
input
77 7 7
output
7
input
114 5 14
output
6
input
1 1 2
output
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 1001000
#define LL __int64
#define INF 1 << 30


using namespace std;

int num(LL n)
{
    int t = 0;
    while(n)
    {
        t++;
        n /= 10;
    }
    return t;
}
int main()
{
    unsigned LL w, m, k;
    unsigned LL sum, cnt;
    while(cin >>w>>m>>k)
    {
        sum = 0;
        cnt = 0;
        while(1)
        {
            int s = num(m);
            //cout <<s<<endl;
            LL t = (LL)pow(10.0, s);
            LL f = t-m;
            if(w >= f*s*k)
            {
                w -= f*s*k;
                cnt += f;
            }
            else
            {
                LL p = w/(s*k);
                w = 0;
                cnt += p;
            }
            if(w <= 0)
                break;
            else
                m = t;
        }
        cout <<cnt<<endl;
    }
    return 0;
}
C。这个题有点sad啊、、一开始想错了啊,二分找的结果会有少的情况啊。。。其实最少也就n/2种情况啊,O(n)一遍查找就可以了啊..

C. Counting Kangaroos is Fun
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.

Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.

The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.

Input

The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).

Output

Output a single integer — the optimal number of visible kangaroos.

Sample test(s)
input
8
2
5
7
6
9
8
4
2
output
5
input
8
9
1
6
2
6
5
8
3
output
5
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 1001000
#define LL long long
#define INF 1 << 30;


using namespace std;

int main()
{
    int n;
    int f[M];
    int i;
    while(cin >>n)
    {
        for(i = 0; i < n; i++)
            cin >>f[i];
        sort(f, f+n);
        int p = n-1;
        int sum = 0;
        for(i = n/2-1; i >= 0; i--)
        {
            if(f[p] >= 2*f[i])
            {
                p--;
                sum ++;
            }
        }
        cout <<n-sum<<endl;
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值