首页 > 其他分享 >C、Grid game 【 Codeforces Round #534 (Div. 2) 】

C、Grid game 【 Codeforces Round #534 (Div. 2) 】

时间:2023-02-14 13:37:29浏览次数:45  
标签:int else Codeforces len st game 534 printf include

C、Grid game

题意:给你一个4 × 4 的方格,然后给你一些1 × 2 或者 2 × 1的小方格,当这些方格在一行或者一列的时候会消除掉,问最佳放置位置。

思路:QAQ,什么时候思维会变强一些。选定一些地方,只放这几个地方就可以了。两个 flag ,分别是放置行和列的标记,如果没放之前,假设先来到是竖的, 所以先放到上面位置 [ 1 ,  4 ],如果再来一个竖的,那么就可以放到下面消掉了,即位置是 [ 3, 4 ]。如果来的不是竖的,而是横的,我们可以放到 [ 4 , 1 ] 或者 [ 4 , 3 ],为了防止后来的第三个可能是竖的,如果放在 [ 4 , 3 ] 没法消掉,所以先放到前面就可以避免了。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

char s[2000];

int main()
{
    while(~scanf("%s", s))
    {
        int len = strlen(s);
        bool h,l;
        h = false;
        l = false;
        for(int i = 0; i < len; i ++)
        {
            if(s[i] == '0')
            {
                if(l)
                {
                    printf("3 4\n");
                    l = false;
                }
                else
                {
                    printf("1 4\n");
                    l = true;
                }
            }
            else if(s[i] == '1')
            {
                if(h)
                {
                    printf("4 3\n");
                    h = false;
                }
                else
                {
                    printf("4 1\n");
                    h = true;
                }
            }
        }
    }
    return 0;
}

B、 Game with string

栈模拟。

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

char s[200000];

int main()
{
    while(~scanf("%s", s)){
       int i = 0;
       int j = 1;
       int pos = 1;
       bool flag = false;
        int len = strlen(s);
       stack<char>st;
        while(1){
            flag = false;
            for(i = 0 ; i < len; i ++){
                if(st.empty()){
                    st.push(s[i]);
                }
                else {
                    if(s[i] == st.top()){
                        pos = -pos;
                        st.pop();
                        flag = true;
                    }
                    else {
                        st.push(s[i]);
                    }
                }
            }
            for(len = 0;!st.empty(); len ++){
                s[len] = st.top();
                st.pop();
            }
            if(!flag) break;
        }
        if(pos == 1)printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

A. Splitting into digits

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int n;
    while(scanf("%d", &n) != EOF){
      printf("%d\n",n);
      for(int i = 0; i < n - 1; i ++)printf("1 ");
      printf("1\n");
    }
    return 0;
}

标签:int,else,Codeforces,len,st,game,534,printf,include
From: https://blog.51cto.com/u_15965659/6056705

相关文章

  • Fire Game (FZU 2150)(BFS)
    题解:一开始想错了,以为只要烧完就是那个答案,但是这不是最优的结果,需要每两个点都bfs一遍,找到如果能够全部烧完,找到花费时间最小的,如果不能return-1。在bfs的时候,记录答案......
  • Codeforces Round #442 (Div. 2)E. Danil and a Part-time Job 线段树+lazytag
    题意:一颗有根树,树上每一个节点有一个灯,要支持两种操作第一种操作是统计一颗子树内开着的灯个数。第二种操作是将一个子树内的所有灯状态改变(开灯->关灯,关灯->开灯)。解......
  • Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 c
    FSouvenirs将询问离线,对原数组离散化,然后用权值线段树维护区间对应权值最大值,\(a_i\)的权值为\(i\),再用树状数组维护区间两数绝对值差的最小值。复杂度为\(\mathcal{......
  • 使用精灵组对精灵成员编队 pygame 230213
    定义精灵成员定义了两个精灵成员说明:Background类是精灵类的子类定义精灵组精灵组添加精灵语法:精灵组.add(精灵成员)批量更新数据语法:精灵组.update()说明:目的是让所有的精灵......
  • Codeforces Round #852 (Div. 2)(C,D)
    CodeforcesRound#852(Div.2)(C,D)B这个题大意是给你一个\(x\),\(y\),\(x\)是极大值(\(a_i>a_{i+1},a_i>a_{i+1}\))的和,\(y\)是极小值(\(a_i<a_{i+1},a_i<a_{i+1}\))的......
  • Codeforces Round #852 (Div. 2)
    F.Rebrending题目抽象为现有长度为\(n\)的数组\(a_1,a_2,\cdots,a_n\),\(m\)次询问,每次询问\(\min\limits_{l\lei,j\ler,i\neqj}|a_i-a_j|\)\((1\lel<r\len)......
  • #0033. Educational Codeforces Round 3
    609A贪心优先选大的USBflashdrive609B先处理每个genre的书有多少本,然后直接枚举每次购买的是哪两种genre然后乘法原理即刻609C手下考虑balanced的长啥样。假设这n......
  • #0032. Educational Codeforces Round 2
    600A简单题但有个坑点在于会有空字符串600B一道可以用来实验upper_bound的题600C挺有趣的一道题。首先考虑怎样的字符串可以通过permutation变成palindrome:条件是至......
  • Codeforces Round #852 (Div. 2)
    A.YetAnotherPromotion题意:买土豆,一种卖a元一公斤,买m公斤送一公斤;一种卖b元一公斤。求买n公斤土豆最少花多少钱。解:完全没有思考,把a*n,b*n,买尽可能多m倍数的土豆剩......
  • Codeforces Round #851 (Div. 2)-F. XOR, Tree, and Queries-树、异或、并查集
    题目:https://codeforces.com/contest/1788/problem/F题解:(首先他和线性基没什么瓜系)想这个问题大概可以分成几个部分:1、很自然地考虑记\(p_x\)表示从根节点走到x路径......