神牛........你想过来虐我吗?....

C. George and Number

time limit per test   1 second

memory limit per test  256 megabytes

题目连接: 传送门

George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b1, b2, ..., b|b| (record |b| denotes the current length of the array). Then one change is a sequence of actions:

  • Choose two distinct indexes i and j (1 ≤ i, j ≤ |b|; i ≠ j), such that bi ≥ bj.
  • Get number v = concat(bi, bj), where concat(x, y) is a number obtained by adding number y to the end of the decimal record of number x. For example, concat(500, 10) = 50010, concat(2, 2) = 22.
  • Add number v to the end of the array. The length of the array will increase by one.
  • Remove from the array numbers with indexes i and j. The length of the array will decrease by two, and elements of the array will become re-numbered from 1 to current length of the array.

George played for a long time with his array b and received from array b an array consisting of exactly one number p. Now George wants to know: what is the maximum number of elements array b could contain originally? Help him find this number. Note that originally the array could contain only positive integers.

Input

The first line of the input contains a single integer p (1 ≤ p < 10100000). It is guaranteed that number p doesn't contain any leading zeroes.

Output

Print an integer — the maximum number of elements array b could contain originally.

Sample test(s)
Input
9555
Output
4
Input
10000000005
Output
2
Input
800101
Output
3
Input
45
Output
1
Input
1000000000000001223300003342220044555
Output
17
Input
19992000
Output
1
Input
310200
Output
2
Note

Let's consider the test examples:

  • Originally array b can be equal to {5, 9, 5, 5}. The sequence of George's changes could have been: {5, 9, 5, 5} → {5, 5, 95} → {95, 55} → {9555}.
  • Originally array b could be equal to {1000000000, 5}. Please note that the array b cannot contain zeros.
  • Originally array b could be equal to {800, 10, 1}.
  • Originally array b could be equal to {45}. It cannot be equal to {4, 5}, because George can get only array {54} from this array in one operation.

Note that the numbers can be very large.


意解:贪心

AC代码:

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    string s,c,t;
    while(cin>>s)
    {
        t = "";
        int point = 0,ans = 1;
        t += s[point++];
        while(s[point] == '0') t += s[point++];
        while(point < s.size())
        {
            c = "";
            c += s[point++];
            while(s[point] == '0') c += s[point++];
            if(t.size() > c.size() ||  (t.size()==c.size() && t >= c)) ans++;
            else ans = 1;
            t += c;
        }
        cout<<ans<<endl;
    }
    return 0;
}



C. Bombs

time limit per test   2 seconds

memory limit per test   256 megabytes

You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (xi, yi). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0, 0). Initially, the robot is at point with coordinates (0, 0). Also, let's mark the robot's current position as (x, y). In order to destroy all the bombs, the robot can perform three types of operations:

  1. Operation has format "1 k dir". To perform the operation robot have to move in direction dir k (k ≥ 1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) (corresponding to directions). It is forbidden to move from point (x, y), if at least one point on the path (besides the destination point) contains a bomb.
  2. Operation has format "2". To perform the operation robot have to pick a bomb at point (x, y) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (x, y) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container.
  3. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0, 0). It is forbidden to perform the operation if the container has no bomb.

Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of bombs on the coordinate plane. Next n lines contain two integers each. The i-th line contains numbers (xi, yi) ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0, 0).

Output

In a single line print a single integer k — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these k operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where k ≤ 106.

Sample test(s)
Input
2
1 1
-1 -1
Output
12
1 1 R
1 1 U
2
1 1 L
1 1 D
3
1 1 L
1 1 D
2
1 1 R
1 1 U
3
Input
3
5 0
0 5
1 0
Output
12
1 1 R
2
1 1 L
3
1 5 R
2
1 5 L
3
1 5 U
2
1 5 D
3

意解:纯模拟;按xy轴走就行了.

AC代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int M = 1e5 + 100;
struct Robot
{
    int x,y;
    //Robot(int x, int y) : x(x),y(y) {}
    bool operator < (const Robot & a) const
    {
        return abs(x) < abs(a.x) || (abs(x) == abs(a.x) && abs(y) < abs(a.y));
    }
    void read()
    {
        scanf("%d %d",&x,&y);
    }
}ro[M];

void check(Robot a)
{
    if(a.x > 0) printf("1 %d R\n",a.x);
    else if(a.x < 0) printf("1 %d L\n",-a.x);
    if(a.y > 0) printf("1 %d U\n",a.y);
    else if(a.y < 0) printf("1 %d D\n",-a.y);
}

int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    while(cin>>n)
    {
        int k = n << 1;
        for(int i = 0; i < n; i++)
        {
            ro[i].read();
            if(ro[i].x && ro[i].y) k += 4;
            else k += 2;
        }
        printf("%d\n",k);
        sort(ro,ro + n);
        for(int i = 0; i < n; i++)
        {
            check(ro[i]);
            puts("2");
            ro[i].x = -ro[i].x;
            ro[i].y = -ro[i].y;
            check(ro[i]);
            puts("3");
        }
    }
    return 0;
}

 
C. k-Multiple Free Set
time limit per test
2 seconds
memory limit per test
256 megabytes

A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.

You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

All the numbers in the lines are separated by single spaces.

Output

On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.

Sample test(s)
Input
6 2
2 3 6 5 4 10
Output
3
Note

In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.


意解:贪心,set的运用.


AC代码:

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

set<int>ms,ls;
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    while(n--)
    {
        int x;
        scanf("%d",&x);
        ms.insert(x);
    }
    set<int> :: iterator it = ms.begin();
    ls.insert(*it);
    for(it++; it != ms.end(); it++)
    {
        if(ls.find((*it) / k) != ls.end() && (*it) % k == 0) continue;
        ls.insert(*it);
    }
    printf("%d\n",ls.size());
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值