hihocoder #1366 : 逆序单词
来源:互联网 发布:种子填充算法原理 编辑:程序博客网 时间:2024/05/21 10:59
题目链接: 点这里
题意:略。
思路:按照每个字符串的长度排个序,然后对每个串二分查找长度相同的串。
AC代码:
#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#include <stack>#include <queue>#include <vector>#include <cmath>#include <map>#include <set>#define ll long long#define llu unsigned long long#define INF 0x3f3f3fusing namespace std;const int maxn = 1011130;const int N = 111123;const double eps = 1e-10;const double PI = acos(-1.0);int n;struct node { char s[20]; int len;}p[55000];bool cmp(node a,node b) { return a.len < b.len;}int lound(int x) { int l = 1,r = n+1; while(l<r) { int mid = (l+r)>>1; if(p[mid].len >= x) { r = mid; }else { l = mid+1; } } return (l+r)/2;}int main(){// ios::sync_with_stdio(false); scanf("%d",&n); char str[20]; for(int i=1;i<=n;i++) { scanf("%s",str); strcpy(p[i].s,str); p[i].len = strlen(str); } sort(p+1,p+n+1,cmp); int ans = 0; for(int i=1;i<n; i++) { int l = p[i].len; int ix = lound(l); int iy = lound(l+1);// cout<<"ix="<<ix<<" iy="<<iy<<endl; for(int j=ix; j<iy; j++) { int idx = 0; int f = 0; while(idx < l) { if(p[i].s[idx] != p[j].s[l-idx-1]) { f = 1; break; } idx++; } if(f == 0) { ans++; break; } }// cout<<"ans="<<ans<<endl; } printf("%d\n",(ans+1)/2); return 0;}/*7doglivehihoevilcodergodredoc*/
0 0
- hihocoder 1366 : 逆序单词
- hihocoder #1366 : 逆序单词
- 【hihocoder】#1366 : 逆序单词
- HihoCoder]#1366 : 逆序单词
- hihocoder 1366 逆序单词
- HihoCoder 1366 STL 单词逆序
- #1366 : 逆序单词
- 单词逆序
- hihocoder中的逆序排队
- 句子逆序,单词不逆序
- 堆栈-单词逆序
- 单词逆序--堆栈方法
- 逆序输出单词
- 字符串中的单词逆序
- 逆序字符串中的单词
- 字符串中单词逆序
- 单词逆序算法
- 逆序输出单词
- 深入理解HTTP协议
- Ubuntu下QT控制台程序无法运行的解决方案以及XTerm的配置方法
- spring MVC配置详解
- Bmob后端云——私人云数据库
- samba服务配置
- hihocoder #1366 : 逆序单词
- Reactivex.js
- GPU图形绘制管线
- left join查询优化
- 阿里前端的困局与突围
- matlab 产生不重复随机整数的序列
- 简版服务器(c语言实现) (多线程)
- 使用POI导入导出Excel2003、2007示例
- window下spyder的快捷键