跳过正文
  1. Posts/

whust 2016 warm up E||codeforces 689 A. Mike and Cellphone (模拟)

·2 分钟

cf689A

思路:一个老式的电话键盘。。。。给出一个拨号的移动路径。。。问这个路径是否唯一。

思路:如果唯一就说明。。。不能平移。。。否则不唯一。。

平移可以上下左右。。所以先写4个常亮数组。。。标记平移后的结果。。。设置不合法位就可以了。。。

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年07月18日 星期一 12时56分28秒
  4File Name :code/2016whust/E.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33
 34const int up[15]={8,-1,-1,-1,1,2,3,4,5,6};
 35const int down[15]={-1,4,5,6,7,8,9,-1,0,-1};
 36const int l[15]={-1,-1,1,2,-1,4,5,-1,7,8};
 37const int r[15]={-1,2,3,-1,5,6,-1,8,9,-1};
 38int n;
 39string st;
 40
 41bool solve()
 42{
 43    bool flag = true;
 44    for ( int i = 0 ; i < n ; i++)
 45    {
 46	int x = st[i]-'0';
 47//	cout<<"x:"<<x<<" x+up[x]"<<x+up[x]<<endl;
 48	x = up[x];
 49	if (x==-1)
 50	{
 51	    flag = false;
 52//	    cout<<"uuuuu"<<endl;
 53	    break;
 54	}
 55    }
 56    if (flag) return true;
 57
 58    flag = true;
 59    for ( int i = 0 ; i < n ; i++)
 60    {
 61	int x = st[i]-'0';
 62	x = down[x];
 63	if (x==-1)
 64	{
 65	    flag = false;
 66//	    cout<<"ddd"<<endl;
 67	    break;
 68	}
 69    }
 70    if (flag) return true;
 71
 72    flag = true;
 73    for ( int i = 0 ; i  < n;  i++)
 74    {
 75	int x = st[i]-'0';
 76	x = l[x];
 77	if (x==-1)
 78	{
 79	    flag = false;
 80//	    cout<<"lll"<<endl;
 81	    break;
 82	}
 83    }
 84
 85    if (flag) return true;
 86    flag = true;
 87
 88    for ( int i =  0 ; i  < n ; i++)
 89    {
 90	int x = st[i]-'0';
 91	x = r[x];
 92	if (x==-1)
 93	{
 94	    flag = false;
 95//	    cout<<"rrr:::"<<endl;
 96	    break;
 97	}
 98    }
 99    if (flag) return  true;
100
101    return false;
102
103
104}
105int main()
106{
107	#ifndef  ONLINE_JUDGE
108	freopen("code/in.txt","r",stdin);
109  #endif
110
111
112	cin>>n;
113	cin>>st;
114	if (!solve())
115	{
116	    puts("YES");
117	}
118	else
119	{
120	    puts("NO");
121	}
122
123
124
125  #ifndef ONLINE_JUDGE
126  fclose(stdin);
127  #endif
128    return 0;
129}

相关文章

hdu 5611 || BC #69 div2 1002 Baby Ming and phone number

·2 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=5611 题意:给出n个电话号码(长度为11的字符串),满足特殊条件的价格为a,否则为b.特殊条件为最后5位数字一样,最后5位严格递增或者严格递减,最后8位是一个1980年1月一日到2016年12月31日的合法日期。问最后的价值。

cf 611 A||codeforces goodbye 2015 C. New Year and Domino

·1 分钟
http://codeforces.com/contest/611/problem/C 题意:给出一个n*m的地图,.表示可以空,#表示墙。一个东西需要占两个相邻的格子,问给定一个矩形,放一个东西的方案数。 思路:q很大。。应该是先预处理出来直接调用答案。。。计数问题累加性。。应该是前缀和之类。。需要做的就是怎么标记。。我的做法是竖着放和横着放的个数分开来存。从左往右从上往下,每次标记到后一个点。然后二维的前缀和。然后每次询问的时候,去掉最上边和最左边两条边界上对应的多加的点。

codeforces 31 C. Schedule

·2 分钟
http://codeforces.com/problemset/problem/31/C 题意:给出n个借用教室的时间安排,可能会有冲突。要求恰好去掉一个时间安排使得剩下的时间安排不冲突。问多多少种方案。 思路:首先一个直觉是。。除非初始就没有任何冲突。。不然这个答案不会很大。。