C++解题——codeforces#586(A-D)

A. Cards

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy’s mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn’t yet able to read. His father decided to rearrange them. Help him restore the original number, on condition that it was the maximum possible one.
Input

The first line contains a single integer n
(1⩽n⩽105) — the length of the string. The second line contains a string consisting of English lowercase letters: ‘z’, ‘e’, ‘r’, ‘o’ and ‘n’.

It is guaranteed that it is possible to rearrange the letters in such a way that they form a sequence of words, each being either “zero” which corresponds to the digit 0
or “one” which corresponds to the digit 1

.
Output

Print the maximum possible number in binary notation. Print binary digits separated by a space. The leading zeroes are allowed.
Examples
Input

4
ezor

Output

0

Input

10
nznooeeoer

Output

1 1 0

Note

In the first example, the correct initial ordering is “zero”.

In the second example, the correct initial ordering is “oneonezero”.

先算多少个1,减去之后看能凑几个零

    #include <bits/stdc++.h>
    #define maxn 100001
    using namespace std;
     
    int main(){
        int l,z=0,e=0,r=0,n=0,o=0;
        char a[maxn];
        scanf("%d",&l);
        scanf("%s",&a);
        for(int i=0;i<l;i++)
        {
            if(a[i]=='z')
                z++;
            else if(a[i]=='e')
                e++;
            else if(a[i]=='r')
                r++;
            else if(a[i]=='o')
                o++;
            else if(a[i]=='n')
                n++;
        }
        int sum1 = min(o,(min(n,e)));
        o -= sum1;
        n -= sum1;
        e -= sum1;
        int sum2 = min(min(z,e),min(r,o));
        for(int i=0;i<sum1;i++)
            printf("1 ");
        for(int i=0;i<sum2;i++)
            printf("0 ");
        return 0;
    }

B. Multiplication Table

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M
with n rows and n columns such that Mij=ai⋅aj where a1,…,anis some sequence of positive integers.

Of course, the girl decided to take it to school with her. But while she was having lunch, hooligan Grisha erased numbers on the main diagonal and threw away the array a1,…,an. Help Sasha restore the array!
Input

The first line contains a single integer n
(3⩽n⩽103), the size of the table.

The next nlines contain n integers each. The j-th number of the i-th line contains the number Mij (1≤Mij≤109). The table has zeroes on the main diagonal, that is, Mii=0

Output

In a single line print nintegers, the original array a1,…,an (1≤ai≤109). It is guaranteed that an answer exists. If there are multiple answers, print any.
Examples
Input

5
0 4 6 2 4
4 0 6 2 4
6 6 0 3 6
2 2 3 0 2
4 4 6 2 0

Output

2 2 3 1 2

Input

3
0 99990000 99970002
99990000 0 99980000
99970002 99980000 0

Output

9999 10000 9998

乘除法互相抵消最后剩下第一个数的平方,然后依次除就得到全部数

    #include <bits/stdc++.h>
    #define maxn 1001
    #define ll long long
    using namespace std;
    ll a[maxn][maxn];
    int main()
    {
        ll l,n;
        cin >> l;
     
        for(int i=1;i<=l;i++)
            for(int j=1;j<=l;j++)
                cin >> a[i][j];
        n = sqrt(a[1][2]*a[1][3]/a[2][3]);
        cout << n << " ";
        for(int i=2;i<=l;i++){
            n = a[i-1][i]/n;
            cout << n << " ";
        }
    	return 0;
    }

C. Substring Game in the Lesson

time limit per test
2 seconds
memory limit per test
256 mebibytes
input
standard input
output
standard output

Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string s
and a number k (0≤k<|s|).

At the beginning of the game, players are given a substring of s with left border l and right border r, both equal to k (i.e. initially l=r=k). Then players start to make moves one by one, according to the following rules:

A player chooses l′and r′ so that l′≤l, r′≥r and s[l′,r′] is lexicographically less than s[l,r]. Then the player changes l and r in this way: l:=l′, r:=r′    .
Ann moves first.
The player, that can't make a move loses.

Recall that a substring s[l,r]
(l≤r) of a string s is a continuous segment of letters from s that starts at position l and ends at position r. For example, “ehn” is a substring (s[3,5]) of “aaaehnsvz” and “ahz” is not.

Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn’t scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only sand k.

Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes sand determines the winner for all possible k.

Input

The first line of the input contains a single string s
(1≤|s|≤5⋅105) consisting of lowercase English letters.
Output

Print |s|lines.

In the line iwrite the name of the winner (print Mike or Ann) in the game with string s and k=i, if both play optimally
Examples
Input

abba

Output

Mike
Ann
Ann
Mike

Input

cba

Output

Mike
Mike
Mike

观察一下就能发现第一个必定是Mike,倒序排列也是Mike,所以从第二个字符开始,每个字符之前有比它小的字符,就是Ann



    #include <bits/stdc++.h>
    #define maxn 1001
    #define ll long long
    using namespace std;
    int main()
    {
        char a[500001];
        scanf("%s",&a);
        int l = strlen(a);
        printf("Mike\n");
        char b = a[0];
        if(l>1)
        {
            for(int i=1;i<l;i++)
            {
                    if(a[i]<=b){
                        printf("Mike\n");
                        b = a[i];
                    }
                    else
                        printf("Ann\n");
            }
        }
     
    }

D. Alex and Julian

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Boy Dima gave Julian a birthday present - set Bconsisting of positive integers. However, he didn’t know, that Julian hates sets, but enjoys bipartite graphs more than anything else!

Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such way: let all integer numbers be vertices, then connect any two i
and j with an edge if |i−j| belongs to B.

Unfortunately, Julian doesn’t like the graph, that was built using B
. Alex decided to rectify the situation, so he wants to erase some numbers form B, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from Bso that graph constructed on the new set is bipartite.

Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
Input

First line contains an integer n (1⩽n⩽200000) — size of B

Second line contains nintegers b1,b2,…,bn (1⩽bi⩽1018) — numbers of B, all biare unique
Output

In first line print single integer k– number of erased elements. In second line print kintegers – values of erased elements.

If there are multiple answers, print any of them.
Examples
Input

3
1 2 3

Output

1
2

Input

2
2 6

Output

0

去掉翻倍的数,标记找出所需去掉的最小个数

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    int l,num[64],vis[200002];
    ll a[200002];
    scanf("%d",&l);
    for(int i=1;i<=l;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=l;i++)
    {
        ll b=a[i];
        while(b&&b%2==0)
        {
            vis[i]++;
            b/=2;
        }
        num[vis[i]]++;
    }
    int id=0;
    for(int i=1;i<=63;i++)
        if(num[i]>num[id])
            id=i;
    printf("%d\n",l-num[id]);
    for(int i=1;i<=l;i++)
        if(vis[i]!=id)
            printf("%lld ",a[i]);
    return 0;
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值