Cf教育场73 Educational Codeforces Round 73 (Rated for Div. 2)

Cf教育场73 Educational Codeforces Round 73 (Rated for Div. 2)

A. 2048 Game
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.

You may perform any number (possibly, zero) operations with this multiset.

During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.

For example, if s={1,2,1,1,4,2,2} and you choose integers 2 and 2, then the multiset becomes {1,1,1,4,4,2}.

You win if the number 2048 belongs to your multiset. For example, if s={1024,512,512,4} you can win as follows: choose 512 and 512, your multiset turns into {1024,1024,4}. Then choose 1024 and 1024, your multiset turns into {2048,4} and you win.

You have to determine if you can win this game.

You have to answer q independent queries.

Input
The first line contains one integer q (1≤q≤100) – the number of queries.

The first line of each query contains one integer n (1≤n≤100) — the number of elements in multiset.

The second line of each query contains n integers s1,s2,…,sn (1≤si≤229) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.

Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

就是给你一系列的数,然后同样的数可以合并起来变成它的2倍;但是!!我模拟的时候看不懂题意,看漏了它全部是2的幂次数。这道题很好做,就是把小于2048的数加起来,看看有没有大于2048就可以了。

#include<bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define pi 3.1415926535898
#define ll long long
#define inf 0x3f3f3f3f
#define infmax 0x3f3f3f3f3f3f3f3f
using namespace std;
int a[2060];
int main(void)
{
    int t;cin>>t;
    int n;
    while(t--){
        cin>>n;
        memset(a,0,sizeof a);
        int k;
        a[0]=1;
        queue<int> q;
        for(int i=1;i<=n;i++){
            cin>>k;
            for(int i=0;i<2048;i++){
                if(i+k<=2048){
                    if(a[i]==1) {
                        q.push(i+k);
                        //cout<<"i  "<<i<<endl;
                    }
                    //cout<<i+k<<endl;
                }
                else{
                    break;
                }
            }
            while(!q.empty()){
                a[q.front()]=1;
                q.pop();
            }
        }
        //for(int i=0;i<=2048;i++) if(a[i]==1) cout<<"ia  "<<i<<endl;
        if(a[2048]==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

B. Knights
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.

A knight is a chess piece that can attack a piece in cell (x2, y2) from the cell (x1, y1) if one of the following conditions is met:

|x1−x2|=2 and |y1−y2|=1, or
|x1−x2|=1 and |y1−y2|=2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
在这里插入图片描述
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.

Input
The first line contains one integer n (3≤n≤100) — the number of rows (and columns) in the board.

Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.

案例永远是最坑的,以为像某一道可以全部用案例输出的题一样,第一发就很自信的wa了,难受啊。马走日嘛,就可以一个间隔一个的放白和黑。巧妙的放法。
当然,组员的思路是搜索,也ac了

#include<bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define pi 3.1415926535898
#define ll long long
#define inf 0x3f3f3f3f
#define infmax 0x3f3f3f3f3f3f3f3f
using namespace std;
 
int main(void)
{
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
           if((i+j)&1)
                cout<<"B";
            else cout<<"W";
        }
        cout<<endl;
    }
    return 0;
}

C. Perfect Team
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can’t have both at the same time.

So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.

You are a coach at a very large university and you know that c of your students are coders, m are mathematicians and x have no specialization.

What is the maximum number of full perfect teams you can distribute them into?

Note that some students can be left without a team and each student can be a part of no more than one team.

You are also asked to answer q independent queries.

Input
The first line contains a single integer q (1≤q≤104) — the number of queries.

Each of the next q lines contains three integers c, m and x (0≤c,m,x≤108) — the number of coders, mathematicians and students without any specialization in the university, respectively.

Note that the no student is both coder and mathematician at the same time.

Output
Print q integers — the i-th of them should be the answer to the i query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.

一个acm团队至少一个数学和一个码农嘛。

#include<bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define pi 3.1415926535898
#define ll long long
#define inf 0x3f3f3f3f
#define infmax 0x3f3f3f3f3f3f3f3f
using namespace std;
 
int main(void)
{
    int n;cin>>n;
    int a,b,c;
    while(n--){
        cin>>a>>b>>c;
        cout<<min(min(a,b),(a+b+c)/3)<<endl;
    }
    return 0;
}

D. Make The Fence Great Again
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is ai. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition ai−1≠ai holds.

Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay bi rubles for it. The length of each board can be increased any number of times (possibly, zero).

Calculate the minimum number of rubles you have to spend to make the fence great again!

You have to answer q independent queries.

Input
The first line contains one integer q (1≤q≤3⋅105) — the number of queries.

The first line of each query contains one integers n (1≤n≤3⋅105) — the number of boards in the fence.

The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers ai and bi (1≤ai,bi≤109) — the length of the i-th board and the price for increasing it by 1, respectively.

It is guaranteed that sum of all n over all queries not exceed 3⋅105.

It is guaranteed that answer to each query will not exceed 1018.

Output
For each query print one integer — the minimum number of rubles you have to spend to make the fence great.

左右的数都不相同就是最好的,相等的话可以长根,但是加成本,答案要成本最低。
动归思想,最多只需要长2节,那么就把每一次都长0,1,2节的情况给列出来然后给动归了。

#include<bits/stdc++.h>
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define pi 3.1415926535898
#define ll long long
#define inf 0x3f3f3f3f
#define infmax 0x3f3f3f3f3f3f3f3f
using namespace std;
ll a[300005],b[300005];
ll f[300005][3];//表示第i根长了j后会使i根满足最好。
int main(void)
{
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]);;
        for(int i=1;i<=n;i++)
            for(int j=0;j<3;j++) f[i][j]=infmax;
        f[0][0]=f[0][1]=f[0][2]=0;
        for(int i=1;i<=n;i++){
            for(ll j=0;j<3;j++){
                for(ll k=0;k<3;k++){
                    if(a[i]+j!=a[i-1]+k)
                    f[i][j]=min(f[i][j],f[i-1][k]+j*b[i]);
                }
            }
        }
            ll ans=0;
    ans=min(f[n][0],min(f[n][1],f[n][2]));
    cout<<ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值