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

zoj 3757 Alice and Bob and Cu...

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

zoj 3757 Alice and Bob and Cu...

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int s[10000],hash[200000];int hit[10000],in[10000];int a[2],i,j,pot,l_hit,l_in,n,m,flag,flag_pot;void set(){    for(int k=0; k<l_in; k++)        hash[in[k]]=1;    while(hash[s[pot]])        pot++;    flag=1-flag;}void solve(){    int sum=0;    for(int k=0; k<l_in; k++)        sum+=in[k];    if(l_hit==0)     {        a[1-flag]+=s[pot];    }    else if(in[0]==0&&l_in!=0)     {        a[1-flag]+=hit[l_hit-1];    }    else if(l_hit>1||(l_hit==1&&hit[0]!=s[pot]))     {        a[1-flag]+=hit[l_hit-1];    }    else     {        if(flag_pot)        { a[flag]+=sum; flag=1-flag; return;        }    }    if(in==0) return;    a[1-flag]+=sum;}int main(){    while(~scanf("%d%d",&n,&m))    {        a[1] = a[0] = 0;        for(i = 1; i<=n; i++) scanf("%d",&s[i]);        sort(s+1,s+n+1);        memset(hash,0,sizeof(hash));        flag = 0;        pot = 1;        for(i = 0; i<m; i++)        { flag_pot = 0; scanf("%d",&l_hit); for(j = 0; j<l_hit; j++)     scanf("%d",&hit[j]); scanf("%d",&l_in); for(j = 0; j<l_in; j++) {     scanf("%d",&in[j]);     if(in[j] == s[pot])     flag_pot = 1; } sort(hit,hit+l_hit); sort(in,in+l_in); solve(); set();        }        printf("%d : %dn",a[0],a[1]);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372041.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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