↓ Skip to main content
  1. Posts/

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

·510 words·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

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}

Related

BZOJ 1689: [Usaco2005 Open] Muddy roads 泥泞的路 (模拟)

·785 words·2 mins
1689: [Usaco2005 Open] Muddy roads 泥泞的路 # Time Limit: 5 Sec Memory Limit: 64 MB Submit: 311 Solved: 227 [Submit][Status][Discuss] Description # Farmer John has a problem: the dirt road from his farm to town has suffered in the recent rainstorms and now contains (1 <= N <= 10,000) mud pools. Farmer John has a collection of wooden planks of length L that he can use to bridge these mud pools. He can overlap planks and the ends do not need to be anchored on the ground. However, he must cover each pool completely. Given the mud pools, help FJ figure out the minimum number of planks he needs in order to completely cover all the mud pools.

bzoj1603: [Usaco2008 Oct]打谷机 (纱布题)

·589 words·2 mins
# Time Limit: 5 Sec Memory Limit: 64 MB Submit: 774 Solved: 593 [Submit][Status][Discuss] Description # Farmer John有一个过时的打谷机(收割小麦),它需要带子来带动。发动机驱动轮1总是顺时针旋转的,用来带动转轮2,转轮2来带动转轮3,等等。一共有n(2<=n<=1000)个转轮(n-1条带子)。上面的图解描述了转轮的两种连接方式,第一种方式使得两个轮子旋转的方向相同,第二种则相反。 给出一串带子的信息: *Si—驱动轮 *Di—被动轮 *Ci—连接的类型(0=直接连接,1=交叉连接) 不幸的是,列出的信息是随即的。 作为样例,考虑上面的图解,n=4,转轮1是驱动轮,可以得知最后转轮4是逆时针旋转的。

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

·757 words·2 mins
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

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

codeforces 31 C. Schedule

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