0717-ZCMU暑期训练4(codeforse)

题目地址:https://vjudge.net/contest/311774#overview

目录:(目前还有M,K没有补)
| | 25 / 28 | A | Vus the Cossack and a Contest |
| | 8 / 21 | B | Tokitsukaze and Mahjong |
| | 10 / 33 | C | Tokitsukaze and Discard Items |
| | 22 / 31 | D | Tokitsukaze and Enhancement |
| | 7 / 20 | E | Vus the Cossack and Strings |
| | 13 / 35 | F | Vus the Cossack and Numbers |
| | 23 / 29 | G | Alex and a Rhombus |
| | 7 / 19 | H | Nick and Array |
| | 1 / 1 | I | Valeriy and Deque |
| | 6 / 18 | J | Lose it! |
| | 1 / 1 | K | Recover it! |
| | 21 / 35 | L | Filling Shapes |
| | 1 / 1 | M | Cover it! |

老师说,这是专门为我们这些菜鸡准备的题目,哲神说题目每题都可以写,反正都是从codesforse找的经典题目,但是写的时候发现并不是这样,很多时候自己的思维开拓不了,甚至很多时候莫名其妙连正常的输入输出都做不到,看着18的学弟们个个厉害的一批,过题快的一批,我的内心如下图:



所以话不多说开始补题:

A - Vus the Cossack and a Contest

Vus the Cossack holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and knotebooks.

Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.

Input

The first line contains three integers nn, mm, and kk (1≤n,m,k≤1001≤n,m,k≤100) — the number of participants, the number of pens, and the number of notebooks respectively

Output

Print "Yes" if it possible to reward all the participants. Otherwise, print "No".

You can print each letter in any case (upper or lower).

Examples

Input
5 8 6
Output
Yes
Input
3 9 3
Output
Yes
Input
8 5 20
Output
No

Note:
In the first example, there are 55 participants. The Cossack has 88 pens and 66 notebooks. Therefore, he has enough pens and notebooks.

In the second example, there are 33 participants. The Cossack has 99 pens and 33 notebooks. He has more than enough pens but only the minimum needed number of notebooks.

In the third example, there are 88 participants but only 55 pens. Since the Cossack does not have enough pens, the answer is "No".

思路:https://blog.csdn.net/king9666/article/details/94043780,
只要a比b,c都小就可以了,没想到啊没想到

AC代码:

#include
int main()
{
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);
    if(b >= a && c >= a)
    {
        printf("Yes\n");
    }
    else
        printf("No\n");

    return 0;
}
B - Tokitsukaze and Mahjong

Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 11 to 99). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, ……, 9m, 1p, 2p, ……, 9p, 1s, 2s, ……, 9s.

In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.

Do you know the minimum number of extra suited tiles she needs to draw so that she can win?

Here are some useful definitions in this game:

  • A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
  • A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
  • A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.

Some examples:

  • [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;
  • [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
  • [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.

输入:
The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 11 to 99 and the second character is m, p or s.
输出:
Print a single integer — the minimum number of extra suited tiles she needs to draw.
样例:

Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1

Note
In the first example, Tokitsukaze already has a shuntsu.

In the second example, Tokitsukaze already has a koutsu.

In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].

参考:https://www.cnblogs.com/xwl3109377858/p/11182117.html:题目首先告诉我们赢得方式有两种,
一种是三个牌相同,也就是koutsu,见样例2;另外一种方式是顺子,也就是shuntsu,见样例1。
然后是问给三个牌给我们,问最多还要凑几张牌能赢。
方法:暴力枚举

AC代码:

#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205
const int maxn = 1e5+5;

struct node{
    char dan;
    int data;
}a[maxn];
bool cmp(node x,node y){
    return x.data

C - Tokitsukaze and Discard Items

Recently, Tokitsukaze found an interesting game. Tokitsukaze had nn items at the beginning of this game. However, she thought there were too many items, so now she wants to discard mm (1≤m≤n1≤m≤n) special items of them.

These nn items are marked with indices from 11 to nn. In the beginning, the item with index ii is placed on the ii-th position. Items are divided into several pages orderly, such that each page contains exactly kk positions and the last positions on the last page may be left empty.

Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.



Consider the first example from the statement: n=10n=10, m=4m=4, k=5k=5, p=[3,5,7,10]p=[3,5,7,10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 33 and 55. After, the first page remains to be special. It contains [1,2,4,6,7][1,2,4,6,7], Tokitsukaze discards the special item with index 77. After, the second page is special (since it is the first page containing a special item). It contains [9,10][9,10], Tokitsukaze discards the special item with index 1010.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers nn, mm and kk (1≤n≤10181≤n≤1018, 1≤m≤1051≤m≤105, 1≤m,k≤n1≤m,k≤n) — the number of items, the number of special items to be discarded and the number of positions in each page.

The second line contains mm distinct integers p1,p2,…,pmp1,p2,…,pm (1≤p1 Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples

Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1

Note

For the first example:

  • In the first operation, Tokitsukaze would focus on the first page [1,2,3,4,5][1,2,3,4,5] and discard items with indices 33 and 55;
  • In the second operation, Tokitsukaze would focus on the first page [1,2,4,6,7][1,2,4,6,7] and discard item with index 77;
  • In the third operation, Tokitsukaze would focus on the second page [9,10][9,10] and discard item with index 1010.
    For the second example, Tokitsukaze would focus on the second page [6,7,8,9,10][6,7,8,9,10] and discard all special items at once.

参考:https://blog.csdn.net/frostmonarch/article/details/95927605
法1:https://blog.csdn.net/qq_43569119/article/details/95923687

#include
#include
#include
#include
#include
#include
using namespace std;
#define rep(i,a,n) for(int i=a;i
#define PLL pair
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205

const int maxn = 1e5+5;
ll n,m,k,i,j;
ll a[maxn];
int main(){
    scanf("%lld%lld%lld",&n,&m,&k);
    LL pre = 1,ans = 1,nn = 0;
    for(int i=1;i<=m;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=m;i++)
    {
     //printf("%lld %lld\n",(a[i+1]-nn-1)/k,(a[i]-nn-1)/k);
    if((a[i+1]-nn-1)/k>(a[i]-nn-1)/k){
        ans++;
        nn = i;
        }
    }


    printf("%lld\n",ans);
    return 0;

}

法2:

#include
#include
#include
#include
#include
#include
using namespace std;
#define rep(i,a,n) for(int i=a;i
#define PLL pair
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205

const int maxn = 1e5+5;
ll n,m,k,i,j;
ll a[maxn];
int main(){
    scanf("%lld%lld%lld",&n,&m,&k);
    LL pre = 1,ans = 1,nn = 0;
    for(int i=1;i<=m;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=m;i++)
    {
     //printf("%lld %lld\n",(a[i+1]-nn-1)/k,(a[i]-nn-1)/k);
    if((a[i+1]-nn-1)/k>(a[i]-nn-1)/k){
        ans++;
        nn = i;
        }
    }


    printf("%lld\n",ans);
    return 0;

}
D - Tokitsukaze and Enhancement

Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.

In general, different values of HP are grouped into 44 categories:

Category AA if HP is in the form of (4n+1)(4n+1), that is, when divided by 44, the remainder is 11;
Category BB if HP is in the form of (4n+3)(4n+3), that is, when divided by 44, the remainder is 33;
Category CC if HP is in the form of (4n+2)(4n+2), that is, when divided by 44, the remainder is 22;
Category DD if HP is in the form of 4n4n, that is, when divided by 44, the remainder is 00.
The above-mentioned nn can be any integer.

These 44 categories ordered from highest to lowest as A>B>C>DA>B>C>D, which means category AA is the highest and category DD is the lowest.

While playing the game, players can increase the HP of the character. Now, Tokitsukaze wants you to increase her HP by at most 22 (that is, either by 00, 11 or 22). How much should she increase her HP so that it has the highest possible category?
Input
The only line contains a single integer xx (30≤x≤10030≤x≤100) — the value Tokitsukaze's HP currently.

Output
Print an integer aa (0≤a≤20≤a≤2) and an uppercase letter bb (b∈{A,B,C,D}b∈{A,B,C,D}), representing that the best way is to increase her HP by aa, and then the category becomes bb.

Note that the output characters are case-sensitive.

Examples
Input
33
Output
0 A
Input
98
Output
1 B

Note
For the first example, the category of Tokitsukaze's HP is already A, so you don't need to enhance her ability.

For the second example:
If you don't increase her HP, its value is still 98, which equals to (4×24+2), and its category is C.
If you increase her HP by 1, its value becomes 99, which equals to (4×24+3), and its category becomes B.
If you increase her HP by 2, its value becomes 100, which equals to (4×25), and its category becomes D.
Therefore, the best way is to increase her HP by 1 so that the category of her HP becomes B.

参考:https://www.cnblogs.com/xwl3109377858/p/11182079.html:题目意思是给一个数根据mod 4 的四个结果定义等级,余1等级A,余3等级B,余2等级C,余0等级D。
 问给你一个数,你可以对数加a:0<=a<=2,问这个数能提升到的最高等级和对应的a。
思路:直接讨论四种情况的最优解就好了,例如n mod 4 = 3 时,显然加2就变成 余1为等级A了.....

#include
#include
#include
#include
#include
#include
using namespace std;
#define rep(i,a,n) for(int i=a;i
#define PLL pair
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205

const int maxn = 1e5+5;

int main(){
     ll n,flag;
     char dd[maxn];
     while(~scanf("%lld",&n)){
         int i=0;
         if(n%4==1)printf("0 A\n");
         else if(n%4==2)printf("1 B\n");
         else if(n%4==3)printf("2 A\n");
         else if(n%4==0)printf("1 A\n");

     }
    return 0;
}

E - Vus the Cossack and Strings

Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b|≤|a|, that is, the length of bb is at most the length of a.

The Cossack considers every substring of length |b| in string aa. Let's call this substring cc. He matches the corresponding characters in bb and cc, after which he counts the number of positions where the two strings are different. We call this function f(b,c).

For example, let b=00110, and c=11000. In these strings, the first, second, third and fourth positions are different.

Vus the Cossack counts the number of such substrings cc such that f(b,c) is even.

For example, let a=01100010a=01100010 and b=00110b=00110. aa has four substrings of the length |b||b|: 01100, 11000, 10001, 00010.

f(00110,01100)=2
f(00110,11000)=4
f(00110,10001)=4
f(00110,00010)=1

Since in three substrings, f(b,c) is even, the answer is 3.

Vus can not find the answer for big strings. That is why he is asking you to help him.

Input
The first line contains a binary string aa (1≤|a|≤106) — the first string.

The second line contains a binary string bb (1≤|b|≤|a|) — the second string.
Output
Print one number — the answer.

Examples
Input
01100010
00110
Output
3
Input
1010111110
0110
Output
4

Note
The first example is explained in the legend.

In the second example, there are five substrings that satisfy us: 1010, 0101, 1111, 1111.

参考:
https://www.cnblogs.com/DreamACMer/p/11107034.html:题意:题目给了一个较长字符串a以及一个较短字符串b,在a中取与b长度相等的子串,比较子串与b字符串中有几组字符不一样。
顺带一提,本题4 4的情况,不仅hack掉了基本所有的AC代码,甚至让这场比赛都不算rate。
先科普一下 位运算中的 异或(运算符"^"),在二进制中,如果两个数字相同的话,那么异或的结果就是0,否则就是1;同时两次异或同一个数字,就相当于没有没有异或过这个数字
https://www.cnblogs.com/Kaike/p/11124512.html

#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205
const int maxn = 1e7+100;
char m[maxn],s[maxn];
int sum1[maxn];

int main(){
    scanf("%s",s+1);
    scanf("%s",m+1);
    int ss=strlen(s+1);
    int mm=strlen(m+1);
    int ans=0,sum0=0;
    for(int i=1;i<=ss;i++){
        sum1[i]=sum1[i-1]+s[i]-'0';
    }
    for(int i=1;i<=mm;i++){
        if(m[i]=='1')sum0++;
    }
    
    if(sum0%2==0){
        for(int i=mm;i<=ss;i++)
            if((sum1[i]-sum1[i-mm])%2==0)
                ans++;
    }
    else {
        for(int i=mm;i<=ss;i++)
            if((sum1[i]-sum1[i-mm])%2==1)
                ans++;
    }
     
     printf("%d\n",ans);
    
     
    return 0;    
 }
F - Vus the Cossack and Numbers

Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is nn such that the sum of all numbers is 0 and each bi is either ⌊ai⌋ or ⌈ai⌉. In other words, bibi equals aiai rounded up or down. It is not necessary to round to the nearest integer.

For example, if a=[4.58413,1.22491,−2.10517,−3.70387], then bb can be equal, for example, to [4,2,−2,−4]

Note that if ai is an integer, then there is no difference between ⌊ai⌋ and ⌈ai⌉, bi will always be equal to ai

Help Vus the Cossack find such sequence!
nput
The first line contains one integer nn (1≤n≤1051≤n≤105) — the number of numbers.

Each of the next nn lines contains one real number aiai (|ai|<105|ai|<105). It is guaranteed that each aiai has exactly 55 digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to 00.
Output
In each of the next nn lines, print one integer bibi. For each ii, |ai−bi|<1|ai−bi|<1 must be met.

If there are multiple answers, print any.

Examples

Input
4
4.58413
1.22491
-2.10517
-3.70387
Output
4
2
-2
-4

Input
5
-6.32509
3.30066
-0.93878
2.00000
1.96321
Output
-6
3
-1
2
2

Note
The first example is explained in the legend.

In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.

参考:
https://www.cnblogs.com/Msmw/p/11113492.html:对于每个a[i]下取整,然后再把它的小数不和取和,那么求和是正的就需要补正的,求和是负的就需要补充负的。这个题是要注意浮点数运算精度问题,用eps卡下一下精度,eps取1e-8就可以。还有下取整上取整函数取到的数还是浮点数。
https://blog.csdn.net/swustlpf/article/details/94150892:最主要的思想就是先取整,比如先都向下取整,然后把所有的舍掉的小数都加起来为sum,而sum一定是整数,然后就看sum是正的还是负的,多退少补,而且要满足多退少补后绝对值还是小于1就行了

#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205
const int maxn = 1e5+5;
double a[maxn];
int b[maxn];
int main(){
    int n;scanf("%d",&n);
    double sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lf",&a[i]);
        b[i]=floor(a[i]);
        sum+=a[i]-b[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(fabs(a[i]-b[i])eps)
        {
            if(sum>0) 
            {
                sum--;
                printf("%d\n",b[i]+1);
            }
            else
            {
                sum++;
                printf("%d\n",b[i]-1);
            }
        }
        else printf("%d\n",b[i]);
    }
    return 0;    
 }

G - Alex and a Rhombus

While playing with geometric figures Alex has accidentally invented a concept of a nn-th order rhombus in a cell grid.

A 1-st order rhombus is just a square 1×1 (i.e just a cell).

A n-th order rhombus for all n≥2 one obtains from a n−1-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).



Input
The first and only input line contains integer nn (1≤n≤1001≤n≤100) — order of a rhombus whose numbers of cells should be computed.

Output
Print exactly one integer — the number of cells in a nn-th order rhombus.
Examples

Input
1
Output
1
Input
2
Output
5
Input
3
Output
13

Note
Images of rhombus corresponding to the examples are given in the statement.

参考:https://www.cnblogs.com/Vampire6/p/11106869.html:题意:求第N个图形的小方格个数
思路:找规律题:
1+3+5+7+..+5+3+1

#include
#include
#include
#include
#include
#include
using namespace std;
#define rep(i,a,n) for(int i=a;i
#define PLL pair
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205

const int maxn = 1e5+5;
int main(){
     ll n;
     while(~scanf("%lld",&n)){
            ll a[maxn];
            a[0]=1;
            for(int i=1;i<205;i++)
            {
                a[i]=a[i-1]+2;
            }
            if(n==1)
               printf("1\n");
            else if(n==2)
                printf("5\n");
            else{
                ll sum=0;
                for (int i=0;i<=n-2;i++)
                {
                    sum+=a[i];
                }
                printf("%lld\n",2*sum+a[n-1]);
            }
        }
    return 0;
}

H - Nick and Array

Nick had received an awesome array of integers a=[a1,a2,…,an]a=[a1,a2,…,an] as a gift for his 55 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a1⋅a2⋅…ana1⋅a2⋅…an of its elements seemed to him not large enough.

He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index ii (1≤i≤n1≤i≤n) and do ai:=−ai−1ai:=−ai−1.

For example, he can change array [3,−1,−4,1][3,−1,−4,1] to an array [−4,−1,3,1][−4,−1,3,1] after applying this operation to elements with indices i=1i=1 and i=3i=3.

Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index.

Help Kolya and print the array with the maximal possible product of elements a1⋅a2⋅…ana1⋅a2⋅…an which can be received using only this operation in some order.

If there are multiple answers, print any of them.
Input
The first line contains integer nn (1≤n≤1051≤n≤105) — number of integers in the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (−106≤ai≤106−106≤ai≤106) — elements of the array
Output
Print nn numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array.

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

Input
4
2 2 2 2
Output
-3 -3 -3 -3
Input
1
0
Output
0
Input
3
-3 -3 2
Output
-3 -3 2

参考:
https://blog.csdn.net/weixin_44694282/article/details/93408599:给你一个数组,每一个数都可以通过给定的公式(a[i] = -a[i]-1)变成另外一个值,让你求所有可能的数组中,数组的所有值乘积最大的那个数组
思路:
每个数都可以变成负数和非负数,并且负数的绝对值比非负数的绝对值大,因此我们可以把所有的负数转换成非负数,然后从小到大排序(一定要从小到大排序,可以试一下这组样例 3 2 2 1 0),然后把尽可能多的偶数个非负数转换成负数,如果最后剩下一个,直接输出就行,因为上边已经全部转换成非负数了
https://www.cnblogs.com/xwl3109377858/p/11070253.html:题目意思是给你n个数,你可以对任何一个数进行操作:num=-num-1,让你输出经过操作之后,n个数乘积最大的一个序列
思路:
显然如果是正数或0,经过操作后变负数,绝对值加一,既然是绝对值增加,那么我们应该把这些数都变成负数,
那么乘积的绝对值才是最大的,但是显然乘积不能为负,那么我们就要对n判断一下,如果n是偶数,乘积为正值,就ok了;
如果n是奇数,那就要在n个数里面找一个负数绝对值最大的,操作后变正,则乘积变为正数最大值......

#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205
const int maxn = 1e7+100;

//int sum1[maxn];
struct node
{
    int x;
    int d;
} a[maxn];

int cmp1(struct node a,struct node b)
{
    return a.x>n)
    {
        int i;
        for(i=0;i

L - Filling Shapes

You have a given integer nn. Find the number of ways to fill all 3×n3×n tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap.



This picture describes when n=4n=4. The left one is the shape and the right one is 3×n3×n tiles.
Input
The only line contains one integer nn (1≤n≤60) — the length.

Output
Print the number of ways to fill.

Examples
Input
4
Output
4
Input
1
Output
0

Note
In the first example, there are 4 possible cases of filling.
In the second example, you cannot fill the shapes in 3×1 tiles.

参考:https://blog.csdn.net/chen_zan_yu_/article/details/93067393:

#include
#include
#include
#include
#include
#include
using namespace std;
#define rep(i,a,n) for(int i=a;i
#define PLL pair
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205

const int maxn = 1e5+5;

int main(){
     int n,flag;
     char dd[maxn];
     scanf("%d",&n);
         if(n%2==0)printf("%d\n",(int)pow(2.0,n/2.0));
         else printf("0\n");

    return 0;
}
I - Valeriy and Deque

Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with nn elements. The ii-th element is aiai (ii = 1,2,…,n1,2,…,n). He gradually takes the first two leftmost elements from the deque (let's call them AA and BB, respectively), and then does the following: if A>BA>B, he writes AA to the beginning and writes BB to the end of the deque, otherwise, he writes to the beginning BB, and AA writes to the end of the deque. We call this sequence of actions an operation.

For example, if deque was [2,3,4,5,1][2,3,4,5,1], on the operation he will write B=3B=3 to the beginning and A=2A=2 to the end, so he will get [3,4,5,1,2][3,4,5,1,2].

The teacher of the course, seeing Valeriy, who was passionate about his work, approached him and gave him qq queries. Each query consists of the singular number mjmj (j=1,2,…,q). It is required for each query to answer which two elements he will pull out on the mjmj-th operation.

Note that the queries are independent and for each query the numbers AA and BB should be printed in the order in which they will be pulled out of the deque.

Deque is a data structure representing a list of elements where insertion of new elements or deletion of existing elements can be made from both sides.
Input
The first line contains two integers nn and qq (2≤n≤105, 0≤q≤3⋅105) — the number of elements in the deque and the number of queries. The second line contains nn integers a1a1, a2a2, ..., anan, where aiai (0≤ai≤109) — the deque element in ii-th position. The next qq lines contain one number each, meaning mjmj (1≤mj≤1018).
Output
For each teacher's query, output two numbers AA and BB — the numbers that Valeriy pulls out of the deque for the mjmj-th operation.

Examples
Input
5 3
1 2 3 4 5
1
2
10
Output
1 2
2 3
5 2
Input
2 0
0 0
Output

Note
Consider all 10 steps for the first test in detail:
[1,2,3,4,5] — on the first operation, A and B are 1 and 2, respectively.
So, 22 we write to the beginning of the deque, and 1 — to the end.

We get the following status of the deque: [2,3,4,5,1]

[2,3,4,5,1]⇒A=2,B=3
[3,4,5,1,2]
[4,5,1,2,3]
[5,1,2,3,4]
[5,2,3,4,1]
[5,3,4,1,2]
[5,4,1,2,3]
[5,1,2,3,4]
[5,2,3,4,1]⇒A=5,B=2

思路:双端队列
https://blog.csdn.net/weixin_44694282/article/details/93478997

#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int maxn = 3e5+10;
int b[maxn],a[maxn];//队首不为最大值是队列的前两项
int c[maxn];// 队首为最大值时队列的第二项

int main()
{
    int n,p;
    while(~scanf("%d%d",&n,&p))
    {
        int i;
        dequeq;//双端队列
        int Max=0; 
        
        // 
        for(int i=0;iMax)Max=x;//寻找最大值 
        } 
        //i=0;
        i=0;
        
        //
        while(1){
            int x=q.front();
            
            if(x==Max) break;
            
            q.pop_front();
            int y=q.front();
            q.pop_front(); 
            a[++i]=x;
            b[i]=y;
            
            if(x>y){//大数放头小放尾 
                q.push_front(x);
                q.push_back(y);
            }
            else {
                q.push_front(y);
                q.push_back(x);
            }
        }
        int u=i;//
        
        q.pop_front();//队首最大值弹出 
        //i=1;
        i=1;
        while(!q.empty()){//换位置 
            c[i]=q.front();//将n-1次循环存入数组 
            q.pop_front();
            i++;
        }
        c[0]=c[i-1];//( 循环次数-u)%(n-1)=0的时候应该输出下标为0的一项。
        //输出 
        while(p--){
            ll t;
            scanf("%lld",&t); 
            if(t>u){
                t=(t-u)%(n-1);//
                printf("%d %d\n",Max,c[t]);
            }
            else {
                printf("%d %d\n",a[t],b[t]);
            }
        }   
    }
    return 0;
}

J - Lose it!

You are given an array aa consisting of nn integers. Each aiai is one of the six following numbers: 4,8,15,16,23,424,8,15,16,23,42.

Your task is to remove the minimum number of elements to make this array good.

An array of length kk is called good if kk is divisible by 66 and it is possible to split it into k6k6 subsequences 4,8,15,16,23,424,8,15,16,23,42.

Examples of good arrays:

[4,8,15,16,23,42](the whole array is a required sequence);
[4,8,4,15,16,8,23,15,16,42,23,42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);
[][] (the empty array is good).
Examples of bad arrays:

[4,8,15,16,42,23] (the order of elements should be exactly 4,8,15,16,23,424,8,15,16,23,42);
[4,8,15,16,23,42,4] (the length of the array is not divisible by 66);
[4,8,15,16,23,42,4,8,15,16,23,23](the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).

参考:https://blog.csdn.net/weixin_44231195/article/details/91391936

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define dd double
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    ll t;
    cin >> t;
    while (t--) {
        ll n; cin >> n;
        ll sum = 0;
        ll flag = 0;
        while (n != 1) {
            if (n % 2 == 0) {
                n = n / 2;
                sum++;
            }
            else if(n % 3 == 0 && n % 5 == 0) {
                n = min(((n / 3) * 2),((n / 5) * 4));
                sum++;
            }
            else if (n % 3 == 0) {
                n = n / 3 * 2;
                sum++;
            }
            else if (n % 5 == 0) {
                n = n / 5 * 4;
                sum++;
            }
            else {
                flag = 1;
                cout << "-1" << endl;
                break;
            }
        }
        if (flag == 0) {
            cout << sum << endl;
        }
    }
}

参考2:https://blog.csdn.net/weixin_44694282/article/details/93527416:
题意:题目把 [4,8,15,16,23,42] 定义为一个好的子序列,然后给你一个数组,你可以对数组进行无数次操作(删除一个元素),
问你最少操作多少次,可以将该数组变成好的序列(只要保证序列里的每个 [4,8,15,16,23,42] 序列的顺序就行了,相互之间可以交叉)
可以先找有多少个这样的子序列,最后n-子序列的个数*6就可以了

#include
#include
#include
#include
using namespace std;
const int maxx = 5e5+10;
int a[maxx];

int main()
{
    int n;
    while(cin>>n)
    {
        int i;
        for(i=0; is2)    //只有4出现的个数大于8出现的个数时s2才能++
                s2++;
            else if(a[i]==15&&s2>s3)  
                s3++;
            else if(a[i]==16&&s3>s4)
                s4++;
            else if(a[i]==23&&s4>s5)
                s5++;
            else if(a[i]==42&&s5>s6)
                s6++;
            if(s1&&s2&&s3&&s4&&s5&&s6)
            {
                s1--;
                s2--;
                s3--;
                s4--;
                s5--;
                s6--;
                count++;
            }
        }
        printf("%d\n",n-count*6);
    }
    return 0;
}

你可能感兴趣的:(0717-ZCMU暑期训练4(codeforse))