Codeforces-C-Grid game(思维)
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time independently). You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time.
Input
The only line contains a string ss consisting of zeroes and ones (1≤|s|≤10001≤|s|≤1000). Zero describes vertical tile, one describes horizontal tile.
Output
Output |s||s| lines — for each tile you should output two positive integers r,cr,c, not exceeding 44, representing numbers of smallest row and column intersecting with it.
If there exist multiple solutions, print any of them.
Example
input
Copy
010
output
Copy
1 1
1 2
1 4
Note
Following image illustrates the example after placing all three tiles:
Then the first row is deleted:
思路:我们可以建立两个数组,如果是0我们就把它放在第一列的两个位置,满了就消去,如果是1我们就放在最右边两列,满了就消去
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string str;
int main()
{
int a[2][2]={1,1,3,1};
int b[4][2]={1,3,2,3,3,3,4,3};
cin>>str;
int len=str.length();
int s1=0;
int s2=0;
for(int t=0;t<len;t++)
{
if(str[t]=='0')
{
cout<<a[s1][0]<<" "<<a[s1][1]<<endl;
s1++;
}
if(str[t]=='1')
{
cout<<b[s2][0]<<" "<<b[s2][1]<<endl;
s2++;
}
if(s1==2)
{
s1=0;
}
if(s2==4)
{
s2=0;
}
}
return 0;
}
Codeforces-C-Grid game(思维)的更多相关文章
- C. Grid game 思维+问题转化
C. Grid game 思维+问题转化 题意 每当有一行或者一列方格的时候,都可以消气这一行或者这一列,一共有两种形状的方块,一种是横的两个,一种是竖着的两个,按时间顺序放在4*4的格子里面,问怎么 ...
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- CF--思维练习-- CodeForces - 215C - Crosses(思维题)
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- Mike and distribution CodeForces - 798D (贪心+思维)
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- Maximal GCD CodeForces - 803C (数论+思维优化)
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 如何在Eclipse下查看JDK源代码以及java源代码阅读方法(转载)
不会看JDK源代码,相当于没学过Java. 网上不容易找到一篇帮助我解决了如何在Eclipse下查看JDK源代码 的文章. 核心提示:在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 w ...
- spring-初始化bean
@EnableScheduling@Servicepublic class BaseTask implements InitializingBean, ApplicationContextAware{ ...
- .Net时间运算 - DateTime类,TimeSpan类
DateTime类是.Net中用于处理时间类型数据的. 一.字段 MaxValue 表示 DateTime 的最大可能值.此字段为只读. MinValue 表示 DateTime 的最小可能值 ...
- PHP通过加锁实现并发情况下抢码功能
本文基于php语言使用加锁实现并发情况下抢码功能,特定时间段开放抢码并不允许开放的码重复: 需求:抢码功能 要求: 1.特定时间段才开放抢码: 2.每个时间段放开的码是有限的: 3.每个码不允许重复: ...
- [Elasticsearch2.x] 多字段搜索 (一) - 多个及单个查询字符串 <译>
多字段搜索(Multifield Search) 本文翻译自官方指南的Multifield Search一章. 查询很少是只拥有一个match查询子句的查询.我们经常需要对一个或者多个字段使用相同或者 ...
- 【总结整理】WebGIS基础
1.万维网:www是world wide web的简称是在超文本基础上形成的信息网 2.互联网:即广域局域网及单机按照一定的通讯协议组成的国际计算机网络 3.WebGIS:网络地理信息系统,指基于In ...
- 列表控件JList的使用
--------------siwuxie095 工程名:TestUI 包名:com.siwuxie095.ui 类名:TestList.jav ...
- SQl Server Tsql基本编程 ,循环语句 ,存储过程
一些比较重要但是不一定经常用的 句子 Tsql定义变量 declare @a int : 定义的变量前面必须用@,数据类型是SQL里的数据类型,执行的时候要把需要的有关联的代码一起执行,单独执行一条 ...
- 算法Sedgewick第四版-第1章基础-002一些工具类算法(Euclid’s algorithm)
1. //Euclid’s algorithm public static int gcd(int p, int q) { if (q == 0) return p; int r = p % q; r ...
- CF438D The Child and Sequence
外国人的数据结构题真耿直 唯一有难度的操作就是区间取模,然而这个东西可以暴力弄一下,因为一个数$x$被取模不会超过$logn$次. 证明如下(假设$x Mod y$): 如果$y \leq \fr ...