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還沒來的及補......

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章