Who Will Win?
Gautam and Subhash are two brothers. They are similar to each other in all respects except one. They have different ways of searching. When Gautam has to search for an item from a lot, he goes through all the items one by one and stops when he finds the item. However Subhash has an entirely different and interesting way of searching. However the search works only for items which are sorted. He goes to the middle of the lot, if he finds the desired item, he stops, if not, he checks whether the middle item is smaller or larger than the required item. If larger, he repeats the same process for the first half of the lot, otherwise second half. One day, the two brothers sit in a contest in which they have to find a name out of a sorted dictionary. Whoever finds out the name first will win the contest. The audience is very eager to know who will win and hence they want you to predict.
Input:
The first line of input takes the number of test cases, T.
The next T lines take the total number of names N, followed by M the position of the name to be searched, as well as the amount of time taken for each observation by Gautam G and Subhash S.
Output:
Print 1 in case Gautam will win, 2 in case Subhash will win, 0 in case of a draw in a separate line.
Constraints:
1<=T<=100
1<=N<=1000
1<=M<=N
1<=G<=100
1<=S<=100
Example:
Input:
3 10 8 10 25 10 8 10 30 10 8 10 12
Output:
2 2 2
下面是我的代码实现,C++
#include <iostream>
using namespace std;
int main()
{
int N;
cin>>N;
while(N--)
{
int num,index,g,s,gtime,stime;
cin>>num;
cin>>index;
cin>>g;
cin>>s;
,r=num,mid,sci=;
gtime=index*g;
while(l<=r)
{
mid=(l+r)>>;
if(mid==index)
{
sci++;
break;
}
else if(mid<index)
{
sci++;
l=mid+;
}
else
{
sci++;
r=mid-;
}
}
stime=sci*s;
if(stime>gtime)
cout<<<<endl;
else
cout<<<<endl;
}
;
}
如有问题,请留言
Who Will Win?的更多相关文章
- 【Win 10 应用开发】启动远程设备上的应用
这个功能必须在“红石-1”(build 14393)以上的系统版中才能使用,运行在一台设备上的应用,可以通过URI来启动另一台设备上的应用.激活远程应用需要以下前提: 系统必须是build 14393 ...
- Win.ini和注册表的读取写入
最近在做打包的工作,应用程序的配置信息可以放在注册表文件中,但是在以前的16位操作系统下,配置信息放在Win.ini文件中.下面介绍一下Win.ini文件的读写方法和注册表的编程. 先介绍下Win.i ...
- 苹果台式一体机笔记本安装win双系统攻略教程
步骤 序:win系统下载 :http://www.itellyou.cn 选择要安装的系统进行下载,本文以win7为例 进入苹果系统,左上角——前往——实用工具——BootCamp 助理 点击继续 ...
- Win下最爱效率利器:AutoHotKey
AutoHotkey是一个windows下的开源.免费.自动化软件工具.它由最初旨在提供键盘快捷键的脚本语言驱动(称为:热键),随着时间的推移演变成一个完整的脚本语言.但你不需要把它想得太深,你只需要 ...
- Win下必备利器之Cmder
诚言,对于开发码字者,Mac和Linux果断要比Windows更贴心;但只要折腾下,Windows下也是有不少利器的.之前就有在Windows下效率必备软件一文中对此做了下记载:其虽没oh-my-zs ...
- 【Win 10 应用开发】手写识别
记得前面(忘了是哪天写的,反正是前些天,请用力点击这里观看)老周讲了一个14393新增的控件,可以很轻松地结合InkCanvas来完成涂鸦.其实,InkCanvas除了涂鸦外,另一个大用途是墨迹识别, ...
- 【Win 10 应用开发】InkToolBar——涂鸦如此简单
从WPF开始,就有个InkCanvas控件,封装了数字墨迹处理相关的功能,Silverlight到Win 8 App,再到UWP应用,都有这个控件,所以,老周说了3688遍,凡是.net基础扎实者,必 ...
- 【Win 10 应用开发】导入.pfx证书
这个功能其实并不常用,一般开发较少涉及到证书,不过,简单了解一下还是有必要的. 先来说说制作测试证书的方法,这里老周讲两种方法,可以生成用于测试的.pfx文件. 产生证书,大家都知道有个makecer ...
- 【Win 10应用开发】延迟共享
延迟共享是啥呢,这么说吧,就是在应用程序打开共享面板选择共享目标时,不会设置要共享的数据,而是等到共享目标请求数据时,才会发送数据,而且,延迟操作可以在后台进行. 这样说似乎过于抽象,最好的诠释方法, ...
- 【Win 10 应用开发】共享目标(UWP)
在开始吹牛之前,先给大伙伴们拜个年,祝各位身体健康.生活愉快.[码]到功成. ------------------------------------------------------------- ...
随机推荐
- 2778:Ride to School-poj
2778:Ride to School 总时间限制: 1000ms 内存限制: 65536kB 描述 Many graduate students of Peking University are ...
- AFNetworking提示3840 Unescaped control character around character XXX
处理办法:找到AFNetworking包中AFURLResponseSerialization.m文件在第250行修改代码如下: if (data.length > 0 && ! ...
- Office 365系列 (1)概览:完整的云中Office
Office365(以下简称O365)是一个集Office,企业邮箱,日历,日程管理,音视频会议 ,企业网盘 ,企业协作平台为一体的,旨在提高团队办公效率,减少基础设施投资和IT运维压力的解决方案.在 ...
- #openstack故障处理汇总
##openstack故障处理汇总 排错 openstack pike 部署 目录汇总 http://www.cnblogs.com/elvi/p/7613861.html ############# ...
- git学习——Github关联(2)
一.参考学习链接 1.重点看Github与Git的关联. http://www.cnblogs.com/schaepher/p/5561193.html#github 2.git的全面详细介绍. ht ...
- Laravel 框架安装
Composer 在命令行执行 create-project 来安装 Laravel:就是下面这一句话就OK了!composer create-project laravel/laravel --pr ...
- Hibernate框架进阶(上篇)
导读 前面一片文章介绍了Hibernate框架的入门,主要是讲解Hibernate的环境搭建和简单测试,有兴趣的童鞋出门左转.本文在入门的基础上进行Hibernate的进阶讲解,分为上中下三篇,本篇为 ...
- 【GISer&&Painter】GISer
基于上一篇OpenGL的渲染原理,这两周又陆续接触了一些关于WebGL绘图的一些内容,因为刚入门,很多东西又很晦涩,所以特意花了小半天的时间整理了一下,特此记录. 一 画布和画笔:创建Canvas ...
- Redis的简单使用和介绍
1.什么是NoSQL NoSQL = Not Only SQL 非关系型的数据库 2. 为什么需要NoSQL High performance 高并发读写 ...
- SQL-Oracle内实现柱形图式的效果
在SQL SERVER内有一个函数replicate()可以实现柱形图效果,本质上是利用字符重复出现的次数来控制柱形图的长短,效果如图: 如果要在Oracle内实现相同的效果,则需要自己写一个函数: ...