POJ3487-稳定婚姻系统

该博客主要展示了如何用C++编程解决POJ3487稳定婚姻系统的算法问题。通过读取输入数据,创建稳定婚姻匹配,并确保每个人都能找到最满意的配对。代码涉及到了数据结构、优先级队列和动态规划等概念。
摘要由CSDN通过智能技术生成
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;

const int NN=128;
const int INF=0x3fffffff;

int n,cnt1,cnt2,hash[NN],tmpf[NN],cur[NN],num[NN],tag[NN],w[NN][NN];
char id[NN];
bool single[NN];
vector<int> fav[NN];

int get()
{
    int x;
    char ch=getchar();
    while (!isalpha(ch)) ch=getchar();
    if (islower(ch))
    {
        x=ch-'a';
        if (!hash[x])
        {
            hash[x]=++cnt1;
            id[cnt1]=ch;
        }
    }
    else
    {
        x=ch-'A'+26;
        if (!hash[x])
        {
            hash[x]=++cnt2;
            id[cnt2]=ch;
        }
    }
    return hash[x];
}
void init()
{
    scanf("%d",&n);
    cnt1=0;
    cnt2=n;
    memset(hash,0,sizeof(hash));
    for (int i=1; i<=n*2; i++) /
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值