M - Lisp em SCU - 4490(模拟)

Time Limit: 1000 MS    Memory Limit: 131072 K 


    

Description

There are two lists and they may be intersected with each other. You must judge if they are intersected and find the first node they have in common.

Input

The first line is the number of cases. Each case consists of two lists. Each list consists of multiple nodes. Each node is represented by its address in memory. So, a list may look like this: 0x233333 0x123456 0xabcdef1 0xffffff nil nil is the end of the list. All lists have no cycle. The length of list is not larger than 4e5. List can't be empty. Warn: huge input.

Output

"No" if they are not intersected. "Yes Address", if they are intersected, print "Yes" and the address of their first common node.

Sample Input

2 0x233333 0x123456 0xabcdef1 0xffffff nil 0x999999 0x332232 0xffffff nil 0x233333 0x123456 0xabcdef1 0xffffff nil 0x987654 0xafafaf 0xfffcccc 0xaaface nil

Sample Output

Yes 0xffffff No

Author

qw4990

描述


有两个可能intersected列表和他们的彼此。

你必须intersected法官如果他们发现他们有一个与第一节点中常见。


输入


第一行是在数量的情况下。

每个案例包括两个列表。

每个列表包括多个节点。

每个节点是由在内存中的地址的代表。

所以,这个列表可能看起来像:

0x233333 0x123456 0xabcdef1 0xffffff无

列表是无尽头的。

在所有的列表有一个周期。

更大的长度比4e5列表”。

can’t是空的列表。

警告:巨大的投入。

输出


“如果他们不intersected”。

“是的,他们是intersected地址”,如果“是”,打印的地址和他们的第一个公共节点。

思路:用map来查找,第一行出现的地址让它的值加一,第二行如果发现再次出现就输出它

一开始用set做,现在还不知道错那.....

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
       string a;
       int b=0;
       map<string,int> s;
       int flag=0;
       while(cin>>a)
       {
           if(a=="nil")
            break;
           s[a]++;
       }
       while(cin>>a)
       {
           if(a=="nil")
            break;
           if(s[a]==1&&b==0)
           {
            cout<<"Yes "<<a<<endl;
            b=1;
           }
       }
       if(b==0)
        cout<<"No"<<endl;
   }
}
 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值