UVAL - 6755 - Swyper Keyboard
先上题目:
https://icpcarchive.ecs.baylor.edu/external/67/6755.pdf
题目复制起来比较麻烦。
题意:定义一种操作:给出一个字符串,然后手指就按照给出的字符串的字符出现顺序不离开触摸屏那样移动,这样最后就会得到一个字符串(不一定等于给出的字符串),现在再给你一堆字符串,问你这些字符串根据给你的顺序,最先出现的是哪一个字符串是得到的那个字符串的子序列。如果没有出现的话就输出"NO SOLUTION"。
做法:先求出那个字符串,然后再逐个逐个字符串找。关于怎样求这个字符串,说起来好像有点复杂,大概的做法就是在判断划过某两个字符的过程中会有哪些字符的时候,先缩小枚举的范围,然后对于范围里面的每一个字符都进行一次判断,判断的方法是使用叉积来判断,如果这个判断的字符的四个角不都在原来的那两个字符连成的线段的一侧的话说明就是穿过的(注意刚好在线上的情况)。具体实现看代码。
上代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#define APH 26
#define MAX 1002
using namespace std; typedef struct Point{
int x,y; Point(int x=,int y=):x(x),y(y){} }Point;
typedef Point Vector;
Vector operator + (Point A,Point B){ return Vector(B.x+A.x,B.y+A.y);}
Vector operator - (Point A,Point B){ return Vector(B.x-A.x,B.y-A.y);}
Vector operator * (Point A,int e){ return Point(A.x*e,A.y*e);}
Vector operator / (Point A,int e){ return Point(A.x/e,A.y/e);} int Dot(Vector A,Vector B){ return A.x*B.x + A.y*B.y;}
inline int Cross(Vector A,Vector B){ return A.x*B.y - A.y*B.x;} int cx[]={-,,,-};
int cy[]={,,-,-}; string path[APH][APH];
Point pos[APH];
char ch[APH][APH]; Point getPoint(char c){
if(c<='E') return Point(c-'A'+,);
else{
return Point((c-'F')%+,-(c-'F')/);
}
} bool check(Point A,Point B,Point C){
bool b=,l=;
A.x*=; A.y*=;
B.x*=; B.y*=;
C.x*=; C.y*=;
Point u;
for(int i=;i<;++i){
u=Point(C.x+cx[i],C.y+cy[i]);
if(Cross(A-u,B-u)>) b|=;
if(Cross(A-u,B-u)<) l|=;
}
return b&&l;
} string GetPath(int a,int b){
string ans="";
if(a==b) return ans;
int ax=pos[a].x,ay=pos[a].y;
int bx=pos[b].x,by=pos[b].y;
for(int i= ax ; (ax < bx ? i<=bx : i>=bx) ; (ax < bx ? i++ : i--) ){
for(int j= ay ; (ay < by ? j<=by : j>=by) ; (ay < by ? j++ : j--)){
if(ch[i][j]==) continue;
if(check(pos[a],pos[b],pos[ch[i][j]-'A'])) ans+=ch[i][j];
}
}
//if(ans.length()<=1) return "";
ans = ans.substr(,max((int)(ans.length()-),));
//cout<<ans<<endl;
return ans;
} void prepare(){
memset(ch,,sizeof(ch));
for(int i=;i<APH;i++){
pos[i]=getPoint('A'+i);
ch[pos[i].x][pos[i].y]='A'+i;
// cout<<ch[pos[i].x][pos[i].y]<<" ";
}
// cout<<endl;
for(int i=;i<APH;i++){
for(int j=;j<APH;j++){
path[i][j]=GetPath(i,j);
// cout<<path[i][j]<<endl;
}
}
} string connect(string st){
string ans;
ans+=st[];
for(unsigned int i=;i<st.length();i++){
ans+=path[st[i-]-'A'][st[i]-'A'];
ans+=st[i];
}
//ans+=st[st.length()-1];
return ans;
} bool check_str(string s,string str){
unsigned i,j;
for(i=,j=;i<s.length();i++){
if(s[i]==str[j]){
j++;
if(j==str.length()) return ;
}
}
return ;
} int main()
{
int t,n;
string st,s,str;
//freopen("data.txt","r",stdin);
ios::sync_with_stdio(false);
prepare();
cin>>t;
while(t--){
cin>>n>>st;
s=connect(st);
//cout<<"* "<<s<<endl;
bool f=;
for(int i=;i<n;i++){
cin>>str;
//cout<<str<<endl;
if(!f && check_str(s,str)){
f=;
cout<<str<<endl;
}
}
if(!f) cout<<"NO SOLUTION"<<endl;
}
return ;
}
/*6755*/
UVAL - 6755 - Swyper Keyboard的更多相关文章
- Fedora 22中的Locale and Keyboard Configuration
Introduction The system locale specifies the language settings of system services and user interface ...
- android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
<activity android:name="xxxActivity" android:configChanges="keyboard|keyboardHidde ...
- USB Keyboard Recorder
catalogue . 引言 . Device Class Definition for Human Interface Devices (HID) . USB HID Report Descript ...
- imx6 matrix keyboard
imx6需要添加4x4的矩阵键盘.本文记录添加方法. 参考链接 http://processors.wiki.ti.com/index.php/TI-Android-JB-PortingGuide h ...
- Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...
- vimium Keyboard Bindings
Modifier keys are specified as `<c-x>`, `<m-x>`, and `<a-x>` for ctrl+x, meta+x, a ...
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...
- 6754 Keyboard of a Mobile Telephone
/*实践再次说明ch=getchar()的速度非常慢*/ /*大水题,不解释*/ #include<stdio.h> #include<string.h> int main() ...
随机推荐
- bzoj1202: [HNOI2005]狡猾的商人(并查集 差分约束)
1202: [HNOI2005]狡猾的商人 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4127 Solved: 1981[Submit][Sta ...
- GG_Model 类库与数据库表对应建立实体类
3.4.GG_Model 类库与数据库表对应建立实体类 我这里不教大家写代码,直接用TT模板自动生成,省去写代码的麻烦. A. 三个文件MysqlDbhelper.ttinclude .mysqlMa ...
- ElementaryOS 0.4快速配置工具
使用方法: 终端执行 wget http://linux-1251056822.costj.myqcloud.com/elementary_config && bash element ...
- 转 DOS(CMD)下批处理换行问题/命令行参数换行 arg ms-dos
DOS(CMD)下批处理换行问题本人经常写一些DOS批处理文件,由于批处理中命令的参考较多且长,写在一行太不容易分辨,所以总想找个办法把一条命令分行来写,今天终于试成功两种方法.一.在CMD下,可以用 ...
- 专题四:自定义Web浏览器
前言: 前一个专题介绍了自定义的Web服务器,然而向Web服务器发出请求的正是本专题要介绍的Web浏览器,本专题通过简单自定义一个Web浏览器来简单介绍浏览器的工作原理,以及帮助一些初学者揭开浏览器这 ...
- LN : leetcode 529 Minesweeper
lc 529 Minesweeper 529 Minesweeper Let's play the minesweeper game! You are given a 2D char matrix r ...
- [ SDOI 2006 ] 仓库管理员的烦恼
\(\\\) Description 有 \(n\) 种货物和 \(n\) 个仓库,开始第 \(i\) 个仓库里有 \(a_{ij}\) 个第 \(j\) 种货物. 现在要让每种货物都只放到一个仓库里 ...
- (9)string对象上的操作2
比较string对象的比较运算符 这种由string类定义的几种比较字符串的运算符能逐一比较string对象中的字符(对大小写敏感).
- The user specified as a definer ('root'@'%') does not exist 解决方法
mysql> grant all privileges on *.* to root@"%" identified by "."; Query OK, r ...
- Laravel 网站项目目录结构规划
最近在用Laravel这个PHP框架搭网站,大致了解这个框架的目录结构之后感觉学到了不少东西. 首先安装好包管理器: PHP部分当然用composer,安装在全局目录下方便一点. 前端部分,我没有选择 ...