nyist 626 intersection set
http://acm.nyist.net/JudgeOnline/problem.php?pid=626
intersection set
- 描述
- 两个集合,你只需要求出两个集合的相同元素,并输出个数。
- 输入
- m n
{a1 , a2 , a3 , a4 … ai … am}
{b1 , b2 , b3 , b4 … bi … bn}
1 <= n , m <= 50000 , 保证一个集合中不会输入重复数据
0 <= ai , bi <= 100000
多组测试数据 - 输出
- 一行一个数据,为两个集合中相同的元素个数
- 样例输入
-
8 8
1 5 6 9 10 12 16 59
5 6 9 8 15 17 65 98 - 样例输出
-
3 分析:
把两组数据直接存到一个数组里,sort排序去重即可。
AC代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
int num[];
int main()
{
int m,i,n,count;
while(~scanf("%d %d",&m,&n))
{
count=;
for(i=;i<m+n;i++)
scanf("%d",&num[i]);
sort(num,num+m+n);
for(i=;i<n+m-;i++)
if(num[i]==num[i+])
count++;
printf("%d\n",count);
}
return ;
}
nyist 626 intersection set的更多相关文章
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- LeetCode Intersection of Two Arrays II
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...
- nyist 78 圈水池
http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一个 ...
随机推荐
- Oracle数值处理函数 (绝对值、取整...)
1.绝对值:abs() select abs(-2) value from dual; 2.取整函数(大):ceil() select ceil(-2.001) value from du ...
- C#委托初探
委托是一种定义方法签名的类型,可以与具有兼容签名的任何方法关联.您可以通过委托调用其中已添加的方法列表.委托用于将方法作为参数传递给其他方法.事件处理程序就是通过委托调用的方法.您可以创建一个自定义方 ...
- isset和empty比较
PHP的isset()函数 一般用来检测变量是否设置 格式:bool isset ( mixed var [, mixed var [, ...]] ) 功能:检测变量是否设置 返回值: 若变量不存在 ...
- Redis学习笔记(5)-Set
package cn.com; import java.util.HashMap; import java.util.Map; import java.util.Set; import redis.c ...
- 设计模式:单例模式(Singleton)
定义:确保一个类仅有一个实例,并提供一个访问它的全局访问点. 优点:在内存中只有一个对象,节省了内存空间 示例: Singleton.cs 写法一:非线程安全 public class Singlet ...
- Cocos2d-JS引入其他场景小实例
创建新项目,目标是把LogoNode.js场景引入app.js 新建LogoNode.js var LogoLayer = cc.Layer.extend({ ctor:function () { t ...
- [LeetCode] Scramble String(树的问题最易用递归)
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- magento email模板设置相关
magento后台 可以设置各种各样的邮件,当客户注册.下单.修改密码.邀请好友等等一系列行为时,会有相关信息邮件发出. 进入magento后台,System > Transactional E ...
- oracle入门-%的用法
vempno emp.empno%type; 例如上面的这句话,你的vempno就是你定义的变量,和面的那个emp是你数据库里面存在的表,他的表里面有意个empno字段,然后%type就是empno的 ...
- UILabel 添加图片
//设置显示图片 NSMutableAttributedString * cellAttributeStr = [[NSMutableAttributedString alloc]initWithSt ...