栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2804 Funny Games

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2804 Funny Games

#include<iostream>#include<cstdio>#include<string.h>#include<ext/hash_map>using namespace std;using namespace __gnu_cxx;enum {    SIZ = 10,    OFF = 8,};typedef unsigned long long ull;struct hf_str {    int operator()(const ull s) const {        return  s % 1313131;    }};struct eq {    bool operator()(const ull&a, const ull&b)const {        return a == b;    }};int N;double gob;double fac[SIZ];hash_map<ull, bool, hf_str, eq> tab;const double eps = 1e-7;bool dfs(double f, ull key){    if (f<=1.0 + eps) return false;    hash_map<ull, bool, hf_str, eq>::iterator it = tab.find(key);    if (it!=tab.end()){        return it->second;    }    bool ret = false;    for (int i=0; i<N; ++i){        key += (1llu<<(i*OFF));        if (!dfs(f * fac[i], key)){ ret = true; break;        }        key -= (1llu<<(i*OFF));    }    tab.insert(make_pair(key, ret));     return ret;}bool fun(){    tab.clear();    ull key = 0llu;    return dfs(gob, key);}void readIn(){    scanf("%lf%d", &gob, &N);    for (int i=0; i<N; ++i){        scanf("%lf", &fac[i]);    }    sort(fac, fac+N);}int main(){    const char *ans[2] = {  "Mikael", "Nils" };    int gn;    scanf("%d", &gn);    while(gn-- > 0){        readIn();        int t = fun();        printf("%sn", ans[t]);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374297.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号