poj 2503

本文深入探讨了算法与数据结构的核心概念及其在实际应用中的重要性。通过详细解析各种数据结构如二叉树、队列、栈等,并结合经典算法如排序、动态规划,展示了它们在解决复杂问题时的高效性。同时,文章还强调了理论知识与实践应用之间的桥梁,旨在帮助读者更好地理解和掌握这一领域的精髓。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个题吧,我是水过去的,然而,一看有些想法真的不错



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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值