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() ...
随机推荐
- 【BZOJ2525】[Poi2011]Dynamite(二分,树形dp)
[BZOJ2525][Poi2011]Dynamite Description Byteotian Cave的结构是一棵N个节点的树,其中某些点上面已经安置了炸.药,现在需要点燃M个点上的引线引爆所有 ...
- ionic之AngularJS扩展动态组件
目录: 1. 模态对话框 : $ionicModal 2. 上拉菜单 : $ionicActionSheet 3. 弹出框 : $ionicPopup 4. 浮动框 : $ionicPopover 5 ...
- [App Store Connect帮助]六、测试 Beta 版本(4.2) 管理 Beta 版构建版本:查看构建版本状态和指标
必要职能:“帐户持有人”职能.“管理”职能.“App 管理”职能.“开发者”职能或“营销”职能.请参见职能权限. 在首页上,点按“我的 App”,选择您的 App,然后在工具栏中点按“TestFlig ...
- mysql的大数据量的查询
mysql的大数据量查询分页应该用where 条件进行分页,limit 100000,100,mysql先查询100100数据量,查询完以后,将 这些100000数据量屏蔽去掉,用100的量,但是如果 ...
- focus、click、blur、display、float、border、absolute、relative、fixed
onfocus:获取焦点,点击时,按着不放 onclick:点击松开之后,未点击其他处 onblur:点击松开之后,又点击其他处 display:block,none,inline block:单独占 ...
- ASP.NET 之页面重定向和传值
在开发 ASP.NET 网站时,经常需要从一个网页重定向(导航)到另一个网页,同时希望能够将信息从源页传递到目标页.例如,如果你正在开发一个保险网站,需要用一个页面来收集基本信息(用户信息.保险产品信 ...
- A8ERP权限管理系统
- IDEA破解方法以及快捷键大全
IntelliJ IDEA2017.3 激活 - CSDN博客:https://blog.csdn.net/dc2222333/article/details/78582131 Eclipse和Int ...
- iframe子页面让父页面跳转 parent.location.href
if ($roleNum < 9) { echo "<script > parent.location.href='admin_login.php' </script ...
- asp.net MVC 和 webForm的区别
asp.net MVC请求过程 ASP.NET MVC框架只是给开发者提供了开发web应用程序的一种选择,并不是要取代Webform这两种技术各有优缺点,开发者需要根据实际情况,选择对应的技术有时候, ...