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() ...
随机推荐
- JavaScript--DOM删除节点removeChild()
删除节点removeChild() removeChild() 方法从子节点列表中删除某个节点.如删除成功,此方法可返回被删除的节点,如失败,则返回 NULL. 语法: nodeObject.remo ...
- Spring.Net学习笔记(4)-属性及构造器注入
一.开发环境 操作系统:Win10 编译器:VS2013 .Net版本:.net framework4.5 二.涉及程序集 Spring.Core.dll:1.3.1 Common.Logging.d ...
- python做一个数独小游戏
最近看了下python的一些知识,在这里记载一下. 1.首先是安装,在官网下载最新的版本3.6,安装的时候要注意在下面勾选上ADD TO PATH,安装的时候会自动写入到环境变量里面,如果没有勾选,可 ...
- Android开发: 关于性能需要考虑的
刚做Android开发时,只管完成任务,将需求完成,以能完成一款界面酷炫的app为自豪.然而,随着代码量的增加,越来越意识到,一款成功的移动端产品,光有酷炫的外衣还不够,还需要在各方面都优秀. 试想, ...
- HanLP自然语言处理包开源(包含源码)
支持中文分词(N-最短路分词.CRF分词.索引分词.用户自定义词典.词性标注),命名实体识别(中国人名.音译人名.日本人名.地名.实体机构名识别),关键词提取,自动摘要,短语提取,拼音转换,简繁转换, ...
- HDU_1024_dp
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 导出功能在数据库内容为数字,excel表格中是汉字的时候
代码如下: @ExcelField(title = "饮水器评价",dictType = "waterer_rate" ,align = 2, sort = 2 ...
- JSON字符串的生成
public class Corporation { public string remark { get; set; } public string version { get; set; } pu ...
- Eureka组件、Eureka自我保护模式
Eureka包含两个组件:Eureka Server和Eureka Client Eureka Server提供服务发现的能力,各个微服务启动时,会向Eureka Server注册自己的信息(例如 ...
- spring 中属性scope 的prototype(有状态)和singleton(无状态)
默认情况下,从bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spring容器只存在一个共享的bean实例, 默认的配置. Prototype: ...