1196. History Exam
来源:互联网 发布:日系男装店 知乎 编辑:程序博客网 时间:2024/05/02 01:23
1196. History Exam
Time Limit: 2.0 second
Memory Limit: 16 MB
Memory Limit: 16 MB
Professor of history decided to simplify the examination process. At the exam, every student should write a list of historic dates she knows (she should write the years only and, of course, must be able to explain what event took place in this or that year). Professor has a list of dates that students must know. In order to decide upon the student's mark, Professor counts the number of dates in the student's list that are also present in his list. The student gets her mark according to the number of coincidences.
Your task is to automatize this process. Write a program that would count the number of dates in the student's list that also occur in Professor's list.
Input
The first line contains the number N of dates in Professor's list, 1 ≤ N ≤ 15000. The followingN lines contain this list, one number per line. Each date is a positive integer not exceeding 109. Professor's list is sorted in non-descending order. The following line contains the number Mof dates in the student's list, 1 ≤ M ≤ 106. Then there is the list itself; it is unsorted. The dates here satisfy the same restriction. Both in Professor's and in the student's lists dates can appear more than once.
Output
Output the number of dates in the student's that are also contained in Professor's list.
Sample
21054149241492655361492100
2
我不知道为什么之前不用二分的时候,明明结果正确,也报错。。(Wrong answer,,无关时间问题)
#include <iostream>using namespace std;int a[15000], b[1000000];int main(){int n, m, i, j, num = 0, l, r, k;cin>>n;for (i=0; i<n; i++)cin>>a[i];cin>>m;for (i=0; i<m; i++)cin>>b[i];for (i=0; i<m; i++){l = 0;r = n - 1;while (l <= r){k = (l + r) / 2;if (b[i] == a[k]){num++;break;}else if (b[i] < a[k])r = k - 1;elsel = k + 1;}}cout<<num<<endl;}
- 1196. History Exam
- URAL 1196. History Exam (二分)
- 【二分orSet】History Exam
- Ural - 1196 History Exam
- exam
- Exam
- history
- history
- history
- history
- history
- history
- history
- history
- history
- history
- history
- history !
- chrome app 学习笔记 (1) --开发简介
- 禁用使用未签名驱动导致的windows 7自动修复
- poj 1375 Intervals 圆的切线
- How to Completely Fix Runtime Error 216 Error
- 简单c/c++笔试题 .
- 1196. History Exam
- mvc3 提供程序未返回 ProviderManifestToken 字符串
- poj1329 Circle Through Three Points 三角形外接圆(水)
- MFC与wxWidgets比较
- 一个程序员的艰辛路程(成功需要汗水和磨练)
- 由字符串是否包含想到的字符串的排序
- [Basic]面向对象之信息隐藏(二)
- 移动产品设计之ios导航模式
- truelicense简要说明