Codeforces Round #554 (Div. 2)

A. Neko Finds Grapes

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

On a random day, Neko found nn treasure chests and mm keys. The ii-th chest has an integer aiai written on it and the jj-th key has an integer bjbj on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.

The jj-th key can be used to unlock the ii-th chest if and only if the sum of the key number and the chest number is an odd number. Formally, ai+bj≡1(mod2)ai+bj≡1(mod2). One key can be used to open at most one chest, and one chest can be opened at most once.

Find the maximum number of chests Neko can open.

Input

The first line contains integers nn and mm (1≤n,m≤1051≤n,m≤105) — the number of chests and the number of keys.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the numbers written on the treasure chests.

The third line contains mm integers b1,b2,…,bmb1,b2,…,bm (1≤bi≤1091≤bi≤109) — the numbers written on the keys.

Output

Print the maximum number of chests you can open.

Examples

input

Copy

5 4
9 14 6 2 11
8 4 7 20

output

Copy

3

input

Copy

5 1
2 4 6 8 10
5

output

Copy

1

input

Copy

1 4
10
20 30 40 50

output

Copy

0

Note

In the first example, one possible way to unlock 33 chests is as follows:

  • Use first key to unlock the fifth chest,
  • Use third key to unlock the second chest,
  • Use fourth key to unlock the first chest.

In the second example, you can use the only key to unlock any single chest (note that one key can't be used twice).

In the third example, no key can unlock the given chest.

题目大意:

给出两组数,问用两组数中的数任意相加(两组间)问怎样组合得出的奇数最多?

很显然,用第一组的奇数和第二组的偶数相加,第一组的偶数和第二组的奇数相加,因为只有奇数和偶数相加才能得到奇数。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,ans;
int main()
{
    while(~scanf("%d%d",&n,&m)){
        ans=0;
        int n1=0,n2=0;
        int m1=0,m2=0;
        int x;
        for(int i=1;i<=n;i++){
            scanf("%d",&x);
            if(x&1)
                n1++;
            else n2++;
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&x);
            if(x&1)
                m1++;
            else m2++;
        }
        printf("%d\n",min(n1,m2)+min(n2,m1));
    }
}

B. Neko Performs Cat Furrier Transform

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat.

Assume that we have a cat with a number xx. A perfect longcat is a cat with a number equal 2m−12m−1 for some non-negative integer mm. For example, the numbers 00, 11, 33, 77, 1515 and so on are suitable for the perfect longcats.

In the Cat Furrier Transform, the following operations can be performed on xx:

  • (Operation A): you select any non-negative integer nn and replace xx with x⊕(2n−1)x⊕(2n−1), with ⊕⊕ being a bitwise XOR operator.
  • (Operation B): replace xx with x+1x+1.

The first applied operation must be of type A, the second of type B, the third of type A again, and so on. Formally, if we number operations from one in the order they are executed, then odd-numbered operations must be of type A and the even-numbered operations must be of type B.

Neko wants to produce perfect longcats at industrial scale, thus for each cat Neko only wants to perform at most 4040 operations. Can you help Neko writing a transformation plan?

Note that it is not required to minimize the number of operations. You just need to use no more than 4040 operations.

Input

The only line contains a single integer xx (1≤x≤1061≤x≤106).

Output

The first line should contain a single integer tt (0≤t≤400≤t≤40) — the number of operations to apply.

Then for each odd-numbered operation print the corresponding number nini in it. That is, print ⌈t2⌉⌈t2⌉ integers nini (0≤ni≤300≤ni≤30), denoting the replacement xx with x⊕(2ni−1)x⊕(2ni−1) in the corresponding step.

If there are multiple possible answers, you can print any of them. It is possible to show, that there is at least one answer in the constraints of this problem.

Examples

input

Copy

39

output

Copy

4
5 3 

input

Copy

1

output

Copy

0

input

Copy

7

output

Copy

0

Note

In the first test, one of the transforms might be as follows: 39→56→57→62→6339→56→57→62→63. Or more precisely:

  1. Pick n=5n=5. xx is transformed into 39⊕3139⊕31, or 5656.
  2. Increase xx by 11, changing its value to 5757.
  3. Pick n=3n=3. xx is transformed into 57⊕757⊕7, or 6262.
  4. Increase xx by 11, changing its value to 63=26−163=26−1.

In the second and third test, the number already satisfies the goal requirement.

题目大意:

给一个数x,有两种操作,一个是x异或2^n-1,另一个是x+1,问要经过几次步骤才能把它变为2^n-1的形式,并把用到的n输出

理解错题意就很尴尬了。。。

一开始以为两个步骤是一起的,必须都执行,然后把x转化为二进制形式,从左往右找到第一个为0的数的位置,即数x为0的最高位的位置,例如样例1的39,转化为二进制为100111,为0的最高位是从左往右数第二个数,即它的第5位,所以这个5就是n,2^5-1就是11111,这样可以把那两个0转换为1,然后把得出的数加1,再继续这个步骤。因为肯定要先转为高位的。

但其实可以发现如果两个步骤必须都执行,当x是2^n的形式,即为0,1,2,4,8......时按照这个形式它会一直进行下去,大家自己可以手动算一下,,其实这个时候按照上面的思想只需要异或一次其实就完成了,,不需要第二步。。。但我以为两步都必须要有,,所以就t了......到最后才醒悟过来

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
int n,ans,a[32];
int f(int n)
{
    int res=n;
    int pos=0;
    int t=1;
    while(res){
        if((res&1)==0)
            pos=t;
            t++;
            res>>=1;
    }
    return pos;
}
int main()
{
    for(int i=0;i<=31;i++)
        a[i]=(1<<i)-1;
    while(~scanf("%d",&n)){
        ans=0; //ans记录步骤数
        int num=0;  //记录要进行异或的数
        while(1){
            int pos=f(n);
            if(pos==0)
                break;
             ans++;
             num++;
             bool flag=false;
            a[num]=pos;
            n^=(1<<pos)-1;
            for(int i=0;i<=31;i++)
                if(a[i]==n){
                    flag=true;
                    break;
                }
                if(flag)
                    break;
               n++;
               ans++;
        }
         printf("%d\n",ans);
        for(int i=1;i<=num;i++){
                if(i==ans)
            printf("%d",a[i]);
        else printf("%d ",a[i]);
        }
        if(ans!=0)
        printf("\n");
    }
}

C还没来的及补......

猜你喜欢

转载自blog.csdn.net/curry___/article/details/89508615
今日推荐