BestCoder Round #48 ($) (hdu 5284、hdu 5285)

1001

模拟

//author: CHC
//First Edit Time:  2015-07-18 19:39
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=3145728+1000;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
char strs1[MAXN],strs2[MAXN];
char dui[]="wyh";
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf(" %s",strs1);
        int len=strlen(strs1);
        int tot=0;
        for(int i=0;i<len;i++){
            if(strs1[i]==strs1[i+1]&&strs1[i]=='v'){
                //printf("here");
                strs2[tot++]='w';
                ++i;
            }
            else strs2[tot++]=strs1[i];
        }
        strs2[tot]=0;
        //printf("h:%s\n",strs2);
        int j=0;
        for(int i=0;i<tot;i++){
            if(strs2[i]==dui[j]){
                ++j;
                if(j==3)break;
            }
        }
        if(j==3)puts("Yes");
        else puts("No");
    }
    return 0;
}
1002

二分图染色,然后贪心

//author: CHC
//First Edit Time:  2015-07-18 19:51
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=100000+1000;
const int MAXM=100000*3+1000;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
struct Edge {
    int to,next;
    Edge(){}
    Edge(int _to,int _next):to(_to),next(_next){}
}e[MAXM];
int head[MAXN],tot;
void init(){
    memset(head,-1,sizeof(head));
    tot=0;
}
void AddEdge(int u,int v){
    e[tot]=Edge(v,head[u]);
    head[u]=tot++;
    e[tot]=Edge(u,head[v]);
    head[v]=tot++;
}
int colors[MAXN],c0,c1;
int dfs(int u){
    if(colors[u]==0)++c0;
    else ++c1;
    for(int i=head[u];~i;i=e[i].next){
        int to=e[i].to;
        if(colors[to]==-1){
            colors[to]=!colors[u];
            if(!dfs(to))return false;
        }
        else if(colors[to]==colors[u]){
            return false;
        }
    }
    return true;
}
int has[MAXN],n,m;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        memset(colors,-1,sizeof(colors));
        memset(has,0,sizeof(has));
        init();
        scanf("%d%d",&n,&m);
        int tot=n;
        for(int i=0,x,y;i<m;i++){
            scanf("%d%d",&x,&y);
            AddEdge(x,y);
            if(!has[x]){
                has[x]=1;
                tot--;
            }
            if(!has[y]){
                has[y]=1;
                tot--;
            }
        }
        if(n==0){
            puts("Poor wyh");
            continue;
        }
        if(m==0){
            if(n==1){
                puts("Poor wyh");
            }
            else {
                printf("%d %d\n",n-1,1);
            }
            continue;
        }
        int cnt1=0,cnt2=0,ok=0;
        for(int i=1;i<=n;i++){
            if(colors[i]==-1&&has[i]){
                c0=c1=0;
                colors[i]=0;
                if(!dfs(i))ok=1;
                if(c0<c1)swap(c0,c1);
                if(cnt1==0){
                    cnt1+=c0;
                    cnt2+=c1;
                }
                else if(cnt2==0){
                    cnt2+=c0;
                    cnt1+=c1;
                }
                else {
                    cnt1+=c0;
                    cnt2+=c1;
                }
                if(cnt1<cnt2)swap(cnt1,cnt2);
            }
        }
        if(ok)puts("Poor wyh");
        else {
            if(cnt1==0||cnt2==0){
                puts("Poor wyh");
                continue;
            }
            if(cnt1<cnt2)swap(cnt1,cnt2);
            //printf("tot:%d\n",tot);
            //printf("cnt1:%d cnt2:%d\n",cnt1,cnt2);
            printf("%d %d\n",cnt1+tot,cnt2);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值