凯撒密码 CH Round #57 - Story of the OI Class
2014-11-02 00:33
375 查看
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/凯撒密码
题解:刚开始想map,结果被出题说的卡map提醒了。
然后直觉告诉我可以hash相邻字母的距离,然后就这样做了。。。
代码:
View Code
题解:刚开始想map,结果被出题说的卡map提醒了。
然后直觉告诉我可以hash相邻字母的距离,然后就这样做了。。。
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 1000000 #define maxm 500+100 #define eps 1e-10 #define ll long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define mod 1000000007 using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} return x*f; } int n,t,a[maxn],b[maxn],f[50][50]; char s[10]; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); n=read(); for1(i,26) for1(j,26) f[i][j]=j>=i?j-i:26-i+j; for1(i,n) { scanf("%s",s);t=0; for0(j,3)t=t*26+f[s[j]-'a'+1][s[j+1]-'a'+1]; a[t]=i;b[t]=s[0]; } for1(i,n) { scanf("%s",s);t=0; for0(j,3)t=t*26+f[s[j]-'a'+1][s[j+1]-'a'+1]; printf("%d %d\n",a[t],f[s[0]-'a'+1][b[t]-'a'+1]); } return 0; }
View Code
相关文章推荐
- CH Round #57 - Story of the OI Class 凯撒密码
- 【拓扑排序】【堆】CH Round #57 - Story of the OI Class 查错
- 查错 CH Round #57 - Story of the OI Class
- CH Round #57 - Story of the OI Class 查错
- 导航软件 CH Round #57 - Story of the OI Class
- An easy instance of using the template class in C++
- 關於Eclipse的提示 The serializable class XXXXXX does not declare a static final serialVersionUID field of type long
- Using the HID class eases the job of writing USB device drivers
- the story of new oriental
- The 4th class of Oral English
- AS.NET2.0 用户控件错误!!The base class includes the field 'MyControl_1', but its type (MyControl) is not compatible with the type of control (ASP.MyControl_ascx).
- The 6th Class of Oral English
- The Story of Lena(.tiff)
- the differences of DataRelation class between 1.1 and 2.0
- The order of running Java class
- A class extends ArrayList, but the instance of the calss do not work in a complex case.
- Why is the size of an empty class not zero?
- The 5th Class of Josh
- [Funny story]Funny story in the English class
- Find a way out of the ClassLoader maze (2)