google要在线笔试----bad horse 二分图

一开始想得不够全面,很傻很天真:

输入如果两个都存在,并且相等那么则出错

输入如果一个存在那么另一个则与其相反

输入如果都不存在那么一个为1一个为0,就是这个地方,01选择的问题最终决定还是二分图吧

想要不等他输完就出结果,显然不对,当然测试用例通过了百分之90 多,但是有几个出现问题了:


例如:

N M    0 1

L D     0 1

D Q     1 0

Q N      0 0

这时应该出错了,但是这个是没有错的因为如果一开始我们把N M设为1 0后面就没错了因此呢,这样不对

#include<iostream>
#include<string>
#include<map>
using namespace std;
#define MAX 101
struct node
{
int color;
node *friends[MAX];
};
int main()
{

freopen("D:\\a3.in","r",stdin);
freopen("D:\\b.out","w",stdout);
/********************************************/
int T;
cin>>T;
int id=1;
while(T--)
{
map<string,int> m;
int M;
cin>>M;
int r=0;
for(int i=0;i<M;i++)
{
string a,b;
cin>>a>>b;
if(m.count(a)>0&&m.count(b)>0)//如果都存在
{
if(m[a]==m[b])
{
r=1;
}
}
else if(m.count(a)>0)
{
m[b]=(m[a]==0)?1:0;
}
else if(m.count(b)>0)
{
m[a]=(m[b]==0)?1:0;
}
else
{
m[a]=0;
m[b]=1;
}
}
if(r==0)
cout<<"Case #"<<id<<": Yes"<<endl;
else
cout<<"Case #"<<id<<": No"<<endl;
id++;
}
/********************************************/
fclose(stdin);
fclose(stdout);
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值