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 ...
随机推荐
- 《Android应用性能优化》 第8章 图形
1.例子中 30个部件的xml setContentView 几乎占用了从onCreate() 到 onResume() 结束之前所有时间的99% 因为展开布局的开销很大.要尽量用不同的布局方式.比如 ...
- AudioFormat
AudioFormat 用于访问 一系列语音格式和通道配置常量 例如用于AudioTrack 和AudioRecord中 The AudioFormat class is used to acce ...
- spring整合web项目演示
- IE的haslayout
haslayout 是Windows Internet Explorer渲染引擎的一个内部组成部分.在InternetExplorer中,一个元素要么自己对自身的内容进行计算大小和组织,要么依赖于父元 ...
- ViewPager+Fragment基本使用方法(附源码)
ViewPager+Fragment可以做出多页面滑动效果,让我们的应用程序界面操作起来更加灵活 对于ViewPager和Fragment组件还不熟悉的朋友,可以先看看相关的资料. 首先在activi ...
- HDU 6162 树链剖分
题意:给你一颗树,每个节点有有一个权值,每次询问从x到y的最短路上权值在c到d之间的所有的点的权值和是多少. 思路:肯定要用树剖,因为询问c到d之间这种操作树上倍增很难做,但是用其它数据结构可以比较好 ...
- 基于IFC的施工过程模拟程序(4D BIM)
- PCL—点云滤波(初步处理)
博客转载自:http://www.cnblogs.com/ironstark/p/4991232.html 点云滤波的概念 点云滤波是点云处理的基本步骤,也是进行 high level 三维图像处理之 ...
- 算法Sedgewick第四版-第1章基础-020一按优先级计算表达式的值
/****************************************************************************** * Compilation: javac ...
- Mat表达式
利用C++中的运算符重载,Opencv2中引入了Mat运算表达式.这一新特点使得使用c++进行编程时,就如同写Matlab脚本. 例如: 如果矩阵A和B大小相同,则可以使用如下表达式: C=A+B+1 ...