poj 2503
2015-11-10 09:19
288 查看
这个题吧,我是水过去的,然而,一看有些想法真的不错
1MAP除了输入之外,没其他要注意的了
2qsort+二分查找
这个要注意的是qsort中的cmp的写法,刚开始不会写,一直在找
3hash
1MAP除了输入之外,没其他要注意的了
#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment(linker,"/STACK:102400000,102400000") using namespace std; #define MAX 100005 #define MAXN 10000005 #define maxnode 500005 #define sigma_size 30 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define LL long long #define ull unsigned long long #define mem(x,v) memset(x,v,sizeof(x)) #define lowbit(x) (x&-x) #define pii pair<int,int> #define bits(a) __builtin_popcount(a) #define mk make_pair const int prime = 999983; const int INF = 0x3f3f3f3f; const LL INFF = 1e18; const double pi = 3.141592653589793; const double inf = 1e18; const double eps = 1e-8; const int mod = 100007; const ull mx = 133333331; /*****************************************************/ inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; } /*****************************************************/ map<string,string>M; int main(){ M.clear(); //char stro[15],strf[15]; char a[30],b[15],c[15]; while(gets(a)&&a[0]!='\0') { sscanf(a,"%s%s",&b,&c); if(!M.count(c))M[c]=b; } while(~scanf("%s",&a)){ getchar(); if(M.count(a))cout<<M[a]<<endl; else cout<<"eh"<<endl; } }
2qsort+二分查找
这个要注意的是qsort中的cmp的写法,刚开始不会写,一直在找
#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment(linker,"/STACK:102400000,102400000") using namespace std; #define MAX 100005 #define MAXN 10000005 #define maxnode 500005 #define sigma_size 30 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 #define middle int m=(r+l)>>1 #define LL long long #define ull unsigned long long #define mem(x,v) memset(x,v,sizeof(x)) #define lowbit(x) (x&-x) #define pii pair<int,int> #define bits(a) __builtin_popcount(a) #define mk make_pair const int prime = 999983; const int INF = 0x3f3f3f3f; const LL INFF = 1e18; const double pi = 3.141592653589793; const double inf = 1e18; const double eps = 1e-8; const int mod = 100007; const ull mx = 133333331; /*****************************************************/ inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; } /*****************************************************/ typedef struct word{ char e[15],f[15]; }word; word Q[100010]; int cnt; //int cmp(const void *a, const void *b) //{ // return strcmp((*(Entry *)a).f, (*(Entry *)b).f); //} int cmp(const void *a,const void *b){ return strcmp((*(word*)a).f,(*(word*)b).f); } int Search(char p[]) { int L=0,R=cnt-1,Mid; int t; while(L<=R){ Mid=(L+R)/2; t=strcmp(Q[Mid].f, p); if(t==0)return Mid; else if(t==1)R=Mid-1; else L=Mid+1; } return -1; } int main(){ char a[30],b[15],c[15]; cnt=0; while(gets(a)&&a[0]!='\0') { sscanf(a,"%s%s",&b,&c); strcpy(Q[cnt].e,b); strcpy(Q[cnt++].f,c); } qsort(Q,cnt,sizeof(word),cmp); while(~scanf("%s",&a)){ getchar(); int pos=Search(a); if(pos==-1)cout<<"eh"<<endl; else cout<<Q[pos].e<<endl; } }
3hash
相关文章推荐
- usaco.section1.3.Prime Cryptarithm
- 原生js和jQuery实现页面跳转的学习
- Pixel
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)from http://www.jcodecraeer.com/a/anzhuokaifa/an
- 数据库ORA-01033错误解决办法
- win7与VMware ubuntu虚拟机实现文件共享
- linux sudo 命令
- 如何构建一个小型的Zoomeye—-从技术细节探讨到实现
- Ubuntu 14.04 Apache2 支持中文文件名
- 解决Android Studio Gradle Build Running 特别慢的问题
- coderforce 527APlaying with Paper
- Jquery+Ajax+Json+ashx生成表
- ImageView控件的基本属性
- 对于适配器ArrayAdapter中getView方法重写
- iOS 修改FMdatabase,不使用FMDatabaseQueue支持多线程数据库操作
- swift 快速奔跑的兔几 本节的内容是:SpriteKit第4讲 字体和动画
- [LeetCode]71. Missing Number缺失的数
- [LeetCode]71. Missing Number缺失的数
- 科目二 不通过 反思
- C语言之指针1.1数组