URAL 1196. History Exam (二分)
1196. History Exam
Memory limit: 64 MB
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.
Input
not exceeding 109. Professor's list is sorted in non-descending order. The following line contains the number M of 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
Sample
input | output |
---|---|
|
|
题意:找出第一和第二个序列中都出现(同意反复累加)过的字符个数。
解析:因为第一个有序的,所以我们遍历第二个序列的同一时候对第一个序列二分搜索答案。
PS:本题有个非常诡异的现象:G++跑了1.5s+。可是VC++居然才跑0.343s。
。。貌似仅仅有VC++才干过。
AC代码:
- #include <cstdio>
- using namespace std;
- int a[15002];
- int main(){
- #ifdef sxk
- freopen("in.txt", "r", stdin);
- #endif // sxk
- int n, m, ans, foo;
- while(scanf("%d", &n)==1){
- ans = 0;
- for(int i=0; i<n; i++) scanf("%d", &a[i]);
- scanf("%d", &m);
- for(int i=0; i<m; i++){
- scanf("%d", &foo);
- int l = 0, r = n - 1, m;
- if(foo < a[0] || foo > a[n-1]) continue;
- else if(foo == a[0] || foo == a[n-1]){
- ans ++;
- continue;
- }
- while(l <= r){
- m = (r - l) / 2 + l;
- if(a[m] == foo){
- ans ++;
- break;
- }
- if(a[m] < foo) l = m + 1;
- else r = m - 1;
- }
- }
- printf("%d\n", ans);
- }
- return 0;
- }
URAL 1196. History Exam (二分)的更多相关文章
- URAL 2048 History 蔡勒公式
HistoryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- 二分法&三分法
ural History Exam 二分 #include <iostream> #include <cstdlib> using namespace std; //二分 ...
- Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】
A Tale of Two Lands 题目链接(点击) The legend of the foundation of Vectorland talks of two integers xx and ...
- UVa 111 - History Grading (by 最长公共子序列 )
History Grading Background Many problems in Computer Science involve maximizing some measure accor ...
- URAL 1873. GOV Chronicles
唔 神题一道 大家感受一下 1873. GOV Chronicles Time limit: 0.5 secondMemory limit: 64 MB A chilly autumn night. ...
- Codeforces Round #561 (Div. 2) C. A Tale of Two Lands
链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...
- uva111动态规划之最长公共子序列
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=74662#problem/C A B C D E C - Largest Rect ...
- UVA 111(LCS问题)
History Grading Background Many problems in Computer Science involve maximizing some measure accor ...
- UVA 111 (复习dp, 14.07.09)
History Grading Background Many problems in Computer Science involve maximizing some measure accor ...
随机推荐
- 安装office1406错误!!!急死个人。。。。。
因为用到Microsoft.Office.Interop.Word,将word转PDF.所以在服务器上需要安装office,但是报错1406,不能将值插入注册表..... 然后百度各种问题,说需要将注 ...
- Java final和static 修饰符
一.final final是不变的,最终的意思.可以用来修饰变量,方法,类. 1. 修饰变量 private final int a = 2; private final int b; // fina ...
- 基于TensorFlow的车牌号识别系统
简介 过去几周我一直在涉足深度学习领域,尤其是卷积神经网络模型.最近,谷歌围绕街景多位数字识别技术发布了一篇不错的paper.该文章描述了一个用于提取街景门牌号的单个端到端神经网络系统.然后,作者阐述 ...
- 如何学习Unity3D
如何学习 第一步首先了解unity3d的菜单,视图界面.这些事最基本的基础,可以像学word操作一样,大致能明白有几个菜单,几个基本的视图,各自起什么作用的就可以了. 第二步理解场景里面的坐标系统 ...
- html5——全屏显示
基本概念 1.HTML5规范允许用户自定义网页上任一元素全屏显示 2.requestFullscreen() 开启全屏显示.cancleFullscreen() 关闭全屏显示 3.不同浏览器兼容性不一 ...
- CSS——font
行高的量取方式: 1.第一行可设置margin-top值.然后将第一文字顶部到第二行文字顶部的值作为行高的值(要注意对齐方式) 2.将 3.电视上 font:12px/1.5//字体12px,行高1. ...
- 如何快速获取yun2win app key?
注册yun2win开发者账号 1.在注册页面输入您的邮箱,点击下方发送,yun2win将会发送一封验证邮件到您的邮箱: 2.如果没有收到邮件请查看垃圾箱或者点击重新发送: 3.打开邮箱查看验证邮件,点 ...
- Python 之读取大文件readline与readlines的差别
import time def get_all_lines(filename): start_time = time.time() try: f = open(filename, 'rb') exce ...
- 解决Mysql Workbench的Error Code: 1175错误
错误: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE ...
- 网络编程_socketserver
一.socketserver 网络编程 1.socketserver支持多用户并发处理:2.socketserver是对socket的再封装;处理步骤:1.创建一个socketserver类2.继承B ...